diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index c9e510bf7d..055774d780 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1,7 +1,12 @@ # Release Notes for Craft Commerce (WIP) -## Administration +### Store Management - Added support for `to`, `bcc`, and `cc` email fields to support environment variables. ([#3738](https://github.com/craftcms/commerce/issues/3738)) - Added an `originalCart` value to the `commerce/update-cart` failed ajax response. ([#430](https://github.com/craftcms/commerce/issues/430)) -- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722)) +- Order conditions can now have a “Payment Gateway” rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722)) +- Variant conditions can now have a “Product” rule. + +### Extensibility + +- Added `craft\commerce\elements\conditions\variants\ProductConditionRule`. \ No newline at end of file diff --git a/src/elements/conditions/variants/ProductConditionRule.php b/src/elements/conditions/variants/ProductConditionRule.php new file mode 100644 index 0000000000..aebc6c582d --- /dev/null +++ b/src/elements/conditions/variants/ProductConditionRule.php @@ -0,0 +1,68 @@ + + * @since 5.3.0 + */ +class ProductConditionRule extends BaseElementSelectConditionRule implements ElementConditionRuleInterface +{ + /** + * @inheritdoc + */ + protected function elementType(): string + { + return Product::class; + } + + /** + * @inheritdoc + */ + public function getLabel(): string + { + return Craft::t('commerce', 'Product'); + } + + /** + * @inheritdoc + */ + public function getExclusiveQueryParams(): array + { + return ['product', 'productId', 'primaryOwnerId', 'primaryOwner', 'owner', 'ownerId']; + } + + /** + * @inheritdoc + */ + public function modifyQuery(ElementQueryInterface $query): void + { + /** @var VariantQuery $query */ + $query->ownerId($this->getElementId()); + } + + /** + * @inheritdoc + */ + public function matchElement(ElementInterface $element): bool + { + /** @var Variant $element */ + return $element->getOwnerId() == $this->getElementId(); + } +} \ No newline at end of file diff --git a/src/elements/conditions/variants/VariantCondition.php b/src/elements/conditions/variants/VariantCondition.php index 311b7baffd..49c3530b53 100644 --- a/src/elements/conditions/variants/VariantCondition.php +++ b/src/elements/conditions/variants/VariantCondition.php @@ -25,6 +25,7 @@ class VariantCondition extends ElementCondition protected function selectableConditionRules(): array { return array_merge(parent::selectableConditionRules(), [ + ProductConditionRule::class, SkuConditionRule::class, ]); }