Skip to content

Commit

Permalink
Fixed #1206
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jan 24, 2020
1 parent f9c6c4d commit a3aa828
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/adjusters/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions src/adjusters/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/models/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/services/Discounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
])
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a3aa828

Please sign in to comment.