-
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 pull request #3777 from craftcms/feature/pt-2315-add-coupon-cod…
…e-order-condition-rule [5.3] Add coupon code condition rule and order query param
- Loading branch information
Showing
8 changed files
with
328 additions
and
7 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,22 +1,23 @@ | ||
# Release Notes for Craft Commerce (WIP) | ||
|
||
### Store Management | ||
|
||
- Order conditions can now have a “Coupon Code” rule. ([#3776](https://github.com/craftcms/commerce/discussions/3776)) | ||
- 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. | ||
|
||
### Administration | ||
|
||
- Added support for `to`, `bcc`, and `cc` email fields to support environment variables. ([#3738](https://github.com/craftcms/commerce/issues/3738)) | ||
|
||
### Development | ||
|
||
- Added the `couponCode` order query param. | ||
- Added an `originalCart` value to the `commerce/update-cart` failed ajax response. ([#430](https://github.com/craftcms/commerce/issues/430)) | ||
|
||
### Extensibility | ||
|
||
- Added `craft\commerce\base\InventoryItemTrait`. | ||
- Added `craft\commerce\base\InventoryLocationTrait`. | ||
- Added `craft\commerce\elements\conditions\orders\CouponCodeConditionRule`. | ||
- Added `craft\commerce\elements\conditions\variants\ProductConditionRule`. | ||
- Added `craft\commerce\elements\db\OrderQuery::$couponCode`. | ||
- Added `craft\commerce\elements\db\OrderQuery::couponCode()`. | ||
- Added `craft\commerce\services\Inventory::updateInventoryLevel()`. | ||
- Added `craft\commerce\services\Inventory::updatePurchasableInventoryLevel()`. |
57 changes: 57 additions & 0 deletions
57
src/elements/conditions/orders/CouponCodeConditionRule.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,57 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\commerce\elements\conditions\orders; | ||
|
||
use Craft; | ||
use craft\helpers\StringHelper; | ||
use yii\base\InvalidConfigException; | ||
|
||
/** | ||
* Order Coupon Code condition rule. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.3.0 | ||
*/ | ||
class CouponCodeConditionRule extends OrderTextValuesAttributeConditionRule | ||
{ | ||
public string $orderAttribute = 'couponCode'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLabel(): string | ||
{ | ||
return Craft::t('commerce', 'Coupon Code'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function matchValue(mixed $value): bool | ||
{ | ||
switch ($this->operator) { | ||
case self::OPERATOR_EMPTY: | ||
return !$value; | ||
case self::OPERATOR_NOT_EMPTY: | ||
return (bool)$value; | ||
} | ||
|
||
if ($this->value === '') { | ||
return true; | ||
} | ||
|
||
return match ($this->operator) { | ||
self::OPERATOR_EQ => strcasecmp($value, $this->value) === 0, | ||
self::OPERATOR_NE => strcasecmp($value, $this->value) !== 0, | ||
self::OPERATOR_BEGINS_WITH => is_string($value) && StringHelper::startsWith($value, $this->value, false), | ||
self::OPERATOR_ENDS_WITH => is_string($value) && StringHelper::endsWith($value, $this->value, false), | ||
self::OPERATOR_CONTAINS => is_string($value) && StringHelper::contains($value, $this->value, false), | ||
default => throw new InvalidConfigException("Invalid operator: $this->operator"), | ||
}; | ||
} | ||
} |
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.