Shipping now getting applied according to selected shipping method
This commit is contained in:
parent
4db41973fd
commit
25007824eb
|
|
@ -68,7 +68,7 @@
|
|||
<div class="control-group" :class="[errors.has('ends_till') ? 'has-error' : '']">
|
||||
<label for="ends_till">{{ __('admin::app.promotion.general-info.ends-till') }}</label>
|
||||
|
||||
<input type="text" class="control" v-model="ends_till" v-validate="'after:starts_from'" name="ends_till" data-vv-as=""{{ __('admin::app.promotion.general-info.ends-till') }}"">
|
||||
<input type="text" class="control" v-model="ends_till" name="ends_till" data-vv-as=""{{ __('admin::app.promotion.general-info.ends-till') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('ends_till')">@{{ errors.first('ends_till') }}</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1116,7 +1116,8 @@ class Cart {
|
|||
*
|
||||
* Move a wishlist item to cart
|
||||
*/
|
||||
public function moveToCart($wishlistItem) {
|
||||
public function moveToCart($wishlistItem)
|
||||
{
|
||||
$product = $wishlistItem->product;
|
||||
|
||||
if ($product->type == 'simple') {
|
||||
|
|
@ -1140,7 +1141,8 @@ class Cart {
|
|||
*
|
||||
* @param instance cartItem $id
|
||||
*/
|
||||
public function moveToWishlist($itemId) {
|
||||
public function moveToWishlist($itemId)
|
||||
{
|
||||
$cart = $this->getCart();
|
||||
$items = $cart->items;
|
||||
$wishlist = [];
|
||||
|
|
@ -1187,7 +1189,8 @@ class Cart {
|
|||
*
|
||||
* @return response mixed
|
||||
*/
|
||||
public function proceedToBuyNow($id, $quantity) {
|
||||
public function proceedToBuyNow($id, $quantity)
|
||||
{
|
||||
$product = $this->product->findOneByField('id', $id);
|
||||
|
||||
if ($product->type == 'configurable') {
|
||||
|
|
|
|||
|
|
@ -145,14 +145,13 @@ abstract class Discount
|
|||
|
||||
$this->clearDiscount();
|
||||
|
||||
$this->applyOnShipping($rule, $cart);
|
||||
$this->checkOnShipping();
|
||||
|
||||
$this->updateCartItemAndCart($rule);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $rule->id
|
||||
|
|
@ -160,7 +159,7 @@ abstract class Discount
|
|||
|
||||
$this->clearDiscount();
|
||||
|
||||
$this->applyOnShipping($rule, $cart);
|
||||
$this->checkOnShipping();
|
||||
|
||||
$this->updateCartItemAndCart($rule);
|
||||
|
||||
|
|
@ -170,6 +169,55 @@ abstract class Discount
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether rule is getting applied on shipping or not
|
||||
*/
|
||||
public function checkOnShipping()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if (! isset($cart->selected_shipping_rate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$shippingRate = config('carriers')[$cart->selected_shipping_rate->carrier]['class'];
|
||||
|
||||
$actualShippingRate = new $shippingRate;
|
||||
$actualShippingRate = $actualShippingRate->calculate();
|
||||
$actualShippingPrice = $actualShippingRate->price;
|
||||
$actualShippingBasePrice = $actualShippingRate->base_price;
|
||||
|
||||
$alreadyAppliedCartRuleCart = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
|
||||
if (count($alreadyAppliedCartRuleCart)) {
|
||||
$alreadyAppliedRule = $alreadyAppliedCartRuleCart->first()->cart_rule;
|
||||
|
||||
$cartShippingRate = $cart->selected_shipping_rate;
|
||||
|
||||
if (isset($cartShippingRate)) {
|
||||
if ($cartShippingRate->price < $actualShippingPrice) {
|
||||
return false;
|
||||
} else {
|
||||
$cartShippingRate->update([
|
||||
'price' => $actualShippingPrice,
|
||||
'base_price' => $actualShippingBasePrice
|
||||
]);
|
||||
|
||||
$this->applyOnShipping($alreadyAppliedRule, $cart);
|
||||
}
|
||||
} else {
|
||||
$this->applyOnShipping($alreadyAppliedRule, $cart);
|
||||
}
|
||||
} else {
|
||||
$cartShippingRate->update([
|
||||
'price' => $actualShippingPrice,
|
||||
'base_price' => $actualShippingBasePrice
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any cart rule from the current cart instance
|
||||
*
|
||||
|
|
@ -597,7 +645,7 @@ abstract class Discount
|
|||
*/
|
||||
public function applyOnShipping($appliedRule, $cart)
|
||||
{
|
||||
if (isset($cart->selected_shipping_rate->base_price)) {
|
||||
if (isset($cart->selected_shipping_rate)) {
|
||||
if ($appliedRule->free_shipping && $cart->selected_shipping_rate->base_price > 0) {
|
||||
$cart->selected_shipping_rate->update([
|
||||
'price' => 0,
|
||||
|
|
|
|||
|
|
@ -147,6 +147,8 @@ class OnepageController extends Controller
|
|||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
$this->nonCoupon->checkOnShipping();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json(Payment::getSupportedPaymentMethods());
|
||||
|
|
@ -166,6 +168,8 @@ class OnepageController extends Controller
|
|||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
$this->nonCoupon->checkOnShipping();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
|
@ -285,19 +289,6 @@ class OnepageController extends Controller
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies non couponable rule if present
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
public function applyNonCouponAbleRule()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
$nonCouponAbleRules = Cart::applyNonCoupon();
|
||||
|
||||
return $nonCouponAbleRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the removal of couponable cart rule
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue