Skip to content

Commit

Permalink
Fixed Drafts showing up in inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Dec 4, 2024
1 parent 8ed09c9 commit 308c1e1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]]);
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/InventoryLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ private function _createInventoryLocationsQuery(bool $withTrashed = false): Quer
'dateCreated',
'dateUpdated',
])
->orderBy(['name' => SORT_ASC])
->from([Table::INVENTORYLOCATIONS]);

if (!$withTrashed) {
Expand Down

0 comments on commit 308c1e1

Please sign in to comment.