From bfada3140a61f14f9bd3678dcbf599837e7a1d0d Mon Sep 17 00:00:00 2001 From: shinybrad <83238715+shinybrad@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:19:47 -0400 Subject: [PATCH 01/24] New translations commerce.php (Dutch) --- src/translations/nl/commerce.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/translations/nl/commerce.php b/src/translations/nl/commerce.php index a3bff857cc..20131c9639 100644 --- a/src/translations/nl/commerce.php +++ b/src/translations/nl/commerce.php @@ -744,7 +744,7 @@ 'Note' => 'Opmerking', 'Notes' => 'Notities', 'Number of Coupons' => 'Aantal coupons', - 'Number' => 'Nummer', + 'Number' => 'Aantal', 'On Hand' => 'Aanwezig', 'Only allow this gateway to be used for zero value orders?' => 'Toestaan dat deze gateway alleen wordt gebruikt voor orders met waarde nul?', 'Only match certain purchasables…' => 'Alleen bepaalde koopbare artikelen vergelijken…', From 4b0f5ab74f6f79517eef65ca4b641ccb85f1e971 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 21 Aug 2024 11:24:56 -0400 Subject: [PATCH 02/24] Release note tweak [ci skip] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9efe47720..4c7b5af026 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- Fixed a bug where available shipping methods were not returning in price order. ([#3631](https://github.com/craftcms/commerce/issues/3631)) +- Fixed a bug where available shipping methods were not returned in order of price. ([#3631](https://github.com/craftcms/commerce/issues/3631)) ## 4.6.8 - 2024-08-14 From a0d88ac6d41f64f371ce1b326bbb00ef961ca58b Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 21 Aug 2024 16:41:49 +0100 Subject: [PATCH 03/24] Finish 4.6.9 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7b5af026..5aaedceac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft Commerce -## Unreleased +## 4.6.9 - 2024-08-21 - Fixed a bug where available shipping methods were not returned in order of price. ([#3631](https://github.com/craftcms/commerce/issues/3631)) From 5337f30f47af2a460fd8ee64ee8e76e11e88cf3f Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Thu, 22 Aug 2024 16:52:56 +0100 Subject: [PATCH 04/24] =?UTF-8?q?Don=E2=80=99t=20log=20uncategorised=20exc?= =?UTF-8?q?eptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Plugin.php | 4 ++-- src/elements/traits/OrderValidatorsTrait.php | 2 +- src/services/Payments.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index c56c47260d..c2241ace87 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -861,14 +861,14 @@ private function _registerCacheTypes(): void try { FileHelper::createDirectory($path); } catch (\Exception $e) { - Craft::error($e->getMessage()); + Craft::$app->getErrorHandler()->logException($e); } Event::on(ClearCaches::class, ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, static function(RegisterCacheOptionsEvent $e) use ($path) { try { FileHelper::createDirectory($path); } catch (\Exception $e) { - Craft::error($e->getMessage()); + Craft::$app->getErrorHandler()->logException($e);; } $e->options[] = [ diff --git a/src/elements/traits/OrderValidatorsTrait.php b/src/elements/traits/OrderValidatorsTrait.php index 626e8f9f84..e3eba9e5be 100644 --- a/src/elements/traits/OrderValidatorsTrait.php +++ b/src/elements/traits/OrderValidatorsTrait.php @@ -46,7 +46,7 @@ public function validatePaymentSourceId(string $attribute, $params, Validator $v // this will confirm the payment source is valid and belongs to the orders customer $this->getPaymentSource(); } catch (InvalidConfigException $e) { - Craft::error($e->getMessage()); + Craft::$app->getErrorHandler()->logException($e);; $validator->addError($this, $attribute, Craft::t('commerce', 'Invalid payment source ID: {value}')); } } diff --git a/src/services/Payments.php b/src/services/Payments.php index 62e2856d42..ce4e545822 100644 --- a/src/services/Payments.php +++ b/src/services/Payments.php @@ -320,7 +320,7 @@ public function processPayment(Order $order, BasePaymentForm $form, ?string &$re $this->_saveTransaction($transaction); } - Craft::error($e->getMessage()); + Craft::$app->getErrorHandler()->logException($e);; throw new PaymentException($e->getMessage(), $e->getCode(), $e); } } @@ -551,7 +551,7 @@ private function _capture(Transaction $parent): Transaction $child->message = $e->getMessage(); $this->_saveTransaction($child); - Craft::error($e->getMessage()); + Craft::$app->getErrorHandler()->logException($e);; } return $child; From 5dc82a98cd6485bf9e95400a801f1032661bc792 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Thu, 22 Aug 2024 17:35:48 +0100 Subject: [PATCH 05/24] fix cs --- src/Plugin.php | 2 +- src/elements/traits/OrderValidatorsTrait.php | 3 ++- src/services/Payments.php | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index c2241ace87..4312c20726 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -868,7 +868,7 @@ private function _registerCacheTypes(): void try { FileHelper::createDirectory($path); } catch (\Exception $e) { - Craft::$app->getErrorHandler()->logException($e);; + Craft::$app->getErrorHandler()->logException($e); } $e->options[] = [ diff --git a/src/elements/traits/OrderValidatorsTrait.php b/src/elements/traits/OrderValidatorsTrait.php index e3eba9e5be..c89bf87385 100644 --- a/src/elements/traits/OrderValidatorsTrait.php +++ b/src/elements/traits/OrderValidatorsTrait.php @@ -46,7 +46,8 @@ public function validatePaymentSourceId(string $attribute, $params, Validator $v // this will confirm the payment source is valid and belongs to the orders customer $this->getPaymentSource(); } catch (InvalidConfigException $e) { - Craft::$app->getErrorHandler()->logException($e);; + Craft::$app->getErrorHandler()->logException($e); + ; $validator->addError($this, $attribute, Craft::t('commerce', 'Invalid payment source ID: {value}')); } } diff --git a/src/services/Payments.php b/src/services/Payments.php index ce4e545822..cb499dc9b4 100644 --- a/src/services/Payments.php +++ b/src/services/Payments.php @@ -320,7 +320,8 @@ public function processPayment(Order $order, BasePaymentForm $form, ?string &$re $this->_saveTransaction($transaction); } - Craft::$app->getErrorHandler()->logException($e);; + Craft::$app->getErrorHandler()->logException($e); + ; throw new PaymentException($e->getMessage(), $e->getCode(), $e); } } @@ -551,7 +552,8 @@ private function _capture(Transaction $parent): Transaction $child->message = $e->getMessage(); $this->_saveTransaction($child); - Craft::$app->getErrorHandler()->logException($e);; + Craft::$app->getErrorHandler()->logException($e); + ; } return $child; From 66214fff4cf28b759ee75d014f42bf6fa590f7db Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Thu, 22 Aug 2024 17:58:42 +0100 Subject: [PATCH 06/24] manual fix cs [ci skip] --- src/elements/traits/OrderValidatorsTrait.php | 1 - src/services/Payments.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/elements/traits/OrderValidatorsTrait.php b/src/elements/traits/OrderValidatorsTrait.php index c89bf87385..a3c5d4c5d9 100644 --- a/src/elements/traits/OrderValidatorsTrait.php +++ b/src/elements/traits/OrderValidatorsTrait.php @@ -47,7 +47,6 @@ public function validatePaymentSourceId(string $attribute, $params, Validator $v $this->getPaymentSource(); } catch (InvalidConfigException $e) { Craft::$app->getErrorHandler()->logException($e); - ; $validator->addError($this, $attribute, Craft::t('commerce', 'Invalid payment source ID: {value}')); } } diff --git a/src/services/Payments.php b/src/services/Payments.php index cb499dc9b4..584cdcbbcb 100644 --- a/src/services/Payments.php +++ b/src/services/Payments.php @@ -321,7 +321,6 @@ public function processPayment(Order $order, BasePaymentForm $form, ?string &$re } Craft::$app->getErrorHandler()->logException($e); - ; throw new PaymentException($e->getMessage(), $e->getCode(), $e); } } @@ -553,7 +552,6 @@ private function _capture(Transaction $parent): Transaction $this->_saveTransaction($child); Craft::$app->getErrorHandler()->logException($e); - ; } return $child; From e50d108027dc9595e1ef3dbfd13520e263caf39d Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 27 Aug 2024 10:41:36 +0800 Subject: [PATCH 07/24] Fixed autoSetNewCartAddresses --- CHANGELOG.md | 4 ++++ src/models/Store.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a0768f52f..3766bb68f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed a bug were the “Auto Set New Cart Addresses” store setting was not persisting when saved. + ## 5.0.17 - 2024-08-21 - Fixed a bug where variant indexes weren’t displaying promotion prices as currency values. diff --git a/src/models/Store.php b/src/models/Store.php index 00e27c57e3..b4f12843b9 100644 --- a/src/models/Store.php +++ b/src/models/Store.php @@ -336,7 +336,7 @@ public function getConfig(): array 'allowEmptyCartOnCheckout' => $this->getAllowEmptyCartOnCheckout(false), 'allowPartialPaymentOnCheckout' => $this->getAllowPartialPaymentOnCheckout(false), 'autoSetCartShippingMethodOption' => $this->getAutoSetCartShippingMethodOption(false), - 'autoSetNewCartAddresses' => $this->getAutoSetCartShippingMethodOption(false), + 'autoSetNewCartAddresses' => $this->getAutoSetNewCartAddresses(false), 'autoSetPaymentSource' => $this->getAutoSetPaymentSource(false), 'freeOrderPaymentStrategy' => $this->getFreeOrderPaymentStrategy(false), 'handle' => $this->handle, From 9633843b39880ffca065054b1ef839a4511caee8 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 27 Aug 2024 10:52:27 +0800 Subject: [PATCH 08/24] Backport 0a1ddca --- src/services/Customers.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/services/Customers.php b/src/services/Customers.php index f22ec7ec9e..6e1e7364d8 100644 --- a/src/services/Customers.php +++ b/src/services/Customers.php @@ -339,17 +339,29 @@ private function _saveAddressesFromOrder(Order $order): void if ($saveBillingAddress && $saveShippingAddress && $order->hasMatchingAddresses()) { // Only save one address if they are matching - $newAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), ['ownerId' => $order->getCustomer()->id]); + $newAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), + [ + 'primaryOwner' => $order->getCustomer(), + 'owner' => $order->getCustomer(), + ] + ); $newSourceBillingAddressId = $newAddress->id; $newSourceShippingAddressId = $newAddress->id; } else { if ($saveBillingAddress) { - $newBillingAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), ['ownerId' => $order->getCustomer()->id]); + $newBillingAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), + [ + 'primaryOwner' => $order->getCustomer(), + 'owner' => $order->getCustomer(), + ]); $newSourceBillingAddressId = $newBillingAddress->id; } if ($saveShippingAddress) { - $newShippingAddress = Craft::$app->getElements()->duplicateElement($order->getShippingAddress(), ['ownerId' => $order->getCustomer()->id]); + $newShippingAddress = Craft::$app->getElements()->duplicateElement($order->getShippingAddress(), [ + 'primaryOwner' => $order->getCustomer(), + 'owner' => $order->getCustomer(), + ]); $newSourceShippingAddressId = $newShippingAddress->id; } } @@ -365,9 +377,9 @@ private function _saveAddressesFromOrder(Order $order): void // Manually update the order DB record to avoid looped element saves if ($newSourceBillingAddressId || $newSourceShippingAddressId) { \craft\commerce\records\Order::updateAll([ - 'sourceBillingAddressId' => $order->sourceBillingAddressId, - 'sourceShippingAddressId' => $order->sourceShippingAddressId, - ], + 'sourceBillingAddressId' => $order->sourceBillingAddressId, + 'sourceShippingAddressId' => $order->sourceShippingAddressId, + ], [ 'id' => $order->id, ] From cd5216e582caf68301e80ab20d6b18ab03debdcc Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 27 Aug 2024 14:07:00 +0800 Subject: [PATCH 09/24] Set owner to object, not ID --- src/controllers/CartController.php | 11 +++++++++-- src/elements/Order.php | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/controllers/CartController.php b/src/controllers/CartController.php index 0407df92d7..4acd0c1987 100644 --- a/src/controllers/CartController.php +++ b/src/controllers/CartController.php @@ -648,7 +648,11 @@ private function _setAddresses(): void $this->_cart->sourceShippingAddressId = $shippingAddressId; /** @var Address $cartShippingAddress */ - $cartShippingAddress = Craft::$app->getElements()->duplicateElement($userShippingAddress, ['ownerId' => $this->_cart->id]); + $cartShippingAddress = Craft::$app->getElements()->duplicateElement($userShippingAddress, + [ + 'owner' => $this->_cart, + 'primaryOwner' => $this->_cart, + ]); $this->_cart->setShippingAddress($cartShippingAddress); if ($billingIsShipping) { @@ -682,7 +686,10 @@ private function _setAddresses(): void $this->_cart->sourceBillingAddressId = $billingAddressId; /** @var Address $cartBillingAddress */ - $cartBillingAddress = Craft::$app->getElements()->duplicateElement($userBillingAddress, ['ownerId' => $this->_cart->id]); + $cartBillingAddress = Craft::$app->getElements()->duplicateElement($userBillingAddress, [ + 'owner' => $this->_cart, + 'primaryOwner' => $this->_cart, + ]); $this->_cart->setBillingAddress($cartBillingAddress); if ($shippingIsBilling) { diff --git a/src/elements/Order.php b/src/elements/Order.php index 696f998169..5c710d1857 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -1527,14 +1527,22 @@ public function autoSetAddresses(): bool if (!$this->_shippingAddress && !$this->shippingAddressId && $primaryShippingAddress = $user->getPrimaryShippingAddress()) { $this->sourceShippingAddressId = $primaryShippingAddress->id; - $shippingAddress = Craft::$app->getElements()->duplicateElement($primaryShippingAddress, ['ownerId' => $this->id]); + $shippingAddress = Craft::$app->getElements()->duplicateElement($primaryShippingAddress, + [ + 'owner' => $this, + 'primaryOwner' => $this, + ]); $this->setShippingAddress($shippingAddress); $autoSetOccurred = true; } if (!$this->_billingAddress && !$this->billingAddressId && $primaryBillingAddress = $user->getPrimaryBillingAddress()) { $this->sourceBillingAddressId = $primaryBillingAddress->id; - $billingAddress = Craft::$app->getElements()->duplicateElement($primaryBillingAddress, ['ownerId' => $this->id]); + $billingAddress = Craft::$app->getElements()->duplicateElement($primaryBillingAddress, + [ + 'owner' => $this, + 'primaryOwner' => $this, + ]); $this->setBillingAddress($billingAddress); $autoSetOccurred = true; } From c02ad47ed3a6f14378282c96c9f71e8d9896e3d4 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 27 Aug 2024 14:19:01 +0800 Subject: [PATCH 10/24] dont need primary owner in 4.x --- src/controllers/CartController.php | 2 -- src/controllers/OrdersController.php | 15 +++++++++------ src/elements/Order.php | 2 -- src/services/Customers.php | 7 +++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/controllers/CartController.php b/src/controllers/CartController.php index 4acd0c1987..c4ec3d6a69 100644 --- a/src/controllers/CartController.php +++ b/src/controllers/CartController.php @@ -651,7 +651,6 @@ private function _setAddresses(): void $cartShippingAddress = Craft::$app->getElements()->duplicateElement($userShippingAddress, [ 'owner' => $this->_cart, - 'primaryOwner' => $this->_cart, ]); $this->_cart->setShippingAddress($cartShippingAddress); @@ -688,7 +687,6 @@ private function _setAddresses(): void /** @var Address $cartBillingAddress */ $cartBillingAddress = Craft::$app->getElements()->duplicateElement($userBillingAddress, [ 'owner' => $this->_cart, - 'primaryOwner' => $this->_cart, ]); $this->_cart->setBillingAddress($cartBillingAddress); diff --git a/src/controllers/OrdersController.php b/src/controllers/OrdersController.php index e3c02b3a1a..54d882aece 100644 --- a/src/controllers/OrdersController.php +++ b/src/controllers/OrdersController.php @@ -1309,24 +1309,27 @@ private function _updateOrder(Order $order, $orderRequestData, bool $tryAutoSet $order->autoSetAddresses(); } else { - $getAddress = static function($address, $orderId, $title) { - if ($address && ($address['id'] && ($address['ownerId'] != $orderId || isset($address['_copy'])))) { + $getAddress = static function($address, Order $order, $title) { + if ($address && ($address['id'] && ($address['ownerId'] != $order->id || isset($address['_copy'])))) { if (isset($address['_copy'])) { unset($address['_copy']); } $address = Craft::$app->getElements()->getElementById($address['id'], Address::class); - $address = Craft::$app->getElements()->duplicateElement($address, ['ownerId' => $orderId, 'title' => $title]); - } elseif ($address && ($address['id'] && $address['ownerId'] == $orderId)) { + $address = Craft::$app->getElements()->duplicateElement($address, [ + 'owner' => $order, + 'title' => $title + ]); + } elseif ($address && ($address['id'] && $address['ownerId'] == $order->id)) { /** @var Address|null $address */ $address = Address::find()->ownerId($address['ownerId'])->id($address['id'])->one(); } return $address; }; - $billingAddress = $getAddress($submittedBillingAddress, $orderRequestData['order']['id'], Craft::t('commerce', 'Billing Address')); + $billingAddress = $getAddress($submittedBillingAddress, $order, Craft::t('commerce', 'Billing Address')); $order->setBillingAddress($billingAddress); - $shippingAddress = $getAddress($submittedShippingAddress, $orderRequestData['order']['id'], Craft::t('commerce', 'Shipping Address')); + $shippingAddress = $getAddress($submittedShippingAddress, $order, Craft::t('commerce', 'Shipping Address')); $order->setShippingAddress($shippingAddress); if (isset($orderRequestData['order']['sourceBillingAddressId'])) { diff --git a/src/elements/Order.php b/src/elements/Order.php index 5c710d1857..4d476740cd 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -1530,7 +1530,6 @@ public function autoSetAddresses(): bool $shippingAddress = Craft::$app->getElements()->duplicateElement($primaryShippingAddress, [ 'owner' => $this, - 'primaryOwner' => $this, ]); $this->setShippingAddress($shippingAddress); $autoSetOccurred = true; @@ -1541,7 +1540,6 @@ public function autoSetAddresses(): bool $billingAddress = Craft::$app->getElements()->duplicateElement($primaryBillingAddress, [ 'owner' => $this, - 'primaryOwner' => $this, ]); $this->setBillingAddress($billingAddress); $autoSetOccurred = true; diff --git a/src/services/Customers.php b/src/services/Customers.php index 6e1e7364d8..0c439abc5f 100644 --- a/src/services/Customers.php +++ b/src/services/Customers.php @@ -341,7 +341,6 @@ private function _saveAddressesFromOrder(Order $order): void // Only save one address if they are matching $newAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), [ - 'primaryOwner' => $order->getCustomer(), 'owner' => $order->getCustomer(), ] ); @@ -351,7 +350,6 @@ private function _saveAddressesFromOrder(Order $order): void if ($saveBillingAddress) { $newBillingAddress = Craft::$app->getElements()->duplicateElement($order->getBillingAddress(), [ - 'primaryOwner' => $order->getCustomer(), 'owner' => $order->getCustomer(), ]); $newSourceBillingAddressId = $newBillingAddress->id; @@ -359,7 +357,6 @@ private function _saveAddressesFromOrder(Order $order): void if ($saveShippingAddress) { $newShippingAddress = Craft::$app->getElements()->duplicateElement($order->getShippingAddress(), [ - 'primaryOwner' => $order->getCustomer(), 'owner' => $order->getCustomer(), ]); $newSourceShippingAddressId = $newShippingAddress->id; @@ -417,7 +414,9 @@ private function _activateUserFromOrder(Order $order): void } if ($billingAddress || $shippingAddress) { - $newAttributes = ['ownerId' => $user->id]; + $newAttributes = [ + 'owner' => $user + ]; // If there is only one address make sure we don't add duplicates to the user if ($order->hasMatchingAddresses()) { From c7f8d9d4f215667dcbd1a8fdfee2cd1c548a6925 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 13:38:26 +0800 Subject: [PATCH 11/24] Set owner not just ID --- src/services/Orders.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/Orders.php b/src/services/Orders.php index 5e33755d53..87ca64a58f 100644 --- a/src/services/Orders.php +++ b/src/services/Orders.php @@ -273,13 +273,13 @@ public function afterSaveAddressHandler(ModelEvent $event): void foreach ($carts as $cart) { // Update the billing address if ($cart->sourceBillingAddressId === $address->id) { - $newBillingAddress = Craft::$app->getElements()->duplicateElement($address, ['ownerId' => $cart->id, 'title' => Craft::t('commerce', 'Billing Address')]); + $newBillingAddress = Craft::$app->getElements()->duplicateElement($address, ['owner' => $cart, 'title' => Craft::t('commerce', 'Billing Address')]); $cart->billingAddressId = $newBillingAddress->id; } // Update the shipping address if ($cart->sourceShippingAddressId === $address->id) { - $newShippingAddress = Craft::$app->getElements()->duplicateElement($address, ['ownerId' => $cart->id, 'title' => Craft::t('commerce', 'Shipping Address')]); + $newShippingAddress = Craft::$app->getElements()->duplicateElement($address, ['owner' => $cart, 'title' => Craft::t('commerce', 'Shipping Address')]); $cart->shippingAddressId = $newShippingAddress->id; } From 2a6e7b07d1288e25b705c2734590a70cd9edf733 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 13:39:55 +0800 Subject: [PATCH 12/24] Changelog update --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aaedceac3..c2327c5440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed a PHP error that could occur when default addresses were set on a cart. ([#3641](https://github.com/craftcms/commerce/issues/3641)) + ## 4.6.9 - 2024-08-21 - Fixed a bug where available shipping methods were not returned in order of price. ([#3631](https://github.com/craftcms/commerce/issues/3631)) From 1e6a64a50fcb296785361792f064c75148ba5f47 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 18:18:31 +0800 Subject: [PATCH 13/24] Cleanup --- src/controllers/OrdersController.php | 2 +- src/services/Customers.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/OrdersController.php b/src/controllers/OrdersController.php index 54d882aece..e50b1069fd 100644 --- a/src/controllers/OrdersController.php +++ b/src/controllers/OrdersController.php @@ -1317,7 +1317,7 @@ private function _updateOrder(Order $order, $orderRequestData, bool $tryAutoSet $address = Craft::$app->getElements()->getElementById($address['id'], Address::class); $address = Craft::$app->getElements()->duplicateElement($address, [ 'owner' => $order, - 'title' => $title + 'title' => $title, ]); } elseif ($address && ($address['id'] && $address['ownerId'] == $order->id)) { /** @var Address|null $address */ diff --git a/src/services/Customers.php b/src/services/Customers.php index 0c439abc5f..4943ae56d6 100644 --- a/src/services/Customers.php +++ b/src/services/Customers.php @@ -415,7 +415,7 @@ private function _activateUserFromOrder(Order $order): void if ($billingAddress || $shippingAddress) { $newAttributes = [ - 'owner' => $user + 'owner' => $user, ]; // If there is only one address make sure we don't add duplicates to the user From fbdc4617852ab626a1080b5e503e1c597d7e07d3 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 19:05:59 +0800 Subject: [PATCH 14/24] Make sure adjustments always belong to the order --- src/elements/Order.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/elements/Order.php b/src/elements/Order.php index 58c718b1cb..0074c26a13 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2966,6 +2966,12 @@ public function getOrderAdjustments(): array */ public function setAdjustments(array $adjustments): void { + $this->_orderAdjustments = []; + + foreach ($adjustments as $adjustment) { + $adjustment->setOrder($this); + } + $this->_orderAdjustments = $adjustments; } From 315e4cb962a1e50a3b48686fef95b2f6bf9778de Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 20:54:00 +0800 Subject: [PATCH 15/24] include the store config values in the project config during migration --- src/migrations/m221122_055725_multi_store.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/migrations/m221122_055725_multi_store.php b/src/migrations/m221122_055725_multi_store.php index ad024dd928..23182a438e 100644 --- a/src/migrations/m221122_055725_multi_store.php +++ b/src/migrations/m221122_055725_multi_store.php @@ -62,7 +62,42 @@ public function safeUp(): bool $this->addColumn(Table::STORES, 'primary', $this->boolean()->defaultValue(false)->notNull()); } - $config = ['name' => 'Primary Store', 'handle' => 'primaryStore', 'primary' => true]; + $config = [ + 'name' => 'Primary Store', + 'handle' => 'primaryStore', + 'primary' => true, + ]; + + $this->update(table: Table::STORES, + columns: $config, + condition: ['id' => $storeSettings['id']], + updateTimestamp: false + ); + + $configKeys = [ + 'name', + 'handle', + 'primary', + 'allowCheckoutWithoutPayment', + 'allowEmptyCartOnCheckout', + 'allowPartialPaymentOnCheckout', + 'autoSetCartShippingMethodOption', + 'autoSetNewCartAddresses', + 'autoSetPaymentSource', + 'freeOrderPaymentStrategy', + 'minimumTotalPriceStrategy', + 'orderReferenceFormat', + 'requireBillingAddressAtCheckout', + 'requireShippingAddressAtCheckout', + 'requireShippingMethodSelectionAtCheckout', + 'useBillingAddressForTax', + 'validateOrganizationTaxIdAsVatId' + ]; + + $config = (new Query()) + ->select($configKeys) + ->from([Table::STORES]) + ->one(); $this->update(table: Table::STORES, columns: $config, @@ -75,6 +110,7 @@ public function safeUp(): bool ->from([Table::STORES]) ->scalar(); + // Make project config updates $projectConfig = Craft::$app->getProjectConfig(); From aec9a7fb6d7fd0f73ea715ac8e3f420e47c1cafb Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 21:23:17 +0800 Subject: [PATCH 16/24] cleanup --- src/migrations/m221122_055725_multi_store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/migrations/m221122_055725_multi_store.php b/src/migrations/m221122_055725_multi_store.php index 23182a438e..6642694cd0 100644 --- a/src/migrations/m221122_055725_multi_store.php +++ b/src/migrations/m221122_055725_multi_store.php @@ -91,7 +91,7 @@ public function safeUp(): bool 'requireShippingAddressAtCheckout', 'requireShippingMethodSelectionAtCheckout', 'useBillingAddressForTax', - 'validateOrganizationTaxIdAsVatId' + 'validateOrganizationTaxIdAsVatId', ]; $config = (new Query()) From f66f2c881d0a3bc3b9716d3ade570a7060b8ec06 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 28 Aug 2024 22:01:25 +0800 Subject: [PATCH 17/24] Cleanup --- src/services/Customers.php | 1 - src/services/Orders.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/services/Customers.php b/src/services/Customers.php index 3e991baee2..8d6cc567e2 100644 --- a/src/services/Customers.php +++ b/src/services/Customers.php @@ -393,7 +393,6 @@ private function _activateUserFromOrder(Order $order): void } if ($billingAddress || $shippingAddress) { - $newAttributes = [ 'owner' => $user, 'primaryOwner' => $user, diff --git a/src/services/Orders.php b/src/services/Orders.php index c13ec7bb1b..8563b33090 100644 --- a/src/services/Orders.php +++ b/src/services/Orders.php @@ -232,7 +232,7 @@ public function afterSaveAddressHandler(ModelEvent $event): void $newBillingAddress = Craft::$app->getElements()->duplicateElement($address, [ 'primaryOwner' => $cart, 'owner' => $cart, - 'title' => Craft::t('commerce', 'Billing Address') + 'title' => Craft::t('commerce', 'Billing Address'), ]); $cart->billingAddressId = $newBillingAddress->id; } @@ -242,7 +242,7 @@ public function afterSaveAddressHandler(ModelEvent $event): void $newShippingAddress = Craft::$app->getElements()->duplicateElement($address, [ 'primaryOwner' => $cart, 'owner' => $cart, - 'title' => Craft::t('commerce', 'Shipping Address') + 'title' => Craft::t('commerce', 'Shipping Address'), ]); $cart->shippingAddressId = $newShippingAddress->id; } From f68195cd87ff38b9694f138f7376c120ed3a7ee7 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 28 Aug 2024 16:06:23 +0100 Subject: [PATCH 18/24] Finish 4.6.10 [ci skip] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2327c5440..fce265c137 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft Commerce -## Unreleased +## 4.6.10 - 2024-08-28 - Fixed a PHP error that could occur when default addresses were set on a cart. ([#3641](https://github.com/craftcms/commerce/issues/3641)) From 80f6f47ffd128c51c0d80361b5dc92a042647a62 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 28 Aug 2024 16:18:52 +0100 Subject: [PATCH 19/24] Finish 5.0.18 [ci skip] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39e2e1b1c0..e4fa742f42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft Commerce -## 4.6.10 - 2024-08-28 +## 5.0.18 - 2024-08-28 - Fixed a PHP error that could occur when default addresses were set on a cart. ([#3641](https://github.com/craftcms/commerce/issues/3641)) - Fixed a bug were the “Auto Set New Cart Addresses” store setting was not persisting when saved. From 396329b99f140bfeeab763a2d9404b956b9ad236 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Fri, 30 Aug 2024 07:37:11 +0100 Subject: [PATCH 20/24] Fixed `null` `sortOrder` values breaking variant ownership migrations --- CHANGELOG.md | 4 ++++ src/migrations/m231019_110814_update_variant_ownership.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4fa742f42..562f6f3007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed a SQL error that could occur when updating Commerce. + ## 5.0.18 - 2024-08-28 - Fixed a PHP error that could occur when default addresses were set on a cart. ([#3641](https://github.com/craftcms/commerce/issues/3641)) diff --git a/src/migrations/m231019_110814_update_variant_ownership.php b/src/migrations/m231019_110814_update_variant_ownership.php index 00c3314960..3506ab92e6 100644 --- a/src/migrations/m231019_110814_update_variant_ownership.php +++ b/src/migrations/m231019_110814_update_variant_ownership.php @@ -6,6 +6,7 @@ use craft\db\Migration; use craft\db\Query; use craft\db\Table as CraftTable; +use yii\db\Expression; /** * m231019_110814_update_variant_ownership migration. @@ -22,7 +23,7 @@ public function safeUp(): bool ->select([ 'id as elementId', 'productId as ownerId', - 'sortOrder', + new Expression('CASE WHEN [[sortOrder]] is NULL THEN 1 ELSE [[sortOrder]] END as [[sortOrder]]'), ]) ->from([Table::VARIANTS]) ->all(); From e75287a96ad4f0afdcdc638465d0f20aa605b68f Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Fri, 30 Aug 2024 07:37:40 +0100 Subject: [PATCH 21/24] Tidy code and make it more understandable --- .../purchasables/CatalogPricingCustomerConditionRule.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/elements/conditions/purchasables/CatalogPricingCustomerConditionRule.php b/src/elements/conditions/purchasables/CatalogPricingCustomerConditionRule.php index 46a810cfea..cb14a371b0 100644 --- a/src/elements/conditions/purchasables/CatalogPricingCustomerConditionRule.php +++ b/src/elements/conditions/purchasables/CatalogPricingCustomerConditionRule.php @@ -91,10 +91,9 @@ public function getExclusiveQueryParams(): array */ public function modifyQuery(Query $query): void { - if (!$this->customerId) { - return; - } + return; - // $query->andWhere(['purchasableId' => $ids]); + // Doesn't modify the query as the modification + // of the query happens in `CatalogPricingCondition::modifyQuery()` for this rule } } From 129326cec237478906c0abe42929bd1d9f112c2d Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 3 Sep 2024 11:51:15 +0100 Subject: [PATCH 22/24] only save inventory record if new; track inventoryItemId --- src/base/Purchasable.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base/Purchasable.php b/src/base/Purchasable.php index 0c07ad3426..40ebf4bd1e 100644 --- a/src/base/Purchasable.php +++ b/src/base/Purchasable.php @@ -994,9 +994,11 @@ public function afterSave(bool $isNew): void $inventoryItem->countryCodeOfOrigin = ''; $inventoryItem->administrativeAreaCodeOfOrigin = ''; $inventoryItem->harmonizedSystemCode = ''; + $inventoryItem->save(); } - $inventoryItem->save(); + $this->inventoryItemId = $inventoryItem->id; + } } From 24686e0ee828bb6f7ce16c7cb5dabf7ddb5622a7 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 3 Sep 2024 16:44:08 +0100 Subject: [PATCH 23/24] fix cs --- src/base/Purchasable.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/base/Purchasable.php b/src/base/Purchasable.php index 40ebf4bd1e..b1525548b5 100644 --- a/src/base/Purchasable.php +++ b/src/base/Purchasable.php @@ -998,7 +998,6 @@ public function afterSave(bool $isNew): void } $this->inventoryItemId = $inventoryItem->id; - } } From 74b11b791ff14b6796ba1bacd2f1979f8a0bc074 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 3 Sep 2024 16:46:58 +0100 Subject: [PATCH 24/24] Add `@var` doc for PHPStan --- src/base/Purchasable.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/Purchasable.php b/src/base/Purchasable.php index b1525548b5..9e438678a8 100644 --- a/src/base/Purchasable.php +++ b/src/base/Purchasable.php @@ -987,6 +987,7 @@ public function afterSave(bool $isNew): void // added to inventory before it is saved as a permanent variant. if ($purchasableId) { // Set the inventory item data + /** @var InventoryItem|null $inventoryItem */ $inventoryItem = InventoryItemRecord::find()->where(['purchasableId' => $purchasableId])->one(); if (!$inventoryItem) { $inventoryItem = new InventoryItemRecord();