Skip to content

Commit 48c233d

Browse files
committed
Merge branch 'release/4.2.9'
2 parents 62e54ba + 145ade2 commit 48c233d

File tree

11 files changed

+533
-506
lines changed

11 files changed

+533
-506
lines changed

CHANGELOG.md

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

3+
## 4.2.9 - 2023-05-25
4+
5+
- The `commerce/cart/update-cart` action now accepts `clearAddresses`, `clearBillingAddress`, and `clearShippingAddress` params.
6+
- Fixed a JavaScript error that occurred when switching control panel tabs on small screens. ([#3162](https://github.com/craftcms/commerce/issues/3162))
7+
- Fixed a bug where the `commerce/upgrade` command wasn’t migrating discounts’ and coupons’ Max Uses values properly. ([#2947](https://github.com/craftcms/commerce/issues/2947))
8+
39
## 4.2.8 - 2023-05-03
410

511
- Added `craft\commerce\services\Customers::EVENT_UPDATE_PRIMARY_PAYMENT_SOURCE`.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"craftcms/phpstan": "dev-main",
3939
"craftcms/rector": "dev-main",
4040
"craftcms/redactor": "*",
41-
"vlucas/phpdotenv": "^3.4"
41+
"vlucas/phpdotenv": "^5.5.0"
4242
},
4343
"autoload": {
4444
"psr-4": {

composer.lock

Lines changed: 419 additions & 434 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-templates/dist/shop/_private/layouts/index.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Common, top-level layout template.
131131
let states = {{ craft.commerce.store.getStore().getAdministrativeAreasListByCountryCode()|json_encode|raw }};
132132
{% set usedFields = {} %}
133133
{% for countryCode in craft.app.addresses.getCountryRepository().getAll()|keys %}
134-
{% set usedFields = usedFields|merge({ (countryCode): craft.app.addresses.getAddressFormatRepository().get(countryCode).getUsedFields()|merge([
134+
{% set usedFields = usedFields|merge({ (countryCode): craft.app.addresses.getUsedFields(countryCode)|merge([
135135
'fullName',
136136
'latLong',
137137
'organizationTaxId',
@@ -140,7 +140,7 @@ let states = {{ craft.commerce.store.getStore().getAdministrativeAreasListByCoun
140140
]) }) %}
141141
{% endfor %}
142142
let usedAddressFieldsByCountryCode = {{ usedFields|json_encode|raw }};
143-
143+
console.log(usedAddressFieldsByCountryCode);
144144
function hideAddressFields(selectorTemplate) {
145145
const fields = document.querySelectorAll('.' + selectorTemplate.replace('placeHolder', 'js-address-field'));
146146
if (!fields.length) {

example-templates/src/shop/_private/layouts/index.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Common, top-level layout template.
131131
let states = {{ craft.commerce.store.getStore().getAdministrativeAreasListByCountryCode()|json_encode|raw }};
132132
{% set usedFields = {} %}
133133
{% for countryCode in craft.app.addresses.getCountryRepository().getAll()|keys %}
134-
{% set usedFields = usedFields|merge({ (countryCode): craft.app.addresses.getAddressFormatRepository().get(countryCode).getUsedFields()|merge([
134+
{% set usedFields = usedFields|merge({ (countryCode): craft.app.addresses.getUsedFields(countryCode)|merge([
135135
'fullName',
136136
'latLong',
137137
'organizationTaxId',
@@ -140,7 +140,7 @@ let states = {{ craft.commerce.store.getStore().getAdministrativeAreasListByCoun
140140
]) }) %}
141141
{% endfor %}
142142
let usedAddressFieldsByCountryCode = {{ usedFields|json_encode|raw }};
143-
143+
console.log(usedAddressFieldsByCountryCode);
144144
function hideAddressFields(selectorTemplate) {
145145
const fields = document.querySelectorAll('.' + selectorTemplate.replace('placeHolder', 'js-address-field'));
146146
if (!fields.length) {

src/controllers/CartController.php

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,30 @@ private function _getCart(bool $forceSave = false): Order
527527
private function _setAddresses(): void
528528
{
529529
$currentUser = Craft::$app->getUser()->getIdentity();
530+
531+
$setShippingAddress = true;
532+
if ($this->request->getParam('clearShippingAddress') !== null) {
533+
$this->_cart->setShippingAddress(null);
534+
$this->_cart->sourceShippingAddressId = null;
535+
$setShippingAddress = false;
536+
}
537+
538+
$setBillingAddress = true;
539+
if ($this->request->getParam('clearBillingAddress') !== null) {
540+
$this->_cart->setBillingAddress(null);
541+
$this->_cart->sourceBillingAddressId = null;
542+
$setBillingAddress = false;
543+
}
544+
545+
if ($this->request->getParam('clearAddresses') !== null) {
546+
$this->_cart->setShippingAddress(null);
547+
$this->_cart->sourceShippingAddressId = null;
548+
$this->_cart->setBillingAddress(null);
549+
$this->_cart->sourceBillingAddressId = null;
550+
$setBillingAddress = false;
551+
$setShippingAddress = false;
552+
}
553+
530554
// Copy address options
531555
$shippingIsBilling = $this->request->getParam('shippingAddressSameAsBilling');
532556
$billingIsShipping = $this->request->getParam('billingAddressSameAsShipping');
@@ -541,68 +565,72 @@ private function _setAddresses(): void
541565
$shippingAddressId = $this->request->getParam('shippingAddressId');
542566
$billingAddressId = $this->request->getParam('billingAddressId');
543567

544-
// Shipping address
545-
if ($shippingAddressId && !$shippingIsBilling) {
546-
/** @var Address|null $userShippingAddress */
547-
$userShippingAddress = Collection::make($currentUser->getAddresses())->firstWhere('id', $shippingAddressId);
568+
if ($setShippingAddress) {
569+
// Shipping address
570+
if ($shippingAddressId && !$shippingIsBilling) {
571+
/** @var Address|null $userShippingAddress */
572+
$userShippingAddress = Collection::make($currentUser->getAddresses())->firstWhere('id', $shippingAddressId);
548573

549-
// If a user's address ID has been submitted duplicate the address to the order
550-
if ($userShippingAddress) {
551-
$this->_cart->sourceShippingAddressId = $shippingAddressId;
574+
// If a user's address ID has been submitted duplicate the address to the order
575+
if ($userShippingAddress) {
576+
$this->_cart->sourceShippingAddressId = $shippingAddressId;
552577

553-
/** @var Address $cartShippingAddress */
554-
$cartShippingAddress = Craft::$app->getElements()->duplicateElement($userShippingAddress, ['ownerId' => $this->_cart->id]);
555-
$this->_cart->setShippingAddress($cartShippingAddress);
578+
/** @var Address $cartShippingAddress */
579+
$cartShippingAddress = Craft::$app->getElements()->duplicateElement($userShippingAddress, ['ownerId' => $this->_cart->id]);
580+
$this->_cart->setShippingAddress($cartShippingAddress);
556581

557-
if ($billingIsShipping) {
558-
$this->_cart->sourceBillingAddressId = $userShippingAddress->id;
559-
$this->_cart->setBillingAddress($cartShippingAddress);
582+
if ($billingIsShipping) {
583+
$this->_cart->sourceBillingAddressId = $userShippingAddress->id;
584+
$this->_cart->setBillingAddress($cartShippingAddress);
585+
}
560586
}
561-
}
562-
} elseif ($shippingAddress && !$shippingIsBilling) {
563-
$this->_cart->sourceShippingAddressId = null;
564-
$this->_cart->setShippingAddress($shippingAddress);
587+
} elseif ($shippingAddress && !$shippingIsBilling) {
588+
$this->_cart->sourceShippingAddressId = null;
589+
$this->_cart->setShippingAddress($shippingAddress);
565590

566-
if (!empty($shippingAddress['fields']) && $this->_cart->getShippingAddress()) {
567-
$this->_cart->getShippingAddress()->setFieldValues($shippingAddress['fields']);
568-
}
591+
if (!empty($shippingAddress['fields']) && $this->_cart->getShippingAddress()) {
592+
$this->_cart->getShippingAddress()->setFieldValues($shippingAddress['fields']);
593+
}
569594

570-
if ($billingIsShipping) {
571-
$this->_cart->sourceBillingAddressId = null;
572-
$this->_cart->setBillingAddress($this->_cart->getShippingAddress());
595+
if ($billingIsShipping) {
596+
$this->_cart->sourceBillingAddressId = null;
597+
$this->_cart->setBillingAddress($this->_cart->getShippingAddress());
598+
}
573599
}
574600
}
575601

576602
// Billing address
577-
if ($billingAddressId && !$billingIsShipping) {
578-
/** @var Address|null $userBillingAddress */
579-
$userBillingAddress = Collection::make($currentUser->getAddresses())->firstWhere('id', $billingAddressId);
580-
581-
// If a user's address ID has been submitted duplicate the address to the order
582-
if ($userBillingAddress) {
583-
$this->_cart->sourceBillingAddressId = $billingAddressId;
603+
if ($setBillingAddress) {
604+
if ($billingAddressId && !$billingIsShipping) {
605+
/** @var Address|null $userBillingAddress */
606+
$userBillingAddress = Collection::make($currentUser->getAddresses())->firstWhere('id', $billingAddressId);
607+
608+
// If a user's address ID has been submitted duplicate the address to the order
609+
if ($userBillingAddress) {
610+
$this->_cart->sourceBillingAddressId = $billingAddressId;
611+
612+
/** @var Address $cartBillingAddress */
613+
$cartBillingAddress = Craft::$app->getElements()->duplicateElement($userBillingAddress, ['ownerId' => $this->_cart->id]);
614+
$this->_cart->setBillingAddress($cartBillingAddress);
615+
616+
if ($shippingIsBilling) {
617+
$this->_cart->sourceShippingAddressId = $userBillingAddress->id;
618+
$this->_cart->setShippingAddress($cartBillingAddress);
619+
}
620+
}
621+
} elseif ($billingAddress && !$billingIsShipping) {
622+
$this->_cart->sourceBillingAddressId = null;
623+
$this->_cart->setBillingAddress($billingAddress);
584624

585-
/** @var Address $cartBillingAddress */
586-
$cartBillingAddress = Craft::$app->getElements()->duplicateElement($userBillingAddress, ['ownerId' => $this->_cart->id]);
587-
$this->_cart->setBillingAddress($cartBillingAddress);
625+
if (!empty($billingAddress['fields']) && $this->_cart->getBillingAddress()) {
626+
$this->_cart->getBillingAddress()->setFieldValues($billingAddress['fields']);
627+
}
588628

589629
if ($shippingIsBilling) {
590-
$this->_cart->sourceShippingAddressId = $userBillingAddress->id;
591-
$this->_cart->setShippingAddress($cartBillingAddress);
630+
$this->_cart->sourceShippingAddressId = null;
631+
$this->_cart->setShippingAddress($this->_cart->getBillingAddress());
592632
}
593633
}
594-
} elseif ($billingAddress && !$billingIsShipping) {
595-
$this->_cart->sourceBillingAddressId = null;
596-
$this->_cart->setBillingAddress($billingAddress);
597-
598-
if (!empty($billingAddress['fields']) && $this->_cart->getBillingAddress()) {
599-
$this->_cart->getBillingAddress()->setFieldValues($billingAddress['fields']);
600-
}
601-
602-
if ($shippingIsBilling) {
603-
$this->_cart->sourceShippingAddressId = null;
604-
$this->_cart->setShippingAddress($this->_cart->getBillingAddress());
605-
}
606634
}
607635

608636
// Estimated Shipping Address
@@ -629,17 +657,21 @@ private function _setAddresses(): void
629657
$this->_cart->setEstimatedBillingAddress($estimatedBillingAddress);
630658
}
631659

660+
632661
$this->_cart->billingSameAsShipping = (bool)$billingIsShipping;
633662
$this->_cart->shippingSameAsBilling = (bool)$shippingIsBilling;
634663
$this->_cart->estimatedBillingSameAsShipping = (bool)$estimatedBillingIsShipping;
635664

636665
// Set primary addresses
637-
if ($this->request->getBodyParam('makePrimaryShippingAddress')) {
638-
$this->_cart->makePrimaryShippingAddress = true;
666+
if ($setShippingAddress) {
667+
if ($this->request->getBodyParam('makePrimaryShippingAddress')) {
668+
$this->_cart->makePrimaryShippingAddress = true;
669+
}
639670
}
640-
641-
if ($this->request->getBodyParam('makePrimaryBillingAddress')) {
642-
$this->_cart->makePrimaryBillingAddress = true;
671+
if ($setBillingAddress) {
672+
if ($this->request->getBodyParam('makePrimaryBillingAddress')) {
673+
$this->_cart->makePrimaryBillingAddress = true;
674+
}
643675
}
644676
}
645677
}

src/elements/db/VariantQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ protected function beforePrepare(): bool
588588
$this->subQuery->andWhere(Db::parseParam('commerce_variants.price', $this->price));
589589
}
590590

591-
if (isset($this->isDefault) && $this->isDefault !== null) {
591+
if (isset($this->isDefault)) {
592592
$this->subQuery->andWhere(Db::parseBooleanParam('commerce_variants.isDefault', $this->isDefault, false));
593593
}
594594

src/migrations/m211118_101920_split_coupon_codes.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ public function safeUp(): bool
5858

5959
if (!empty($discountsWithCodes)) {
6060
$coupons = array_map(static function($discount) use ($codeUsage) {
61+
$maxUses = $discount['totalDiscountUseLimit'] !== null && $discount['totalDiscountUseLimit'] > 0
62+
? $discount['totalDiscountUseLimit']
63+
: null;
64+
6165
$row['code'] = $discount['code'];
6266
$row['discountId'] = $discount['id'];
6367
$row['uses'] = $codeUsage[$discount['code']] ?? 0;
64-
$row['maxUses'] = $discount['totalDiscountUseLimit'] ?? 0;
68+
$row['maxUses'] = $maxUses;
6569
$row['dateCreated'] = $discount['dateCreated'];
6670
$row['dateUpdated'] = $discount['dateUpdated'];
6771
$row['uid'] = StringHelper::UUID();

src/templates/promotions/discounts/_edit.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
{% endif %}
3737

3838
{% set tabs = {
39-
0: {'label':'Discount'|t('commerce'),'url':'#discount','class':discountClasses},
40-
1: {'label':'Coupons'|t('commerce'),'url':'#coupons','class':couponClasses},
41-
2: {'label':'Matching Items'|t('commerce'),'url':'#matching-items','class':matchingItemsClasses},
42-
3: {'label':'Conditions Rules'|t('commerce'),'url':'#condition-rules','class':conditionRulesClasses},
43-
4: {'label':'Conditions'|t('commerce'),'url':'#conditions','class':conditionsClasses},
44-
5: {'label':'Actions'|t('commerce'),'url':'#actions'}
39+
discount: {'label':'Discount'|t('commerce'),'url':'#discount','class':discountClasses},
40+
coupons: {'label':'Coupons'|t('commerce'),'url':'#coupons','class':couponClasses},
41+
matchingItems: {'label':'Matching Items'|t('commerce'),'url':'#matching-items','class':matchingItemsClasses},
42+
conditionRules: {'label':'Conditions Rules'|t('commerce'),'url':'#condition-rules','class':conditionRulesClasses},
43+
conditions: {'label':'Conditions'|t('commerce'),'url':'#conditions','class':conditionsClasses},
44+
actions: {'label':'Actions'|t('commerce'),'url':'#actions'}
4545
} %}
4646

4747
{% set couponsTable = {

src/templates/promotions/sales/_edit.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
{% endif %}
2929

3030
{% set tabs = {
31-
0: {'label':'Sale'|t('commerce'),'url':'#sale','class': saleClasses},
32-
1: {'label':'Matching Items'|t('commerce'),'url':'#matching-items'},
33-
2: {'label':'Conditions'|t('commerce'),'url':'#conditions'},
34-
3: {'label':'Actions'|t('commerce'),'url':'#actions','class': actionClasses}
31+
sale: {'label':'Sale'|t('commerce'),'url':'#sale','class': saleClasses},
32+
matchingItems: {'label':'Matching Items'|t('commerce'),'url':'#matching-items'},
33+
conditions: {'label':'Conditions'|t('commerce'),'url':'#conditions'},
34+
actions: {'label':'Actions'|t('commerce'),'url':'#actions','class': actionClasses}
3535
} %}
3636

3737
{% hook "cp.commerce.sales.edit" %}

src/templates/shipping/shippingrules/_edit.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@
117117
{% import "commerce/_includes/forms/commerceForms" as commerceForms %}
118118

119119
{% set tabs = {
120-
0: {'label':'Rule'|t('commerce'),'url':'#rule-tab'},
121-
1: {'label':'Conditions'|t('commerce'),'url':'#conditions-tab'},
122-
2: {'label':'Costs'|t('commerce'),'url':'#costs-tab'}
120+
rule: {'label':'Rule'|t('commerce'),'url':'#rule-tab'},
121+
conditions: {'label':'Conditions'|t('commerce'),'url':'#conditions-tab'},
122+
costs: {'label':'Costs'|t('commerce'),'url':'#costs-tab'}
123123
} %}
124124

125125
{% block actionButton %}

0 commit comments

Comments
 (0)