diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index f1ac70b86..c640a30d0 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -423,7 +423,6 @@ class Cart { 'customer_id' => $this->getCurrentCustomer()->user()->id, 'is_active' => 1 ]); - } elseif (session()->has('cart')) { $cart = $this->cartRepository->find(session()->get('cart')->id); } @@ -671,6 +670,8 @@ class Cart { return false; } else { foreach ($cart->items as $item) { + $item->product->getTypeInstance()->validateCartItem($item); + $price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price; $this->cartItemRepository->update([ diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index aec1c610a..54a6a3500 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -573,4 +573,26 @@ abstract class AbstractType { return $this->productImageHelper->getProductBaseImage($item->product); } + + /** + * Validate cart item product price + * + * @param CartItem $item + * @return void + */ + public function validateCartItem($item) + { + $price = $item->product->getTypeInstance()->getFinalPrice(); + + if ($price == $item->base_price) + return; + + $item->base_price = $price; + $item->price = core()->convertPrice($price); + + $item->base_total = $price * $item->quantity; + $item->total = core()->convertPrice($price * $item->quantity); + + $item->save(); + } } \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Bundle.php b/packages/Webkul/Product/src/Type/Bundle.php index e8d1ae6a2..e0688069e 100644 --- a/packages/Webkul/Product/src/Type/Bundle.php +++ b/packages/Webkul/Product/src/Type/Bundle.php @@ -441,4 +441,34 @@ class Bundle extends AbstractType return $data; } + + /** + * Validate cart item product price + * + * @param CartItem $item + * @return void + */ + public function validateCartItem($item) + { + $price = 0; + + foreach ($item->children as $childItem) { + $childItem->product->getTypeInstance()->validateCartItem($childItem); + + $price += $childItem->base_price * $childItem->quantity; + } + + if ($price == $item->base_price) + return; + + $item->base_price = $price; + $item->price = core()->convertPrice($price); + + $item->base_total = $price * $item->quantity; + $item->total = core()->convertPrice($price * $item->quantity); + + $item->additional = $this->getAdditionalOptions($item->additional); + + $item->save(); + } } \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Configurable.php b/packages/Webkul/Product/src/Type/Configurable.php index 58224b4e7..79cb4c081 100644 --- a/packages/Webkul/Product/src/Type/Configurable.php +++ b/packages/Webkul/Product/src/Type/Configurable.php @@ -485,4 +485,26 @@ class Configurable extends AbstractType return $this->productImageHelper->getProductBaseImage($product); } + + /** + * Validate cart item product price + * + * @param CartItem $item + * @return float + */ + public function validateCartItem($item) + { + $price = $item->child->product->getTypeInstance()->getFinalPrice(); + + if ($price == $item->base_price) + return; + + $item->base_price = $total; + $item->price = core()->convertPrice($price); + + $item->base_total = $price * $item->quantity; + $item->total = core()->convertPrice($price * $item->quantity); + + $item->save(); + } } \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Downloadable.php b/packages/Webkul/Product/src/Type/Downloadable.php index 326b53020..aaf97acdf 100644 --- a/packages/Webkul/Product/src/Type/Downloadable.php +++ b/packages/Webkul/Product/src/Type/Downloadable.php @@ -215,4 +215,33 @@ class Downloadable extends AbstractType return $data; } + + /** + * Validate cart item product price + * + * @param CartItem $item + * @return float + */ + public function validateCartItem($item) + { + $price = $item->product->getTypeInstance()->getFinalPrice(); + + foreach ($item->product->downloadable_links as $link) { + if (! in_array($link->id, $item->additional['links'])) + continue; + + $price += $link->price; + } + + if ($price == $item->base_price) + return; + + $item->base_price = $price; + $item->price = core()->convertPrice($price); + + $item->base_total = $price * $item->quantity; + $item->total = core()->convertPrice($price * $item->quantity); + + $item->save(); + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 6cc2958c2..a080d0fd3 100755 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -65,6 +65,8 @@ class CartController extends Controller */ public function index() { + Cart::collectTotals(); + return view($this->_config['view'])->with('cart', Cart::getCart()); } diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/cart/mini-cart.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/cart/mini-cart.blade.php index fa5847dfa..da7cc9f81 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/cart/mini-cart.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/cart/mini-cart.blade.php @@ -3,10 +3,6 @@ getCart(); ?> @if ($cart) - @php - Cart::collectTotals(); - @endphp - items; ?>