Skip to content

Commit

Permalink
Fix issues when cart is empty or not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Jan 6, 2021
1 parent 5569e6b commit 34657f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.3 - 2021-01-06
### Fixed
- Fix issues when cart is empty or not saved

## 1.0.2 - 2019-08-02
### Fixed
- Fix CP edit url not linking to the admin
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ether/cart-notices",
"description": "Automatically show notices based off cart details",
"version": "1.0.2",
"version": "1.0.3",
"type": "craft-plugin",
"license": "proprietary",
"minimum-stability": "dev",
Expand Down
10 changes: 9 additions & 1 deletion src/elements/db/NoticeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,19 @@ protected function beforePrepare (): bool
$this->_lineItemProductIds($cart->lineItems)
);

if (empty($productIds))
$productIds = -1;

$cartId = $cart->id ?? -1;

$sql = <<<SQL
[[cart-notices.type]] = :type4 AND
[[cart-notices.id]] IN (
SELECT [[np.noticeId]]
FROM {{%cart-notices_notice_product}} [[np]]
INNER JOIN {{%cart-notices}} [[cn]] ON [[cn.id]] = [[np.noticeId]]
INNER JOIN {{%commerce_variants}} [[cv]] ON [[np.productId]] = [[cv.productId]]
INNER JOIN {{%commerce_lineitems}} [[li]] ON [[li.purchasableId]] = [[cv.id]] AND [[li.orderId]] = '$cart->id'
INNER JOIN {{%commerce_lineitems}} [[li]] ON [[li.purchasableId]] = [[cv.id]] AND [[li.orderId]] = '$cartId'
WHERE [[np.productId]] IN ('$productIds')
AND ([[li.qty]] BETWEEN COALESCE([[cn.minQty]], 0) AND COALESCE([[cn.maxQty]], 99999999))
)
Expand All @@ -225,6 +230,9 @@ protected function beforePrepare (): bool
$this->_lineItemPurchasableIds($cart->lineItems)
);

if (empty($purchasableIds))
$purchasableIds = -2;

$sql = <<<SQL
[[cart-notices.type]] = :type5 AND
[[cart-notices.id]] IN (
Expand Down

0 comments on commit 34657f0

Please # to comment.