From 4db41973fd882575368fbfa28c20d0d67eb796bf Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Thu, 27 Jun 2019 18:34:37 +0530 Subject: [PATCH] Removed the option of BuyAGetB as its current functionality was same as Fixed amount --- .../Discount/src/Config/rule-conditions.php | 2 +- .../Webkul/Discount/src/Helpers/Discount.php | 32 ++++++++++--------- .../src/Helpers/NonCouponAbleRule.php | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/Webkul/Discount/src/Config/rule-conditions.php b/packages/Webkul/Discount/src/Config/rule-conditions.php index 99d170b7a..5974af80a 100644 --- a/packages/Webkul/Discount/src/Config/rule-conditions.php +++ b/packages/Webkul/Discount/src/Config/rule-conditions.php @@ -34,7 +34,7 @@ return [ 'actions' => [ 'percent_of_product' => 'Percentage of product', 'fixed_amount' => 'Apply as fixed amount', - 'buy_a_get_b' => 'Buy A get B' + // 'buy_a_get_b' => 'Buy A get B' ], 'validation' => [ diff --git a/packages/Webkul/Discount/src/Helpers/Discount.php b/packages/Webkul/Discount/src/Helpers/Discount.php index 7602313dc..f2846951a 100644 --- a/packages/Webkul/Discount/src/Helpers/Discount.php +++ b/packages/Webkul/Discount/src/Helpers/Discount.php @@ -597,23 +597,25 @@ abstract class Discount */ public function applyOnShipping($appliedRule, $cart) { - if ($appliedRule->free_shipping && $cart->selected_shipping_rate->base_price > 0) { - $cart->selected_shipping_rate->update([ - 'price' => 0, - 'base_price' => 0 - ]); - } else if ($appliedRule->free_shipping == 0 && $appliedRule->apply_to_shipping && $cart->selected_shipping_rate->base_price > 0) { - $actionType = config('discount-rules')[$appliedRule->action_type]; - - if ($appliedRule->apply_to_shipping) { - $actionInstance = new $actionType; - - $discountOnShipping = $actionInstance->calculateOnShipping($cart); - + if (isset($cart->selected_shipping_rate->base_price)) { + if ($appliedRule->free_shipping && $cart->selected_shipping_rate->base_price > 0) { $cart->selected_shipping_rate->update([ - 'price' => $cart->selected_shipping_rate->base_price - $discountOnShipping, - 'base_price' => $cart->selected_shipping_rate->price - core()->convertPrice($discountOnShipping, $cart->cart_currency_code) + 'price' => 0, + 'base_price' => 0 ]); + } else if ($appliedRule->free_shipping == 0 && $appliedRule->apply_to_shipping && $cart->selected_shipping_rate->base_price > 0) { + $actionType = config('discount-rules')[$appliedRule->action_type]; + + if ($appliedRule->apply_to_shipping) { + $actionInstance = new $actionType; + + $discountOnShipping = $actionInstance->calculateOnShipping($cart); + + $cart->selected_shipping_rate->update([ + 'price' => $cart->selected_shipping_rate->base_price - $discountOnShipping, + 'base_price' => $cart->selected_shipping_rate->price - core()->convertPrice($discountOnShipping, $cart->cart_currency_code) + ]); + } } } } diff --git a/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php b/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php index 11c54d095..4fd0b591b 100644 --- a/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php +++ b/packages/Webkul/Discount/src/Helpers/NonCouponAbleRule.php @@ -117,7 +117,7 @@ class NonCouponAbleRule extends Discount if (count($endRules) == 1) { $this->save(array_first($endRules)['rule']); - return $endRules; + return array_first($endRules)['impact']; } $maxImpact = 0;