Skip to content

Commit 21145b8

Browse files
authored
Merge pull request #3703 from craftcms/feature/pt-2184-5x-pring-rules-customer-condition-without-matching-customer
Fixed #3700 don’t generate prices if there aren’t any users applicable
2 parents 26056df + 1f167e5 commit 21145b8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fixed a bug where tax categories that were not available to the product type were showing up for selection on the Edit Product screen. ([#3690](https://github.com/craftcms/commerce/issues/3690))
99
- Fixed a bug where the store name was being displayed twice on the Edit Order screen.
1010
- Fixed a bug where the `CatalogPricingRule::$description` property was not being populated. ([#3699](https://github.com/craftcms/commerce/issues/3699))
11+
- Fixed a bug where catalog pricing rules were generating prices incorrectly. ([#3700](https://github.com/craftcms/commerce/issues/3700))
1112

1213
## 5.1.2 - 2024-09-19
1314

src/services/CatalogPricing.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ public function generateCatalogPrices(?array $purchasableIds = null, ?array $cat
8484
return;
8585
}
8686

87+
// Rules with user ID records
88+
$cprWithUserIds = (new Query())
89+
->select(['catalogPricingRuleId'])
90+
->from(Table::CATALOG_PRICING_RULES_USERS)
91+
->groupBy('catalogPricingRuleId')
92+
->column();
93+
8794
// @TODO maybe mark prices as pending update here?
8895
8996
$cprStartTime = microtime(true);
@@ -115,6 +122,11 @@ public function generateCatalogPrices(?array $purchasableIds = null, ?array $cat
115122
continue;
116123
}
117124

125+
// Skip if the rule has user conditions but didn't generate any applicable users
126+
if (!empty($catalogPricingRule->getCustomerCondition()->getConditionRules()) && !in_array($catalogPricingRule->id, $cprWithUserIds, true)) {
127+
continue;
128+
}
129+
118130
// If `getPurchasableIds()` is `null` this means all purchasables
119131
if ($catalogPricingRule->getPurchasableIds() === null) {
120132
$applyPurchasableIds = $purchasableIds;

0 commit comments

Comments
 (0)