diff --git a/src/adjusters/Discount.php b/src/adjusters/Discount.php index e4f26a08cc..a7c8600f9a 100644 --- a/src/adjusters/Discount.php +++ b/src/adjusters/Discount.php @@ -141,7 +141,7 @@ private function _getAdjustments(DiscountModel $discount) $matchingLineIds = []; foreach ($this->_order->getLineItems() as $item) { $lineItemHashId = spl_object_hash($item); - if (Plugin::getInstance()->getDiscounts()->matchLineItem($item, $this->_discount)) { + if (Plugin::getInstance()->getDiscounts()->matchLineItem($item, $this->_discount, false)) { if (!$this->_discount->allGroups) { $customer = $this->_order->getCustomer(); $user = $customer ? $customer->getUser() : null; diff --git a/src/adjusters/Shipping.php b/src/adjusters/Shipping.php index 26acf96f96..ca9023d4f0 100644 --- a/src/adjusters/Shipping.php +++ b/src/adjusters/Shipping.php @@ -68,15 +68,13 @@ public function adjust(Order $order): array foreach ($lineItems as $item) { $purchasable = $item->getPurchasable(); - if($purchasable && !$purchasable->getIsShippable()) - { + if ($purchasable && !$purchasable->getIsShippable()) { $nonShippableItems[$item->id] = $item->id; } } // Are all line items non shippable items? No shipping cost. - if(count($lineItems) == count($nonShippableItems)) - { + if (count($lineItems) == count($nonShippableItems)) { return []; } @@ -104,13 +102,13 @@ public function adjust(Order $order): array // Lets match the discount now for free shipped items and not even make a shipping cost for the line item. $hasFreeShippingFromDiscount = false; foreach ($discounts as $discount) { - if ($discount->hasFreeShippingForMatchingItems && Plugin::getInstance()->getDiscounts()->matchLineItem($item, $discount)) { + if ($discount->hasFreeShippingForMatchingItems && Plugin::getInstance()->getDiscounts()->matchLineItem($item, $discount, true)) { $hasFreeShippingFromDiscount = true; } } $freeShippingFlagOnProduct = $item->purchasable->hasFreeShipping(); - $shippable = $item->purchasable->getIsShippable(); + $shippable = $item->purchasable->getIsShippable(); if (!$freeShippingFlagOnProduct && !$hasFreeShippingFromDiscount && $shippable) { $adjustment = $this->_createAdjustment($shippingMethod, $rule); diff --git a/src/models/LineItem.php b/src/models/LineItem.php index c811665ff4..547ff27447 100644 --- a/src/models/LineItem.php +++ b/src/models/LineItem.php @@ -409,7 +409,7 @@ public function populateFromPurchasable(PurchasableInterface $purchasable) // Check to see if there is a discount applied that ignores Sales $ignoreSales = false; foreach ($discounts as $discount) { - if ($discount->enabled && Plugin::getInstance()->getDiscounts()->matchLineItem($this, $discount)) { + if ($discount->enabled && Plugin::getInstance()->getDiscounts()->matchLineItem($this, $discount, true)) { $ignoreSales = $discount->ignoreSales; if ($discount->ignoreSales) { $ignoreSales = $discount->ignoreSales; diff --git a/src/services/Discounts.php b/src/services/Discounts.php index b4d74571eb..d1e6df0f80 100644 --- a/src/services/Discounts.php +++ b/src/services/Discounts.php @@ -198,11 +198,13 @@ public function getAllActiveDiscounts($order = null): array 'enabled' => 1, ]) // Restrict by things that a definitely not in date - ->andWhere(['or', + ->andWhere([ + 'or', ['dateFrom' => null], ['<=', 'dateFrom', Db::prepareDateForDb($date)] ]) - ->andWhere(['or', + ->andWhere([ + 'or', ['dateTo' => null], ['>=', 'dateTo', Db::prepareDateForDb($date)] ]) @@ -486,6 +488,7 @@ public function matchOrder(Order $order, Discount $discount): bool if (($discount->getPurchasableIds() && !$discount->allPurchasables) || ($discount->getCategoryIds() && !$discount->allCategories)) { $lineItemMatch = false; foreach ($order->getLineItems() as $lineItem) { + // Must mot match order as we would get an infinate recursion if ($this->matchLineItem($lineItem, $discount, false)) { $lineItemMatch = true; break;