From f7d4dcf9812cb7044e112b8fe813c6c8a04807b7 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink <378974+boboldehampsink@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:53:55 +0100 Subject: [PATCH 1/7] Use subquery in hasVariant criteria to improve performance --- src/elements/db/ProductQuery.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/elements/db/ProductQuery.php b/src/elements/db/ProductQuery.php index 9bd6d6e935..4332978d03 100644 --- a/src/elements/db/ProductQuery.php +++ b/src/elements/db/ProductQuery.php @@ -1126,12 +1126,11 @@ private function _applyHasVariantParam(): void $variantQuery->limit = null; $variantQuery->select('commerce_variants.productId'); - $productIds = $variantQuery->asArray()->column(); // Remove any blank product IDs (if any) - $productIds = array_filter($productIds); + $variantQuery->andWhere(['not', ['commerce_variants.productId' => null]]); - $this->subQuery->andWhere(['commerce_products.id' => array_values($productIds)]); + $this->subQuery->andWhere(['commerce_products.id' => $variantQuery]); } /** From a18d57ba67610d3791d5e3b4b0c5482e0e6131e4 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink <378974+boboldehampsink@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:04:20 +0100 Subject: [PATCH 2/7] Also apply for VariantQuery::hasProduct --- src/elements/db/VariantQuery.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/elements/db/VariantQuery.php b/src/elements/db/VariantQuery.php index 1c4a136b4a..d5cadac2cd 100644 --- a/src/elements/db/VariantQuery.php +++ b/src/elements/db/VariantQuery.php @@ -927,11 +927,11 @@ private function _applyHasProductParam(): void $productQuery->limit = null; $productQuery->select('commerce_products.id'); - $productIds = $productQuery->column(); // Remove any blank product IDs (if any) - $productIds = array_filter($productIds); - $this->subQuery->andWhere(['commerce_variants.productId' => $productIds]); + $productQuery->andWhere(['not', ['commerce_products.id' => null]]); + + $this->subQuery->andWhere(['commerce_variants.productId' => $productQuery]); } /** From 0b61ec51a5000eac648afc492f87a9a7e8a312e5 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 8 Nov 2023 12:16:59 +0000 Subject: [PATCH 3/7] removed space between the status circle and wording --- src/elements/Order.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index d8a544278b..131b26a56c 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2457,7 +2457,7 @@ public function getCustomerLinkHtml(): string public function getOrderStatusHtml(): string { if ($status = $this->getOrderStatus()) { - return ' ' . $status->name . ''; + return '' . $status->name . ''; } return ''; @@ -2469,10 +2469,10 @@ public function getOrderStatusHtml(): string public function getPaidStatusHtml(): string { return match ($this->getPaidStatus()) { - self::PAID_STATUS_OVERPAID => ' ' . Craft::t('commerce', 'Overpaid') . '', - self::PAID_STATUS_PAID => ' ' . Craft::t('commerce', 'Paid') . '', - self::PAID_STATUS_PARTIAL => ' ' . Craft::t('commerce', 'Partial') . '', - self::PAID_STATUS_UNPAID => ' ' . Craft::t('commerce', 'Unpaid') . '', + self::PAID_STATUS_OVERPAID => '' . Craft::t('commerce', 'Overpaid') . '', + self::PAID_STATUS_PAID => '' . Craft::t('commerce', 'Paid') . '', + self::PAID_STATUS_PARTIAL => '' . Craft::t('commerce', 'Partial') . '', + self::PAID_STATUS_UNPAID => '' . Craft::t('commerce', 'Unpaid') . '', default => '', }; } From e5b51eadcddf85685d7fd2e244ec0be7169d4c84 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Fri, 10 Nov 2023 13:29:51 +0800 Subject: [PATCH 4/7] Release notes update --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a38aac9e6..a72e673019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft Commerce +## Unreleased + +- Improved the performance of the `craft\commerce\elements\db\VariantQuery::hasProduct()` and `craft\commerce\elements\db\ProductQuery::hasVariant()` query params. ([#3325](https://github.com/craftcms/commerce/pull/3325)) + ## 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)) From 4e620f9cf8c923a7411623dc0e021195acfb8637 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Mon, 13 Nov 2023 12:23:02 +0800 Subject: [PATCH 5/7] Fixed wrapping issue for statuses As per https://github.com/craftcms/cms/issues/13910#issuecomment-1806820880 --- src/elements/Order.php | 10 +++++----- src/models/LineItemStatus.php | 2 +- src/models/OrderStatus.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/elements/Order.php b/src/elements/Order.php index 131b26a56c..fccdc16776 100644 --- a/src/elements/Order.php +++ b/src/elements/Order.php @@ -2457,7 +2457,7 @@ public function getCustomerLinkHtml(): string public function getOrderStatusHtml(): string { if ($status = $this->getOrderStatus()) { - return '' . $status->name . ''; + return '' . $status->name . ''; } return ''; @@ -2469,10 +2469,10 @@ public function getOrderStatusHtml(): string public function getPaidStatusHtml(): string { return match ($this->getPaidStatus()) { - self::PAID_STATUS_OVERPAID => '' . Craft::t('commerce', 'Overpaid') . '', - self::PAID_STATUS_PAID => '' . Craft::t('commerce', 'Paid') . '', - self::PAID_STATUS_PARTIAL => '' . Craft::t('commerce', 'Partial') . '', - self::PAID_STATUS_UNPAID => '' . Craft::t('commerce', 'Unpaid') . '', + self::PAID_STATUS_OVERPAID => '' . Craft::t('commerce', 'Overpaid') . '', + self::PAID_STATUS_PAID => '' . Craft::t('commerce', 'Paid') . '', + self::PAID_STATUS_PARTIAL => '' . Craft::t('commerce', 'Partial') . '', + self::PAID_STATUS_UNPAID => '' . Craft::t('commerce', 'Unpaid') . '', default => '', }; } diff --git a/src/models/LineItemStatus.php b/src/models/LineItemStatus.php index feb67a19dd..fec0af341b 100644 --- a/src/models/LineItemStatus.php +++ b/src/models/LineItemStatus.php @@ -102,7 +102,7 @@ public function getCpEditUrl(): string public function getLabelHtml(): string { - return sprintf('%s', $this->color, Html::encode($this->name)); + return sprintf('%s', $this->color, Html::encode($this->name)); } /** diff --git a/src/models/OrderStatus.php b/src/models/OrderStatus.php index 1705c8e9d1..9b228a611e 100644 --- a/src/models/OrderStatus.php +++ b/src/models/OrderStatus.php @@ -158,7 +158,7 @@ public function getEmails(): array public function getLabelHtml(): string { - return sprintf('%s', $this->color, Html::encode($this->getDisplayName())); + return sprintf('%s', $this->color, Html::encode($this->getDisplayName())); } /** From a28de03162af840cecfe7d9ce316b11f9daed7e9 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Mon, 13 Nov 2023 12:31:59 +0800 Subject: [PATCH 6/7] Update release notes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a72e673019..cb738f6d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Improved the performance of the `craft\commerce\elements\db\VariantQuery::hasProduct()` and `craft\commerce\elements\db\ProductQuery::hasVariant()` query params. ([#3325](https://github.com/craftcms/commerce/pull/3325)) +- Order statuses with long names no longer line wrap on the Orders index page. ([#3335](https://github.com/craftcms/commerce/issues/3335)) ## 4.3.2 - 2023-10-31 From 997cc85b8a2d999b0776056a9c5ce0e9fea1115c Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Mon, 13 Nov 2023 12:34:18 +0800 Subject: [PATCH 7/7] Min quantity of zero rule already lives in the line item rules, not needed on the variant. Fixes #3334 --- CHANGELOG.md | 1 + src/elements/Variant.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb738f6d07..00885faee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Improved the performance of the `craft\commerce\elements\db\VariantQuery::hasProduct()` and `craft\commerce\elements\db\ProductQuery::hasVariant()` query params. ([#3325](https://github.com/craftcms/commerce/pull/3325)) - Order statuses with long names no longer line wrap on the Orders index page. ([#3335](https://github.com/craftcms/commerce/issues/3335)) +- Fixed duplicate validate errors that occurred when submitting a zero quantity to the cart. ([3334](https://github.com/craftcms/commerce/issues/3334)) ## 4.3.2 - 2023-10-31 diff --git a/src/elements/Variant.php b/src/elements/Variant.php index 4f45813467..5ee3eb9599 100644 --- a/src/elements/Variant.php +++ b/src/elements/Variant.php @@ -823,7 +823,6 @@ function($attribute, $params, Validator $validator) use ($lineItem, $getQty) { } }, ], - [['qty'], 'integer', 'min' => 1, 'skipOnError' => false], ]; }