From 5b64b1fccef4d3980227724fe16c98531511bdd4 Mon Sep 17 00:00:00 2001 From: August Miller Date: Tue, 5 Sep 2023 10:44:49 -0700 Subject: [PATCH 01/29] Remove legacy Order::availableShippingMethods hint --- src/elements/Order.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 56061cdf25..205257fa66 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -88,7 +88,6 @@ * @property string $recalculationMode the mode of recalculation. * @property string $origin * @property int|null $customerId The order customer ID - * @property-read ShippingMethod[] $availableShippingMethods * @property-read bool $activeCart Is the current order the same as the active cart * @property-read User|null $customer * @property-read Gateway $gateway From 6b5173e1d2e76d8c8f8bf15ed0474b7167731da2 Mon Sep 17 00:00:00 2001 From: August Miller Date: Tue, 5 Sep 2023 10:45:05 -0700 Subject: [PATCH 02/29] Make availableShippingMethodOptions hint read-only --- src/elements/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 205257fa66..d26f6411f8 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -148,7 +148,7 @@ * @property float $totalTaxIncluded * @property float $totalTax * @property float $totalShippingCost - * @property ShippingMethodOption[] $availableShippingMethodOptions + * @property-read ShippingMethodOption[] $availableShippingMethodOptions * @property-read float|int $totalAuthorized * @property float $paymentAmount * @property-read null|string $loadCartUrl From 94dd13e84ba2622499dbb081d90ee15dd634110a Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 18 Oct 2023 11:36:32 +0800 Subject: [PATCH 03/29] Fixes #3279 --- CHANGELOG.md | 1 + src/adjusters/Shipping.php | 4 ++-- src/base/ShippingMethod.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f04b1e806..179b0557f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed an XSS vulnerability. - Fixed a bug where emails were not being ordered by name correctly. ([#3263](https://github.com/craftcms/commerce/issues/3263)) - Fixed a bug where a gateway’s webhook URL was malformed. ([#3299](https://github.com/craftcms/commerce/issues/3299)) +- The order param is now included when triggering the `craft\commerce\services\Purchasables::EVENT_PURCHASABLE_SHIPPABLE` event. ([#3279](https://github.com/craftcms/commerce/pull/3279)) ## 3.4.22.1 - 2023-06-03 diff --git a/src/adjusters/Shipping.php b/src/adjusters/Shipping.php index e3280f7f54..a96b60fad4 100644 --- a/src/adjusters/Shipping.php +++ b/src/adjusters/Shipping.php @@ -64,7 +64,7 @@ public function adjust(Order $order): array foreach ($lineItems as $item) { $purchasable = $item->getPurchasable(); - if ($purchasable && !Plugin::getInstance()->getPurchasables()->isPurchasableShippable($purchasable)) { + if ($purchasable && !Plugin::getInstance()->getPurchasables()->isPurchasableShippable($purchasable, $order)) { $nonShippableItems[$item->id] = $item->id; } } @@ -125,7 +125,7 @@ public function adjust(Order $order): array } $freeShippingFlagOnProduct = $item->purchasable->hasFreeShipping(); - $shippable = Plugin::getInstance()->getPurchasables()->isPurchasableShippable($item->getPurchasable()); + $shippable = Plugin::getInstance()->getPurchasables()->isPurchasableShippable($item->getPurchasable(), $order); if (!$freeShippingFlagOnProduct && !$hasFreeShippingFromDiscount && $shippable) { $adjustment = $this->_createAdjustment($shippingMethod, $rule); diff --git a/src/base/ShippingMethod.php b/src/base/ShippingMethod.php index e57c6b7668..6b251f49f0 100644 --- a/src/base/ShippingMethod.php +++ b/src/base/ShippingMethod.php @@ -162,7 +162,7 @@ public function getPriceForOrder(Order $order) foreach ($lineItems as $item) { $purchasable = $item->getPurchasable(); - if ($purchasable && !Plugin::getInstance()->getPurchasables()->isPurchasableShippable($purchasable)) { + if ($purchasable && !Plugin::getInstance()->getPurchasables()->isPurchasableShippable($purchasable, $order)) { $nonShippableItems[$item->id] = $item->id; } } @@ -175,7 +175,7 @@ public function getPriceForOrder(Order $order) $amount = $shippingRule->getBaseRate(); foreach ($order->lineItems as $item) { - if ($item->getPurchasable() && !$item->purchasable->hasFreeShipping() && Plugin::getInstance()->getPurchasables()->isPurchasableShippable($item->getPurchasable())) { + if ($item->getPurchasable() && !$item->purchasable->hasFreeShipping() && Plugin::getInstance()->getPurchasables()->isPurchasableShippable($item->getPurchasable(), $order)) { $percentageRate = $shippingRule->getPercentageRate($item->shippingCategoryId); $perItemRate = $shippingRule->getPerItemRate($item->shippingCategoryId); $weightRate = $shippingRule->getWeightRate($item->shippingCategoryId); From 8d31b99b9ffc5c93f41982dc94798ec5911e989c Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 18 Oct 2023 20:42:38 +0800 Subject: [PATCH 04/29] Dont override title if one is already set --- src/elements/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index ac719ba659..41344c7028 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2927,7 +2927,7 @@ public function setShippingAddress(AddressElement|array|null $address): void } $this->shippingAddressId = $address->id; - $address->title = Craft::t('commerce', 'Shipping Address'); + $address->title = $address->title ?: Craft::t('commerce', 'Shipping Address'); $this->_shippingAddress = $address; } @@ -3022,7 +3022,7 @@ public function setBillingAddress(AddressElement|array|null $address): void $address->ownerId = $this->id; $this->billingAddressId = $address->id; - $address->title = Craft::t('commerce', 'Billing Address'); + $address->title = $address->title ?: Craft::t('commerce', 'Billing Address'); $this->_billingAddress = $address; } From c71ff549b7212be721f7f285d4f0072ae58d07bc Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 18 Oct 2023 09:36:59 -0700 Subject: [PATCH 05/29] 4.3.0 included #3267 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c747418cd2..081b1f7f0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Fixed a bug where Commerce wasn’t invoking `craft\services\Elements::EVENT_AUTHORIZE_*` event handlers. - Fixed a bug where discounts’ per user usage counters weren’t getting migrated properly when upgrading to Commerce 4. - Fixed a bug where address changes weren’t being synced to carts that were using them. ([#3178](https://github.com/craftcms/commerce/issues/3178)) +- Fixed a SQL error that could occur when fetching emails. ([#3267](https://github.com/craftcms/commerce/pull/3267)) - Fixed an XSS vulnerability. ## 4.2.11 - 2023-06-05 From 9efb621e0bd30df54b99c64808983874564e2734 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 18 Oct 2023 09:40:28 -0700 Subject: [PATCH 06/29] 4.3.1 fixed #3299 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aa44726c5..97f8c28b86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Fixed a bug where sales’ and discounts’ timestamps weren’t getting populated. ([#3298](https://github.com/craftcms/commerce/issues/3298)) - Fixed a bug where the `commerce/upgrade` command could create duplicate inactive users. ([#3286](https://github.com/craftcms/commerce/issues/3286)) - Fixed a bug where `commerce/payments/pay` JSON responses were missing the `redirect` key. ([#3265](https://github.com/craftcms/commerce/issues/3265)) +- Fixed a bug where gateway URLs could be malformed. ([#3299](https://github.com/craftcms/commerce/issues/3299)) ## 4.3.0 - 2023-09-13 From fc7be6ec00aa33be8666a276653677340c8fa06d Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 18 Oct 2023 09:43:09 -0700 Subject: [PATCH 07/29] Changelog tweaks --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 179b0557f2..b490a02b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ ## Unreleased +- `craft\commerce\services\Purchasables::EVENT_PURCHASABLE_SHIPPABLE` event handlers can now access the order. ([#3279](https://github.com/craftcms/commerce/pull/3279)) +- Fixed a SQL error that could occur when fetching emails. ([#3267](https://github.com/craftcms/commerce/pull/3267)) +- Fixed a bug where gateway URLs could be malformed. ([#3299](https://github.com/craftcms/commerce/issues/3299)) - Fixed an XSS vulnerability. -- Fixed a bug where emails were not being ordered by name correctly. ([#3263](https://github.com/craftcms/commerce/issues/3263)) -- Fixed a bug where a gateway’s webhook URL was malformed. ([#3299](https://github.com/craftcms/commerce/issues/3299)) -- The order param is now included when triggering the `craft\commerce\services\Purchasables::EVENT_PURCHASABLE_SHIPPABLE` event. ([#3279](https://github.com/craftcms/commerce/pull/3279)) ## 3.4.22.1 - 2023-06-03 From bc11b8a3db4584b60438b5dfdff028433afeb52f Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 18 Oct 2023 18:17:09 +0100 Subject: [PATCH 08/29] Finish 3.4.23 --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b490a02b4b..daac66dedd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft Commerce -## Unreleased +## 3.4.23 - 2023-10-18 - `craft\commerce\services\Purchasables::EVENT_PURCHASABLE_SHIPPABLE` event handlers can now access the order. ([#3279](https://github.com/craftcms/commerce/pull/3279)) - Fixed a SQL error that could occur when fetching emails. ([#3267](https://github.com/craftcms/commerce/pull/3267)) diff --git a/composer.json b/composer.json index b0180cbcf9..e98782d365 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ }, "extra": { "handle": "commerce", - "version": "3.4.22.1", + "version": "3.4.23", "name": "Craft Commerce", "description": "Create beautifully bespoke ecommerce experiences", "developer": "Pixel & Tonic", From e890b8927467aa0accb601923d042557f73feafc Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Thu, 19 Oct 2023 15:20:32 +0800 Subject: [PATCH 09/29] Dont allow title change for now --- src/elements/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 41344c7028..ac719ba659 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2927,7 +2927,7 @@ public function setShippingAddress(AddressElement|array|null $address): void } $this->shippingAddressId = $address->id; - $address->title = $address->title ?: Craft::t('commerce', 'Shipping Address'); + $address->title = Craft::t('commerce', 'Shipping Address'); $this->_shippingAddress = $address; } @@ -3022,7 +3022,7 @@ public function setBillingAddress(AddressElement|array|null $address): void $address->ownerId = $this->id; $this->billingAddressId = $address->id; - $address->title = $address->title ?: Craft::t('commerce', 'Billing Address'); + $address->title = Craft::t('commerce', 'Billing Address'); $this->_billingAddress = $address; } From 0e220a4e710009082e718d34d8ec4c306ce1bc42 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Thu, 19 Oct 2023 14:26:26 +0200 Subject: [PATCH 10/29] Extend product default variant fields and arguments --- src/gql/arguments/elements/Product.php | 25 +++++++++++++++++++++ src/gql/interfaces/elements/Product.php | 30 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/gql/arguments/elements/Product.php b/src/gql/arguments/elements/Product.php index 63bf304cf2..5529126979 100644 --- a/src/gql/arguments/elements/Product.php +++ b/src/gql/arguments/elements/Product.php @@ -34,11 +34,36 @@ public static function getArguments(): array 'type' => Type::boolean(), 'description' => 'Whether to only return products that are available to purchase.', ], + 'defaultSku' => [ + 'name' => 'defaultSku', + 'type' => Type::listOf(QueryArgument::getType()), + 'description' => 'Narrows the query results based on the default SKU on the product.', + ], 'defaultPrice' => [ 'name' => 'defaultPrice', 'type' => Type::listOf(QueryArgument::getType()), 'description' => 'Narrows the query results based on the default price on the product.', ], + 'defaultHeight' => [ + 'name' => 'defaultHeight', + 'type' => Type::listOf(QueryArgument::getType()), + 'description' => 'Narrows the query results based on the default height on the product.', + ], + 'defaultLength' => [ + 'name' => 'defaultLength', + 'type' => Type::listOf(QueryArgument::getType()), + 'description' => 'Narrows the query results based on the default length on the product.', + ], + 'defaultWidth' => [ + 'name' => 'defaultWidth', + 'type' => Type::listOf(QueryArgument::getType()), + 'description' => 'Narrows the query results based on the default width on the product.', + ], + 'defaultWeight' => [ + 'name' => 'defaultWeight', + 'type' => Type::listOf(QueryArgument::getType()), + 'description' => 'Narrows the query results based on the default weight on the product.', + ], 'editable' => [ 'name' => 'editable', 'type' => Type::boolean(), diff --git a/src/gql/interfaces/elements/Product.php b/src/gql/interfaces/elements/Product.php index d1478bf823..dd1a78df86 100644 --- a/src/gql/interfaces/elements/Product.php +++ b/src/gql/interfaces/elements/Product.php @@ -73,6 +73,11 @@ public static function getFieldDefinitions(): array 'type' => Type::boolean(), 'description' => 'If the product is available for purchase.', ], + 'defaultSku' => [ + 'name' => 'defaultSku', + 'type' => Type::string(), + 'description' => 'The SKU of the default variant for the product.', + ], 'defaultPrice' => [ 'name' => 'defaultPrice', 'type' => Type::float(), @@ -83,6 +88,31 @@ public static function getFieldDefinitions(): array 'type' => Type::string(), 'description' => 'The formatted price of the default variant for the product.', ], + 'defaultHeight' => [ + 'name' => 'defaultHeight', + 'type' => Type::float(), + 'description' => 'The height of the default variant for the product.', + ], + 'defaultLength' => [ + 'name' => 'defaultLength', + 'type' => Type::float(), + 'description' => 'The length of the default variant for the product.', + ], + 'defaultWidth' => [ + 'name' => 'defaultWidth', + 'type' => Type::float(), + 'description' => 'The width of the default variant for the product.', + ], + 'defaultWeight' => [ + 'name' => 'defaultWeight', + 'type' => Type::float(), + 'description' => 'The weight of the default variant for the product.', + ], + 'defaultVariant' => [ + 'name' => 'defaultVariant', + 'type' => Variant::getType(), + 'description' => 'The default variant for the product.', + ], 'productTypeId' => [ 'name' => 'productTypeId', 'type' => Type::int(), From 7fd03a4984741f21df936255bd4bcf4d24e8561d Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Thu, 19 Oct 2023 14:28:57 +0200 Subject: [PATCH 11/29] Added promotable and free shipping --- src/gql/arguments/elements/Product.php | 10 ++++++++++ src/gql/interfaces/elements/Product.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/gql/arguments/elements/Product.php b/src/gql/arguments/elements/Product.php index 5529126979..c6b23a97ec 100644 --- a/src/gql/arguments/elements/Product.php +++ b/src/gql/arguments/elements/Product.php @@ -29,11 +29,21 @@ class Product extends ElementArguments public static function getArguments(): array { return array_merge(parent::getArguments(), self::getContentArguments(), [ + 'promotable' => [ + 'name' => 'promotable', + 'type' => Type::boolean(), + 'description' => 'Whether to only return products that are promotable.', + ], 'availableForPurchase' => [ 'name' => 'availableForPurchase', 'type' => Type::boolean(), 'description' => 'Whether to only return products that are available to purchase.', ], + 'freeShipping' => [ + 'name' => 'freeShipping', + 'type' => Type::boolean(), + 'description' => 'Whether to only return products that have free shipping.', + ], 'defaultSku' => [ 'name' => 'defaultSku', 'type' => Type::listOf(QueryArgument::getType()), diff --git a/src/gql/interfaces/elements/Product.php b/src/gql/interfaces/elements/Product.php index dd1a78df86..b22d7ed2c4 100644 --- a/src/gql/interfaces/elements/Product.php +++ b/src/gql/interfaces/elements/Product.php @@ -68,11 +68,21 @@ public static function getName(): string public static function getFieldDefinitions(): array { return Craft::$app->getGql()->prepareFieldDefinitions(array_merge(parent::getFieldDefinitions(), [ + 'promotable' => [ + 'name' => 'promotable', + 'type' => Type::boolean(), + 'description' => 'If the product is promotable.', + ], 'availableForPurchase' => [ 'name' => 'availableForPurchase', 'type' => Type::boolean(), 'description' => 'If the product is available for purchase.', ], + 'freeShipping' => [ + 'name' => 'freeShipping', + 'type' => Type::boolean(), + 'description' => 'If the product has free shipping.', + ], 'defaultSku' => [ 'name' => 'defaultSku', 'type' => Type::string(), From a3773c0df94b92fe9eefa130fec0a903a08e7208 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Fri, 20 Oct 2023 12:04:10 +0100 Subject: [PATCH 12/29] Fixed soft-deleted tax categories being selectable --- CHANGELOG.md | 4 ++++ src/services/TaxCategories.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80f3de9e5e..362e3c80fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Fixed a bug where it was possible to select soft-deleted tax categories. + ## 4.3.1 - 2023-10-18 - Added the `commerce/gateways/list` command. diff --git a/src/services/TaxCategories.php b/src/services/TaxCategories.php index 2b5676f09a..d9563ef7f7 100644 --- a/src/services/TaxCategories.php +++ b/src/services/TaxCategories.php @@ -249,7 +249,7 @@ public function getTaxCategoriesByProductTypeId(int $productTypeId): array { $rows = $this->_createTaxCategoryQuery() ->innerJoin(Table::PRODUCTTYPES_TAXCATEGORIES . ' productTypeTaxCategories', '[[taxCategories.id]] = [[productTypeTaxCategories.taxCategoryId]]') - ->where(['productTypeTaxCategories.productTypeId' => $productTypeId]) + ->andWhere(['productTypeTaxCategories.productTypeId' => $productTypeId]) ->all(); if (empty($rows)) { From 05120f3d2005dae2350bf28fc31afb8e8689438c Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 24 Oct 2023 07:50:09 +0100 Subject: [PATCH 13/29] Fix collapsing add address button in example templates --- example-templates/dist/shop/_private/address/list.twig | 2 +- example-templates/src/shop/_private/address/list.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example-templates/dist/shop/_private/address/list.twig b/example-templates/dist/shop/_private/address/list.twig index 2386f7dff5..0acd99c1f6 100644 --- a/example-templates/dist/shop/_private/address/list.twig +++ b/example-templates/dist/shop/_private/address/list.twig @@ -62,7 +62,7 @@ {% endfor %} {% if showAdd %} - +
Add Address diff --git a/example-templates/src/shop/_private/address/list.twig b/example-templates/src/shop/_private/address/list.twig index d653691ea6..2b9cb542f0 100644 --- a/example-templates/src/shop/_private/address/list.twig +++ b/example-templates/src/shop/_private/address/list.twig @@ -62,7 +62,7 @@
{% endfor %} {% if showAdd %} -
+
Add Address From 9748053478f4bc32905c1536e73ce112def7a91e Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 24 Oct 2023 16:28:50 +0800 Subject: [PATCH 14/29] Fixed #3309 --- CHANGELOG.md | 1 + src/Plugin.php | 11 +++++++++++ src/services/Emails.php | 13 +++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7f4a9f0a..eff69345fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fixed a bug where it was possible to select soft-deleted tax categories. +- Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) ## 4.3.1 - 2023-10-18 diff --git a/src/Plugin.php b/src/Plugin.php index bfc3554e7a..e131621e89 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -271,6 +271,17 @@ public function init(): void } Craft::setAlias('@commerceLib', Craft::getAlias('@craft/commerce/../lib')); + + Event::on( + BaseFrontEndController::class, + BaseFrontEndController::EVENT_MODIFY_CART_INFO, + function(ModifyCartInfoEvent $e) { + $cartArray = $e->cartInfo; + $cartArray['anotherOne'] = 'Howdy'; + $e->cartInfo = $cartArray; + } + ); + } /** diff --git a/src/services/Emails.php b/src/services/Emails.php index 3c2854c73a..a2b5ae8190 100644 --- a/src/services/Emails.php +++ b/src/services/Emails.php @@ -691,9 +691,18 @@ public function sendEmail(Email $email, Order $order, ?OrderHistory $orderHistor file_put_contents($tempPath, $renderedPdf); - $fileName = $view->renderObjectTemplate($pdf->fileNameFormat, $order); + $fileName = ''; + $defaultFileName = $pdf->handle . '-' . $order->number; + if($pdf->fileNameFormat) { + try { + $fileName = $view->renderObjectTemplate($pdf->fileNameFormat, $order); + }catch (\Throwable $e){ + $fileName = $defaultFileName; + } + } + if (!$fileName) { - $fileName = $pdf->handle . '-' . $order->number; + $fileName = $defaultFileName; } // Attachment information From 60e3f447ece5a2f9881d76b82cd6ae9692f98234 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 24 Oct 2023 10:16:17 +0100 Subject: [PATCH 15/29] Fixed #3313 example templates redirects for mult site installs --- example-templates/dist/shop/_private/address/list.twig | 4 ++-- .../dist/shop/_private/layouts/includes/header.twig | 2 +- example-templates/dist/shop/cart/index.twig | 2 +- example-templates/dist/shop/cart/load.twig | 2 +- example-templates/dist/shop/checkout/pay-static.twig | 2 +- example-templates/dist/shop/checkout/register-signin.twig | 2 +- example-templates/dist/shop/customer/cards.twig | 8 ++++---- example-templates/dist/shop/customer/index.twig | 2 +- example-templates/dist/shop/customer/orders.twig | 2 +- example-templates/src/shop/_private/address/list.twig | 4 ++-- .../src/shop/_private/layouts/includes/header.twig | 2 +- example-templates/src/shop/cart/index.twig | 2 +- example-templates/src/shop/cart/load.twig | 2 +- example-templates/src/shop/checkout/pay-static.twig | 2 +- example-templates/src/shop/checkout/register-signin.twig | 2 +- example-templates/src/shop/customer/cards.twig | 8 ++++---- example-templates/src/shop/customer/index.twig | 2 +- example-templates/src/shop/customer/orders.twig | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/example-templates/dist/shop/_private/address/list.twig b/example-templates/dist/shop/_private/address/list.twig index 0acd99c1f6..77cc2cd8bd 100644 --- a/example-templates/dist/shop/_private/address/list.twig +++ b/example-templates/dist/shop/_private/address/list.twig @@ -4,12 +4,12 @@ {% set primaryShippingAddressId = primaryShippingAddressId ?? null %} {% set showDelete = showDelete ?? false %} {% set showAdd = showAdd ?? false %} -{% set addUrl = '/shop/customer/addresses/edit?redirect=' ~ craft.app.request.fullPath %} +{% set addUrl = siteUrl('shop/customer/addresses/edit?redirect=' ~ craft.app.request.pathInfo) %} {% if currentUser %}
{% for address in addresses %} - {% set editUrl = '/shop/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %} + {% set editUrl = 'shop/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.pathInfo %}
{% tag selectable ? 'label' : 'div' with { class: 'block relative address-select js-address-select', diff --git a/example-templates/dist/shop/_private/layouts/includes/header.twig b/example-templates/dist/shop/_private/layouts/includes/header.twig index 4c479235f4..b07c1b9a39 100644 --- a/example-templates/dist/shop/_private/layouts/includes/header.twig +++ b/example-templates/dist/shop/_private/layouts/includes/header.twig @@ -1,7 +1,7 @@

- + {{- siteName ~ ' Shop' -}}

diff --git a/example-templates/dist/shop/cart/index.twig b/example-templates/dist/shop/cart/index.twig index f29aa0e14c..491d2a8acc 100644 --- a/example-templates/dist/shop/cart/index.twig +++ b/example-templates/dist/shop/cart/index.twig @@ -320,7 +320,7 @@ Outputs cart. {% else %}

{{ 'Empty cart. Add items on the {link} page.'|t({ - link: tag('a', { href: url('/shop/products'), text: 'products', class: 'underline' }) + link: tag('a', { href: url('shop/products'), text: 'products', class: 'underline' }) })|raw }}

{% endif %} {% endblock %} diff --git a/example-templates/dist/shop/cart/load.twig b/example-templates/dist/shop/cart/load.twig index ff95d1c12e..dfe8d144d9 100644 --- a/example-templates/dist/shop/cart/load.twig +++ b/example-templates/dist/shop/cart/load.twig @@ -7,7 +7,7 @@ Outputs form for collecting a cart number to be loaded.
{{ csrfInput() }} {{ actionInput('commerce/cart/load-cart') }} - {{ redirectInput('/shop/cart') }} + {{ redirectInput('shop/cart') }}

{{- 'Load Cart'|t -}} diff --git a/example-templates/dist/shop/checkout/pay-static.twig b/example-templates/dist/shop/checkout/pay-static.twig index be6cb9abc2..3243e735fa 100644 --- a/example-templates/dist/shop/checkout/pay-static.twig +++ b/example-templates/dist/shop/checkout/pay-static.twig @@ -137,7 +137,7 @@ > {{ csrfInput() }} {{ hiddenInput('action', 'commerce/payments/pay') }} - {{ redirectInput('/shop/customer/order?number=' ~ cart.number ~ '&success=true') }} + {{ redirectInput('shop/customer/order?number=' ~ cart.number ~ '&success=true') }} {{ hiddenInput('cancelUrl', craft.app.request.getUrl()|hash) }} {{ hiddenInput('email', email) }} {{ hiddenInput('number', cart.number) }} diff --git a/example-templates/dist/shop/checkout/register-signin.twig b/example-templates/dist/shop/checkout/register-signin.twig index 2b43956013..19e0b2a75d 100644 --- a/example-templates/dist/shop/checkout/register-signin.twig +++ b/example-templates/dist/shop/checkout/register-signin.twig @@ -54,7 +54,7 @@ {{- 'Checkout'|t -}}

diff --git a/example-templates/dist/shop/customer/cards.twig b/example-templates/dist/shop/customer/cards.twig index d9ff069a3b..66e6c8f10c 100644 --- a/example-templates/dist/shop/customer/cards.twig +++ b/example-templates/dist/shop/customer/cards.twig @@ -33,7 +33,7 @@ {% if paymentSource.id != currentUser.primaryPaymentSourceId %} {{ csrfInput() }} - {{ redirectInput('/shop/customer/cards') }} + {{ redirectInput('shop/customer/cards') }} {{ actionInput('commerce/payment-sources/set-primary-payment-source') }} {{ hiddenInput('id', paymentSource.id) }} {{ tag('button', { @@ -45,7 +45,7 @@ {% endif %} {{ csrfInput() }} - {{ redirectInput('/shop/customer/cards') }} + {{ redirectInput('shop/customer/cards') }} {{ actionInput('commerce/payment-sources/delete') }} {{ hiddenInput('id', paymentSource.id) }} {{ tag('button', { @@ -118,8 +118,8 @@ {{ actionInput('commerce/payment-sources/add') }} {{ hiddenInput('gatewayId', gateway.id) }} {{ hiddenInput('successMessage', 'Added payment source.'|hash) }} - {{ hiddenInput('cancelUrl', '/shop/customer/cards'|hash) }} - {{ redirectInput('/shop/customer/cards') }} + {{ hiddenInput('cancelUrl', 'shop/customer/cards'|hash) }} + {{ redirectInput('shop/customer/cards') }} {% set params = {} %} diff --git a/example-templates/dist/shop/customer/index.twig b/example-templates/dist/shop/customer/index.twig index a81ea21b8f..6ac51a0473 100644 --- a/example-templates/dist/shop/customer/index.twig +++ b/example-templates/dist/shop/customer/index.twig @@ -1 +1 @@ -{% redirect '/shop/customer/orders' %} \ No newline at end of file +{% redirect 'shop/customer/orders' %} \ No newline at end of file diff --git a/example-templates/dist/shop/customer/orders.twig b/example-templates/dist/shop/customer/orders.twig index a529a91cf6..41b113970a 100644 --- a/example-templates/dist/shop/customer/orders.twig +++ b/example-templates/dist/shop/customer/orders.twig @@ -8,7 +8,7 @@ {% endset %} {% if not currentUser %} - {% redirect '/shop/customer/sign-in' %} + {% redirect 'shop/customer/sign-in' %} {% endif %} diff --git a/example-templates/src/shop/_private/address/list.twig b/example-templates/src/shop/_private/address/list.twig index 2b9cb542f0..7ac0907a1d 100644 --- a/example-templates/src/shop/_private/address/list.twig +++ b/example-templates/src/shop/_private/address/list.twig @@ -4,12 +4,12 @@ {% set primaryShippingAddressId = primaryShippingAddressId ?? null %} {% set showDelete = showDelete ?? false %} {% set showAdd = showAdd ?? false %} -{% set addUrl = '/[[folderName]]/customer/addresses/edit?redirect=' ~ craft.app.request.fullPath %} +{% set addUrl = siteUrl('[[folderName]]/customer/addresses/edit?redirect=' ~ craft.app.request.pathInfo) %} {% if currentUser %}
{% for address in addresses %} - {% set editUrl = '/[[folderName]]/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %} + {% set editUrl = '[[folderName]]/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.pathInfo %}
{% tag selectable ? 'label' : 'div' with { class: 'block relative address-select js-address-select', diff --git a/example-templates/src/shop/_private/layouts/includes/header.twig b/example-templates/src/shop/_private/layouts/includes/header.twig index 2ade3b4c26..8a26e093b7 100644 --- a/example-templates/src/shop/_private/layouts/includes/header.twig +++ b/example-templates/src/shop/_private/layouts/includes/header.twig @@ -1,7 +1,7 @@

- + {{- siteName ~ ' Shop' -}}

diff --git a/example-templates/src/shop/cart/index.twig b/example-templates/src/shop/cart/index.twig index 792e2da572..da3d962f89 100755 --- a/example-templates/src/shop/cart/index.twig +++ b/example-templates/src/shop/cart/index.twig @@ -320,7 +320,7 @@ Outputs cart. {% else %}

{{ 'Empty cart. Add items on the {link} page.'|t({ - link: tag('a', { href: url('/[[folderName]]/products'), text: 'products', class: 'underline' }) + link: tag('a', { href: url('[[folderName]]/products'), text: 'products', class: 'underline' }) })|raw }}

{% endif %} {% endblock %} diff --git a/example-templates/src/shop/cart/load.twig b/example-templates/src/shop/cart/load.twig index 5a22b9b9dd..563f666899 100644 --- a/example-templates/src/shop/cart/load.twig +++ b/example-templates/src/shop/cart/load.twig @@ -7,7 +7,7 @@ Outputs form for collecting a cart number to be loaded.
{{ csrfInput() }} {{ actionInput('commerce/cart/load-cart') }} - {{ redirectInput('/[[folderName]]/cart') }} + {{ redirectInput('[[folderName]]/cart') }}

{{- 'Load Cart'|t -}} diff --git a/example-templates/src/shop/checkout/pay-static.twig b/example-templates/src/shop/checkout/pay-static.twig index 9ea1341431..96aa568bc2 100755 --- a/example-templates/src/shop/checkout/pay-static.twig +++ b/example-templates/src/shop/checkout/pay-static.twig @@ -137,7 +137,7 @@ > {{ csrfInput() }} {{ hiddenInput('action', 'commerce/payments/pay') }} - {{ redirectInput('/[[folderName]]/customer/order?number=' ~ cart.number ~ '&success=true') }} + {{ redirectInput('[[folderName]]/customer/order?number=' ~ cart.number ~ '&success=true') }} {{ hiddenInput('cancelUrl', craft.app.request.getUrl()|hash) }} {{ hiddenInput('email', email) }} {{ hiddenInput('number', cart.number) }} diff --git a/example-templates/src/shop/checkout/register-signin.twig b/example-templates/src/shop/checkout/register-signin.twig index 0313eb56fc..402658c58f 100755 --- a/example-templates/src/shop/checkout/register-signin.twig +++ b/example-templates/src/shop/checkout/register-signin.twig @@ -54,7 +54,7 @@ {{- 'Checkout'|t -}}

diff --git a/example-templates/src/shop/customer/cards.twig b/example-templates/src/shop/customer/cards.twig index 05af55ca93..d7d2167066 100755 --- a/example-templates/src/shop/customer/cards.twig +++ b/example-templates/src/shop/customer/cards.twig @@ -33,7 +33,7 @@ {% if paymentSource.id != currentUser.primaryPaymentSourceId %} {{ csrfInput() }} - {{ redirectInput('/[[folderName]]/customer/cards') }} + {{ redirectInput('[[folderName]]/customer/cards') }} {{ actionInput('commerce/payment-sources/set-primary-payment-source') }} {{ hiddenInput('id', paymentSource.id) }} {{ tag('button', { @@ -45,7 +45,7 @@ {% endif %} {{ csrfInput() }} - {{ redirectInput('/[[folderName]]/customer/cards') }} + {{ redirectInput('[[folderName]]/customer/cards') }} {{ actionInput('commerce/payment-sources/delete') }} {{ hiddenInput('id', paymentSource.id) }} {{ tag('button', { @@ -118,8 +118,8 @@ {{ actionInput('commerce/payment-sources/add') }} {{ hiddenInput('gatewayId', gateway.id) }} {{ hiddenInput('successMessage', 'Added payment source.'|hash) }} - {{ hiddenInput('cancelUrl', '/[[folderName]]/customer/cards'|hash) }} - {{ redirectInput('/[[folderName]]/customer/cards') }} + {{ hiddenInput('cancelUrl', '[[folderName]]/customer/cards'|hash) }} + {{ redirectInput('[[folderName]]/customer/cards') }} {% set params = {} %} diff --git a/example-templates/src/shop/customer/index.twig b/example-templates/src/shop/customer/index.twig index 0de4cfcea7..28a4be4ab4 100755 --- a/example-templates/src/shop/customer/index.twig +++ b/example-templates/src/shop/customer/index.twig @@ -1 +1 @@ -{% redirect '/[[folderName]]/customer/orders' %} \ No newline at end of file +{% redirect '[[folderName]]/customer/orders' %} \ No newline at end of file diff --git a/example-templates/src/shop/customer/orders.twig b/example-templates/src/shop/customer/orders.twig index c326cfe014..ee8c70fcf8 100755 --- a/example-templates/src/shop/customer/orders.twig +++ b/example-templates/src/shop/customer/orders.twig @@ -8,7 +8,7 @@ {% endset %} {% if not currentUser %} - {% redirect '/[[folderName]]/customer/sign-in' %} + {% redirect '[[folderName]]/customer/sign-in' %} {% endif %} From 156022ea949a22e6ef1d365b13ccfa1249b188ec Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 24 Oct 2023 12:05:42 +0100 Subject: [PATCH 16/29] Remove debug statement --- src/Plugin.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index e131621e89..bfc3554e7a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -271,17 +271,6 @@ public function init(): void } Craft::setAlias('@commerceLib', Craft::getAlias('@craft/commerce/../lib')); - - Event::on( - BaseFrontEndController::class, - BaseFrontEndController::EVENT_MODIFY_CART_INFO, - function(ModifyCartInfoEvent $e) { - $cartArray = $e->cartInfo; - $cartArray['anotherOne'] = 'Howdy'; - $e->cartInfo = $cartArray; - } - ); - } /** From 4eeb75c7d7eca0524fdcf5cede44e648420a9421 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 24 Oct 2023 12:06:18 +0100 Subject: [PATCH 17/29] Fix cs --- src/services/Emails.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/Emails.php b/src/services/Emails.php index a2b5ae8190..6e504215f4 100644 --- a/src/services/Emails.php +++ b/src/services/Emails.php @@ -692,11 +692,11 @@ public function sendEmail(Email $email, Order $order, ?OrderHistory $orderHistor file_put_contents($tempPath, $renderedPdf); $fileName = ''; - $defaultFileName = $pdf->handle . '-' . $order->number; - if($pdf->fileNameFormat) { + $defaultFileName = $pdf->handle . '-' . $order->number; + if ($pdf->fileNameFormat) { try { $fileName = $view->renderObjectTemplate($pdf->fileNameFormat, $order); - }catch (\Throwable $e){ + } catch (\Throwable $e) { $fileName = $defaultFileName; } } From 9fedaa9eaff5345df79407877a21b307290a3db1 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 24 Oct 2023 19:28:43 +0100 Subject: [PATCH 18/29] Fixed #3308 viewing trashed orders index --- CHANGELOG.md | 1 + src/elements/Order.php | 37 +++++++++++++++++++++++++++++++++---- src/services/Orders.php | 23 +++++++++++++++++++---- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eff69345fe..917b599d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug where it was possible to select soft-deleted tax categories. - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) +- Fixed a PHP error that occurred when viewing trashed orders. ([#3308](https://github.com/craftcms/commerce/issues/3308)) ## 4.3.1 - 2023-10-18 diff --git a/src/elements/Order.php b/src/elements/Order.php index ac719ba659..a54c1f8a4a 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -48,6 +48,7 @@ use craft\commerce\validators\StoreCountryValidator; use craft\db\Query; use craft\elements\Address as AddressElement; +use craft\elements\db\AddressQuery; use craft\elements\User; use craft\errors\ElementNotFoundException; use craft\errors\InvalidElementException; @@ -2887,8 +2888,22 @@ public function getAdjustmentsTotal(): float public function getShippingAddress(): ?AddressElement { if (!isset($this->_shippingAddress) && $this->shippingAddressId) { - /** @var AddressElement|null $address */ - $address = AddressElement::find()->ownerId($this->id)->id($this->shippingAddressId)->one(); + // Query addresses as array to avoid instantiating elements immediately + /** @var AddressQuery $query */ + $query = AddressElement::find() + ->ownerId($this->id) + ->id($this->shippingAddressId) + ->asArray(); + $data = $query->one(); + + if (!$data) { + throw new InvalidConfigException("Invalid shipping address ID: $this->shippingAddressId"); + } + + $data['owner'] = $this; + + /** @var AddressElement $address */ + $address = $query->createElement($data); $this->_shippingAddress = $address; } @@ -2981,8 +2996,22 @@ public function setEstimatedShippingAddress(AddressElement|array|null $address): public function getBillingAddress(): ?AddressElement { if (!isset($this->_billingAddress) && $this->billingAddressId) { - /** @var AddressElement|null $address */ - $address = AddressElement::find()->ownerId($this->id)->id($this->billingAddressId)->one(); + // Query addresses as array to avoid instantiating elements immediately + /** @var AddressQuery $query */ + $query = AddressElement::find() + ->ownerId($this->id) + ->id($this->billingAddressId) + ->asArray(); + $data = $query->one(); + + if (!$data) { + throw new InvalidConfigException("Invalid billing address ID: $this->billingAddressId"); + } + + $data['owner'] = $this; + + /** @var AddressElement $address */ + $address = $query->createElement($data); $this->_billingAddress = $address; } diff --git a/src/services/Orders.php b/src/services/Orders.php index 26a6dd418e..22815cefec 100644 --- a/src/services/Orders.php +++ b/src/services/Orders.php @@ -146,16 +146,31 @@ public function eagerLoadAddressesForOrders(array $orders): array $billingAddressIds = array_filter(ArrayHelper::getColumn($orders, 'billingAddressId')); $ids = array_unique(array_merge($shippingAddressIds, $billingAddressIds)); - /** @var Address[] $addresses */ - $addresses = Address::find()->id($ids)->indexBy('id')->all(); + // Query addresses as array to avoid instantiating elements immediately + $query = Address::find() + ->id($ids) + ->indexBy('id') + ->asArray(); + $addresses = $query->all(); foreach ($orders as $key => $order) { if (isset($order['shippingAddressId'], $addresses[$order['shippingAddressId']])) { - $order->setShippingAddress($addresses[$order['shippingAddressId']]); + $data = $addresses[$order['shippingAddressId']]; + $data['owner'] = $order; + /** @var Address $address */ + $address = $query->createElement($data); + + $order->setShippingAddress($address); } if (isset($order['billingAddressId'], $addresses[$order['billingAddressId']])) { - $order->setBillingAddress($addresses[$order['billingAddressId']]); + $data = $addresses[$order['billingAddressId']]; + $data['owner'] = $order; + + /** @var Address $address */ + $address = $query->createElement($data); + + $order->setBillingAddress($address); } $orders[$key] = $order; From 36a79ead0193e53423b3bde139567f2077c37494 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 25 Oct 2023 13:45:19 +0800 Subject: [PATCH 19/29] Release notes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eff69345fe..681d4a575d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a bug where it was possible to select soft-deleted tax categories. - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) +- Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307)) ## 4.3.1 - 2023-10-18 From 09b96da6bff1aeaa8f6664795bcb13cac6c051f5 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Wed, 25 Oct 2023 08:06:09 +0100 Subject: [PATCH 20/29] PHPStan fix --- src/services/Orders.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Orders.php b/src/services/Orders.php index 22815cefec..313d335339 100644 --- a/src/services/Orders.php +++ b/src/services/Orders.php @@ -151,6 +151,7 @@ public function eagerLoadAddressesForOrders(array $orders): array ->id($ids) ->indexBy('id') ->asArray(); + /** @var array $addresses */ $addresses = $query->all(); foreach ($orders as $key => $order) { From 6e79084b5ca6adc660f2a6d53d2a76947316b4ce Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 25 Oct 2023 18:20:43 +0800 Subject: [PATCH 21/29] Fixed validation of zones --- CHANGELOG.md | 1 + src/base/Zone.php | 12 ------------ src/models/ShippingAddressZone.php | 14 ++++++++++++++ src/models/TaxAddressZone.php | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 681d4a575d..cc68c9b597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed a bug where it was possible to select soft-deleted tax categories. - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) - Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307)) +- Fixed an incorrect validation error that occurred when saving a Shipping Zone. (#3317](https://github.com/craftcms/commerce/issues/3317)) ## 4.3.1 - 2023-10-18 diff --git a/src/base/Zone.php b/src/base/Zone.php index adfc723e14..21a9872fc0 100644 --- a/src/base/Zone.php +++ b/src/base/Zone.php @@ -89,16 +89,4 @@ public function setCondition(ZoneAddressCondition|string|array|null $condition): $this->_condition = $condition; } - - /** - * @inheritdoc - */ - protected function defineRules(): array - { - return [ - [['name'], 'required'], - [['condition'], 'required'], - [['name'], UniqueValidator::class, 'targetClass' => TaxZoneRecord::class, 'targetAttribute' => ['name']], - ]; - } } diff --git a/src/models/ShippingAddressZone.php b/src/models/ShippingAddressZone.php index 6068cf4fd1..423c9c502a 100644 --- a/src/models/ShippingAddressZone.php +++ b/src/models/ShippingAddressZone.php @@ -8,7 +8,9 @@ namespace craft\commerce\models; use craft\commerce\base\Zone; +use craft\commerce\records\ShippingZone as ShippingZoneRecord; use craft\helpers\UrlHelper; +use craft\validators\UniqueValidator; /** * Shipping zone model. @@ -27,4 +29,16 @@ public function getCpEditUrl(): string { return UrlHelper::cpUrl('commerce/shipping/shippingzones/' . $this->id); } + + /** + * @inheritdoc + */ + protected function defineRules(): array + { + return [ + [['name'], 'required'], + [['condition'], 'required'], + [['name'], UniqueValidator::class, 'targetClass' => ShippingZoneRecord::class, 'targetAttribute' => ['name']], + ]; + } } diff --git a/src/models/TaxAddressZone.php b/src/models/TaxAddressZone.php index 31655ff4e8..7e24bc353d 100644 --- a/src/models/TaxAddressZone.php +++ b/src/models/TaxAddressZone.php @@ -8,7 +8,9 @@ namespace craft\commerce\models; use craft\commerce\base\Zone; +use craft\commerce\records\TaxZone as TaxZoneRecord; use craft\helpers\UrlHelper; +use craft\validators\UniqueValidator; /** * Tax zone model. @@ -32,4 +34,16 @@ public function getCpEditUrl(): string { return UrlHelper::cpUrl('commerce/tax/taxzones/' . $this->id); } + + /** + * @inheritdoc + */ + protected function defineRules(): array + { + return [ + [['name'], 'required'], + [['condition'], 'required'], + [['name'], UniqueValidator::class, 'targetClass' => TaxZoneRecord::class, 'targetAttribute' => ['name']], + ]; + } } From 8d61d530cec16b04906f7a6d0f9f0120c1b2117f Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 25 Oct 2023 18:58:26 +0800 Subject: [PATCH 22/29] Cleanup --- src/base/Zone.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/base/Zone.php b/src/base/Zone.php index 21a9872fc0..501c87bb4e 100644 --- a/src/base/Zone.php +++ b/src/base/Zone.php @@ -6,10 +6,8 @@ use craft\base\conditions\ConditionInterface; use craft\base\Model as BaseModel; use craft\commerce\elements\conditions\addresses\ZoneAddressCondition; -use craft\commerce\records\TaxZone as TaxZoneRecord; use craft\elements\Address; use craft\helpers\Json; -use craft\validators\UniqueValidator; use DateTime; use yii\base\InvalidConfigException; From 9591d9d6f655164adcf4165811609581cc4d3773 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 25 Oct 2023 20:05:28 +0800 Subject: [PATCH 23/29] Fux changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc68c9b597..59bc358cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Fixed a bug where it was possible to select soft-deleted tax categories. - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) - Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307)) -- Fixed an incorrect validation error that occurred when saving a Shipping Zone. (#3317](https://github.com/craftcms/commerce/issues/3317)) +- Fixed an incorrect validation error that occurred when saving a Shipping Zone. ([#3317](https://github.com/craftcms/commerce/issues/3317)) ## 4.3.1 - 2023-10-18 From ddfaf22fc2d2adb4ccdd29ca0d41a3796ebf2868 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Fri, 27 Oct 2023 08:19:42 +0100 Subject: [PATCH 24/29] Revert address retrieval uses: craftcms/cms@6502b05e99fa588127edf55ec457ba516e896d4a --- src/elements/Order.php | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 2425c8c353..5405677e09 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2887,22 +2887,12 @@ public function getAdjustmentsTotal(): float public function getShippingAddress(): ?AddressElement { if (!isset($this->_shippingAddress) && $this->shippingAddressId) { - // Query addresses as array to avoid instantiating elements immediately - /** @var AddressQuery $query */ - $query = AddressElement::find() - ->ownerId($this->id) + /** @var AddressElement|null $address */ + $address = AddressElement::find() + ->owner($this) ->id($this->shippingAddressId) - ->asArray(); - $data = $query->one(); - - if (!$data) { - throw new InvalidConfigException("Invalid shipping address ID: $this->shippingAddressId"); - } - - $data['owner'] = $this; + ->one(); - /** @var AddressElement $address */ - $address = $query->createElement($data); $this->_shippingAddress = $address; } @@ -2995,22 +2985,12 @@ public function setEstimatedShippingAddress(AddressElement|array|null $address): public function getBillingAddress(): ?AddressElement { if (!isset($this->_billingAddress) && $this->billingAddressId) { - // Query addresses as array to avoid instantiating elements immediately - /** @var AddressQuery $query */ - $query = AddressElement::find() - ->ownerId($this->id) + /** @var AddressElement|null $address */ + $address = AddressElement::find() + ->owner($this) ->id($this->billingAddressId) - ->asArray(); - $data = $query->one(); - - if (!$data) { - throw new InvalidConfigException("Invalid billing address ID: $this->billingAddressId"); - } - - $data['owner'] = $this; + ->one(); - /** @var AddressElement $address */ - $address = $query->createElement($data); $this->_billingAddress = $address; } From 2d0a70ba634b1184eb7b0e0ca40e209e3485196c Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Mon, 30 Oct 2023 09:21:27 +0000 Subject: [PATCH 25/29] Fixed #3253 consistent decoding of line item snapshot --- CHANGELOG.md | 1 + src/services/LineItems.php | 5 +++++ tests/unit/services/LineItemsTest.php | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59bc358cba..1b26d83df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) - Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307)) - Fixed an incorrect validation error that occurred when saving a Shipping Zone. ([#3317](https://github.com/craftcms/commerce/issues/3317)) +- Fixed a bug where a line item’s snapshot wasn’t being decoded. ([#3253](https://github.com/craftcms/commerce/issues/3253)) ## 4.3.1 - 2023-10-18 diff --git a/src/services/LineItems.php b/src/services/LineItems.php index 3522690a52..e0f8c78262 100644 --- a/src/services/LineItems.php +++ b/src/services/LineItems.php @@ -312,6 +312,11 @@ public function getLineItemById(int $id): ?LineItem ->where(['id' => $id]) ->one(); + if ($result) { + // Unpack the snapshot + $result['snapshot'] = Json::decodeIfJson($result['snapshot']); + } + return $result ? new LineItem($result) : null; } diff --git a/tests/unit/services/LineItemsTest.php b/tests/unit/services/LineItemsTest.php index 89fcf78273..6e41849433 100644 --- a/tests/unit/services/LineItemsTest.php +++ b/tests/unit/services/LineItemsTest.php @@ -122,6 +122,18 @@ public function testGetLineItemById(): void self::assertEquals($lineItems[0]->qty, $lineItem->qty); } + public function testSnapshotUnpacking(): void + { + /** @var Order $order */ + $order = $this->fixtureData->getElement('completed-new'); + $lineItemById = $this->service->getLineItemById($order->getLineItems()[0]->id); + $lineItemFromAll = collect($this->service->getAllLineItemsByOrderId($order->id))->firstWhere('id', $lineItemById->id); + + self::assertIsArray($lineItemById->snapshot); + self::assertIsArray($lineItemFromAll->snapshot); + self::assertEquals($lineItemById->snapshot, $lineItemFromAll->snapshot); + } + public function testCreateLineItem(): void { /** @var Order $order */ From 4064390d113b329a232d3356c5350390178b56fb Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Mon, 30 Oct 2023 09:28:24 +0000 Subject: [PATCH 26/29] cs fix --- src/elements/Order.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 5405677e09..d8a544278b 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -48,7 +48,6 @@ use craft\commerce\validators\StoreCountryValidator; use craft\db\Query; use craft\elements\Address as AddressElement; -use craft\elements\db\AddressQuery; use craft\elements\User; use craft\errors\ElementNotFoundException; use craft\errors\InvalidElementException; From f20b5034f0ab933e2ae9300273a450d085b92377 Mon Sep 17 00:00:00 2001 From: Nathaniel Hammond Date: Tue, 31 Oct 2023 08:10:08 +0000 Subject: [PATCH 27/29] Add todo --- src/models/LineItem.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/LineItem.php b/src/models/LineItem.php index fd7581abad..ce88684423 100644 --- a/src/models/LineItem.php +++ b/src/models/LineItem.php @@ -108,6 +108,7 @@ class LineItem extends Model /** * @var mixed Snapshot + * @TODO add get and set methods in 5.0.0. Strict typing will be enforced. */ public mixed $snapshot = null; From 111d00ffc6da83fb54a037751472f843a7d9292e Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 31 Oct 2023 11:17:52 -0700 Subject: [PATCH 28/29] Changelog tweaks [ci skip] --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63ecc26da1..5cf80919d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ ## Unreleased +- Product GraphQL queries now support `promotable`, `freeShipping`, `defaultSku`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` arguments. ([#3307](https://github.com/craftcms/commerce/pull/3307)) +- Product GraphQL queries now support `promotable`, `freeShipping`, `defaultSku`, `defaultHeight`, `defaultLength`, `defaultWidth`, `defaultWeight`, and `defaultVariant` fields. ([#3307](https://github.com/craftcms/commerce/pull/3307)) - Fixed a bug where it was possible to select soft-deleted tax categories. - Fixed a PHP error that occurred when sending an email with a missing PDF filename format. ([#3309](https://github.com/craftcms/commerce/issues/3309)) -- Product GQL queries now support `promotable`, `availableForPurchase`, `freeShipping`, `defaultSku`, `defaultPrice`, `defaultVariant`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` params. ([#3307](https://github.com/craftcms/commerce/pull/3307)) -- Fixed a PHP error that occurred when viewing trashed orders. ([#3308](https://github.com/craftcms/commerce/issues/3308)) -- Fixed an incorrect validation error that occurred when saving a Shipping Zone. ([#3317](https://github.com/craftcms/commerce/issues/3317)) -- Fixed a bug where a line item’s snapshot wasn’t being decoded. ([#3253](https://github.com/craftcms/commerce/issues/3253)) +- Fixed a PHP error that occurred when viewing soft-deleted orders. ([#3308](https://github.com/craftcms/commerce/issues/3308)) +- Fixed a bug where saving a shipping zone could fail if a tax zone existed with the same name. ([#3317](https://github.com/craftcms/commerce/issues/3317)) +- Fixed a bug where `craft\commerce\services\LineItems::getLineItemById()` wasn’t decoding the snapshot data. ([#3253](https://github.com/craftcms/commerce/issues/3253)) ## 4.3.1 - 2023-10-18 From 6e6384fa7143ef872985179dbcc1f6646f98dac5 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 1 Nov 2023 14:19:01 +0800 Subject: [PATCH 29/29] Finished 4.3.2 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf80919d7..9a38aac9e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft Commerce -## Unreleased +## 4.3.2 - 2023-10-31 - Product GraphQL queries now support `promotable`, `freeShipping`, `defaultSku`, `defaultHeight`, `defaultLength`, `defaultWidth`, and `defaultWeight` arguments. ([#3307](https://github.com/craftcms/commerce/pull/3307)) - Product GraphQL queries now support `promotable`, `freeShipping`, `defaultSku`, `defaultHeight`, `defaultLength`, `defaultWidth`, `defaultWeight`, and `defaultVariant` fields. ([#3307](https://github.com/craftcms/commerce/pull/3307))