-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
…tswitch-to-discounts # Conflicts: # CHANGELOG-WIP.md
- Loading branch information
Showing
18 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
# Release Notes for Craft Commerce 4.7 (WIP) | ||
|
||
## Unreleased | ||
|
||
### Store Management | ||
- It’s now possible to specifically make discounts require a coupon code. ([#3132](https://github.com/craftcms/commerce/issues/3132)) | ||
- Country code defaults to the store’s country when creating a new address on the Order Edit page. ([#3306](https://github.com/craftcms/commerce/issues/3306)) | ||
- Product conditions can now have a “Variant Search” rule. ([#3689](https://github.com/craftcms/commerce/issues/3689)) | ||
|
||
### Administration | ||
|
||
### Development | ||
|
||
### Extensibility | ||
- Added `craft\commerce\elements\conditions\products\ProductVariantSearchConditionRule`. | ||
- Added `craft\commerce\models\Discount::$requireCouponCode`. | ||
|
||
### System |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/elements/conditions/products/ProductVariantSearchConditionRule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\commerce\elements\conditions\products; | ||
|
||
use Craft; | ||
use craft\base\conditions\BaseTextConditionRule; | ||
use craft\base\ElementInterface; | ||
use craft\commerce\elements\db\ProductQuery; | ||
use craft\commerce\elements\Product; | ||
use craft\commerce\elements\Variant; | ||
use craft\elements\conditions\ElementConditionRuleInterface; | ||
use craft\elements\db\ElementQueryInterface; | ||
use craft\helpers\ArrayHelper; | ||
use yii\base\InvalidConfigException; | ||
|
||
/** | ||
* Product Variant Search Condition Rule | ||
* | ||
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com> | ||
* @since 4.7.0 | ||
*/ | ||
class ProductVariantSearchConditionRule extends BaseTextConditionRule implements ElementConditionRuleInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return Craft::t('commerce', 'Variant Search'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getExclusiveQueryParams(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function operators(): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function paramValue(): ?string | ||
{ | ||
return trim(parent::paramValue()); // TODO: Change the autogenerated stub | ||
} | ||
|
||
/** | ||
* @param ElementQueryInterface $query | ||
*/ | ||
public function modifyQuery(ElementQueryInterface $query): void | ||
{ | ||
$variantQuery = Variant::find(); | ||
$variantQuery->select(['commerce_variants.productId as id']); | ||
$variantQuery->search($this->paramValue()); | ||
|
||
/** @var ProductQuery $query */ | ||
$query->andWhere(['elements.id' => $variantQuery]); | ||
} | ||
|
||
/** | ||
* @param Product $element | ||
* @return bool | ||
* @throws InvalidConfigException | ||
*/ | ||
public function matchElement(ElementInterface $element): bool | ||
{ | ||
$variantIds = ArrayHelper::getColumn($element->getVariants(), 'id'); | ||
if (empty($variantIds)) { | ||
return false; | ||
} | ||
|
||
// Perform a variant query search to ensure it is the same process as `modifyQuery` | ||
$variantQuery = Variant::find(); | ||
$variantQuery->search($this->paramValue()); | ||
$variantQuery->id($variantIds); | ||
|
||
return $variantQuery->count() > 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.