From 308c1e126a8a5c9fc9018fc7e8264ccf40006c6e Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 4 Dec 2024 18:51:03 +0800 Subject: [PATCH] Fixed Drafts showing up in inventory --- CHANGELOG.md | 1 + src/controllers/InventoryController.php | 2 ++ src/services/Inventory.php | 6 +++++- src/services/InventoryLocations.php | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d67c23cc..e35f416765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fixed a bug where draft purchasables would show up on the Inventory page. - Fixed a bug where the price was not formatted correctly according to the locale in the payment model on the Order Edit screens. ([#3789](https://github.com/craftcms/commerce/issues/3789)) ## 5.2.7 - 2024-11 diff --git a/src/controllers/InventoryController.php b/src/controllers/InventoryController.php index 13e2653aea..7d083825f7 100644 --- a/src/controllers/InventoryController.php +++ b/src/controllers/InventoryController.php @@ -242,6 +242,8 @@ public function actionInventoryLevelsTableData(): Response $inventoryQuery->leftJoin(['purchasables' => Table::PURCHASABLES], '[[ii.purchasableId]] = [[purchasables.id]]'); $inventoryQuery->addGroupBy(['[[purchasables.description]]', '[[purchasables.sku]]']); + $inventoryQuery->andWhere(['not', ['elements.id' => null]]); + if ($search) { $inventoryQuery->andWhere(['or', ['like', 'purchasables.description', $search], ['like', 'purchasables.sku', $search]]); } diff --git a/src/services/Inventory.php b/src/services/Inventory.php index 93107c4fba..01ecd7a4be 100644 --- a/src/services/Inventory.php +++ b/src/services/Inventory.php @@ -262,8 +262,12 @@ public function getInventoryLevelQuery(?int $limit = null, ?int $offset = null, ->limit($limit) ->offset($offset); + $query->leftJoin( + ['elements' => CraftTable::ELEMENTS], + '[[ii.purchasableId]] = [[elements.id]] AND [[elements.draftId]] IS NULL AND [[elements.revisionId]] IS NULL' + ); + if (!$withTrashed) { - $query->leftJoin(['elements' => CraftTable::ELEMENTS], '[[ii.purchasableId]] = [[elements.id]]'); $query->andWhere(['elements.dateDeleted' => null]); } diff --git a/src/services/InventoryLocations.php b/src/services/InventoryLocations.php index c92e806797..31ead4e14f 100644 --- a/src/services/InventoryLocations.php +++ b/src/services/InventoryLocations.php @@ -283,6 +283,7 @@ private function _createInventoryLocationsQuery(bool $withTrashed = false): Quer 'dateCreated', 'dateUpdated', ]) + ->orderBy(['name' => SORT_ASC]) ->from([Table::INVENTORYLOCATIONS]); if (!$withTrashed) {