Skip to content

Commit b0f2cd5

Browse files
committed
Merge branch 'release/3.3.0.1' into main
2 parents 8e4189f + 9eb0ab2 commit b0f2cd5

File tree

23 files changed

+107
-120
lines changed

23 files changed

+107
-120
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release Notes for Craft Commerce
22

3+
### 3.3.0.1 - 2021-04-26
4+
5+
### Fixed
6+
- Fixed a bug where an incorrect amount could be calculated when paying an outstanding balance in a non-primary currency.
7+
- Fixed a bug where shipping rules were enforcing the “Order Condition Formula” field as required. ([#2098](https://github.com/craftcms/commerce/issues/2098))
8+
- Fixed a bug where Base Discount and Per Item Discount fields could show negative values on the Edit Discount page. ([#2090](https://github.com/craftcms/commerce/issues/2090))
9+
310
## 3.3.0 - 2021-04-20
411

512
### Added
@@ -148,10 +155,6 @@
148155
- Emails and PDFs now have Language settings that can be used to specify the language that should be used, instead of the order’s language. ([#1884](https://github.com/craftcms/commerce/issues/1884))
149156
- Added the `cp.commerce.order.content`, `cp.commerce.order.edit.order-actions`, and `cp.commerce.order.edit.order-secondary-actions` template hooks to the Edit Order page. ([#138](https://github.com/craftcms/commerce/issues/138), [#1269](https://github.com/craftcms/commerce/issues/1269))
150157

151-
### Added
152-
- Partial payments on orders can now be made from the Edit Order page.
153-
- Added the `allowFrontEndPartialPayments` config setting.
154-
155158
### Changed
156159
- Improved the Edit Product page load time by lazy-loading variants’ related sales on scroll. ([#1883](https://github.com/craftcms/commerce/issues/1883))
157160
- The Edit Order page no longer requires orders to have at least one line item to be saved.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "craftcms/commerce",
33
"description": "Craft Commerce",
44
"type": "craft-plugin",
5-
"version": "3.3.0",
5+
"version": "3.3.0.1",
66
"keywords": [
77
"cms",
88
"craftcms",

src/controllers/DiscountsController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ public function actionSave()
181181
$this->redirectToPostedUrl($discount);
182182
} else {
183183
$this->setFailFlash(Craft::t('commerce', 'Couldn’t save discount.'));
184+
185+
// Set back to original input value of the text field to prevent negative value.
186+
$discount->baseDiscount = $baseDiscount;
187+
$discount->perItemDiscount = $perItemDiscount;
184188
}
185189

186190
// Send the model back to the template

src/controllers/PaymentsController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ public function actionPay()
421421
$order->setPaymentAmount($paymentAmount);
422422
}
423423

424-
if (!$partialAllowed && $order->getPaymentAmount() < $order->getOutstandingBalance()) {
424+
$paymentAmountInPrimaryCurrency = Plugin::getInstance()->getPaymentCurrencies()->convertCurrency($order->getPaymentAmount(), $order->paymentCurrency, $order->currency);
425+
426+
if (!$partialAllowed && $paymentAmountInPrimaryCurrency < $order->getOutstandingBalance()) {
425427
$error = Craft::t('commerce', 'Partial payment not allowed.');
426428
$this->setFailFlash($error);
427429
Craft::$app->getUrlManager()->setRouteParams(['paymentForm' => $paymentForm, $this->_cartVariableName => $order]);

src/elements/Order.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,11 +2244,13 @@ public function getIsUnpaid(): bool
22442244
*/
22452245
public function getPaymentAmount(): float
22462246
{
2247-
if ($this->_paymentAmount && $this->_paymentAmount >= 0 && $this->_paymentAmount <= $this->getOutstandingBalance()) {
2247+
$outstandingBalanceInPaymentCurrency = Plugin::getInstance()->getPaymentCurrencies()->convertCurrency($this->getOutstandingBalance(), $this->currency, $this->paymentCurrency);
2248+
2249+
if ($this->_paymentAmount && $this->_paymentAmount >= 0 && $this->_paymentAmount <= $outstandingBalanceInPaymentCurrency) {
22482250
return $this->_paymentAmount;
22492251
}
2250-
$amount = $this->getOutstandingBalance();
2251-
return $amount;
2252+
2253+
return $outstandingBalanceInPaymentCurrency;
22522254
}
22532255

22542256
/**

src/models/Discount.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,20 @@ public function defineRules(): array
388388
}
389389
}
390390
];
391+
$rules[] = [['orderConditionFormula'], 'string', 'length' => [1, 65000], 'skipOnEmpty' => true];
391392
$rules[] = [
392393
'orderConditionFormula', function($attribute, $params, $validator) {
393-
$order = Order::find()->one();
394-
if (!$order) {
395-
$order = new Order();
396-
}
397-
$orderDiscountConditionParams = [
398-
'order' => $order->toArray([], ['lineItems.snapshot', 'shippingAddress', 'billingAddress'])
399-
];
400-
if (!Plugin::getInstance()->getFormulas()->validateConditionSyntax($this->orderConditionFormula, $orderDiscountConditionParams)) {
401-
$this->addError($attribute, Craft::t('commerce', 'Invalid order condition syntax.'));
394+
if ($this->orderConditionFormula) {
395+
$order = Order::find()->one();
396+
if (!$order) {
397+
$order = new Order();
398+
}
399+
$orderDiscountConditionParams = [
400+
'order' => $order->toArray([], ['lineItems.snapshot', 'shippingAddress', 'billingAddress'])
401+
];
402+
if (!Plugin::getInstance()->getFormulas()->validateConditionSyntax($this->orderConditionFormula, $orderDiscountConditionParams)) {
403+
$this->addError($attribute, Craft::t('commerce', 'Invalid order condition syntax.'));
404+
}
402405
}
403406
}
404407
];

src/models/ShippingAddressZone.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ public function defineRules(): array
224224
$rules = parent::defineRules();
225225

226226
$rules[] = [['name'], 'required'];
227+
$rules[] = [['zipCodeConditionFormula'], 'string', 'length' => [1, 65000], 'skipOnEmpty' => true];
227228
$rules[] = [['name'], UniqueValidator::class, 'targetClass' => ShippingZoneRecord::class, 'targetAttribute' => ['name']];
229+
228230
$rules[] = [
229231
['states'], 'required', 'when' => static function($model) {
230232
return !$model->isCountryBased;

src/models/ShippingRule.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public function defineRules(): array
194194
'methodId',
195195
'priority',
196196
'enabled',
197-
'orderConditionFormula',
198197
'minQty',
199198
'maxQty',
200199
'minTotal',
@@ -221,17 +220,21 @@ public function defineRules(): array
221220

222221
$rules[] = [['shippingRuleCategories'], 'validateShippingRuleCategories', 'skipOnEmpty' => true];
223222

223+
$rules[] = [['orderConditionFormula'], 'string', 'length' => [1, 65000], 'skipOnEmpty' => true];
224224
$rules[] = [
225225
'orderConditionFormula', function($attribute, $params, $validator) {
226-
$order = Order::find()->one();
227-
if (!$order) {
228-
$order = new Order();
229-
}
230-
$orderConditionParams = [
231-
'order' => $order->toArray([], ['lineItems.snapshot', 'shippingAddress', 'billingAddress'])
232-
];
233-
if (!Plugin::getInstance()->getFormulas()->validateConditionSyntax($this->orderConditionFormula, $orderConditionParams)) {
234-
$this->addError($attribute, Craft::t('commerce', 'Invalid order condition syntax.'));
226+
227+
if($this->orderConditionFormula) {
228+
$order = Order::find()->one();
229+
if (!$order) {
230+
$order = new Order();
231+
}
232+
$orderConditionParams = [
233+
'order' => $order->toArray([], ['lineItems.snapshot', 'shippingAddress', 'billingAddress'])
234+
];
235+
if (!Plugin::getInstance()->getFormulas()->validateConditionSyntax($this->orderConditionFormula, $orderConditionParams)) {
236+
$this->addError($attribute, Craft::t('commerce', 'Invalid order condition syntax.'));
237+
}
235238
}
236239
}
237240
];

src/models/TaxAddressZone.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ public function defineRules(): array
234234
$rules = parent::defineRules();
235235

236236
$rules[] = [['name'], 'required'];
237+
$rules[] = [['zipCodeConditionFormula'], 'string', 'length' => [1, 65000], 'skipOnEmpty' => true];
237238
$rules[] = [['name'], UniqueValidator::class, 'targetClass' => TaxZoneRecord::class, 'targetAttribute' => ['name']];
239+
238240
$rules[] = [
239241
['states'], 'required', 'when' => static function($model) {
240242
return !$model->isCountryBased;

src/services/Discounts.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ public function matchLineItem(LineItem $lineItem, Discount $discount, bool $matc
514514
* @param Order $order
515515
* @param Discount $discount
516516
* @return bool
517+
* @throws \Exception
517518
*/
518519
public function matchOrder(Order $order, Discount $discount): bool
519520
{
@@ -549,14 +550,8 @@ public function matchOrder(Order $order, Discount $discount): bool
549550
return false;
550551
}
551552

552-
if ($discount->orderConditionFormula) {
553-
$orderDiscountConditionParams = [
554-
'order' => $order->toArray([], ['lineItems.snapshot', 'shippingAddress', 'billingAddress'])
555-
];
556-
557-
if (!Plugin::getInstance()->getFormulas()->evaluateCondition($discount->orderConditionFormula, $orderDiscountConditionParams, 'Evaluate Order Discount Condition Formula')) {
558-
return false;
559-
}
553+
if(!$this->_isDiscountConditionFormulaValid($order, $discount)){
554+
return false;
560555
}
561556

562557
if (($discount->allPurchasables && $discount->allCategories) && $discount->purchaseTotal > 0 && $order->getItemSubtotal() < $discount->purchaseTotal) {

0 commit comments

Comments
 (0)