From ce06916b3a927f967a453560e60e660e98f357e1 Mon Sep 17 00:00:00 2001 From: jitendra Date: Mon, 7 Jan 2019 17:27:07 +0530 Subject: [PATCH] Cart issue fixed --- packages/Webkul/Checkout/src/Cart.php | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 48325c583..3f203fd0a 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -284,26 +284,17 @@ class Cart { 'weight' => $weight, 'total_weight' => $weight * $data['quantity'], 'base_total_weight' => $weight * $data['quantity'], - 'additional' => $additional + 'additional' => $additional, + 'type' => $product['type'], + 'product_id' => $product['id'], + 'additional' => $data, ]; - if($configurable){ - $parentData['type'] = $product['type']; - $parentData['product_id'] = $product['id']; - $parentData['additional'] = $data; - } else { - $parentData['type'] = $product['type']; - $parentData['product_id'] = $product['id']; - $parentData['additional'] = $data; - } - if($configurable) { - $additional = $this->getProductAttributeOptionDetails($parentProduct); + $attributeDetails = $this->getProductAttributeOptionDetails($parentProduct); + unset($attributeDetails['html']); - unset($additional['html']); - - $additional['request'] = $data; - $additional['variant_id'] = $data['selected_configurable_option']; + $parentData['additional'] = array_merge($parentData['additional'], $attributeDetails); $childData['product_id'] = (int)$data['selected_configurable_option']; $childData['sku'] = $parentProduct->sku; @@ -333,6 +324,12 @@ class Cart { { $item = $this->cartItem->findOneByField('id', $itemId); + if (isset($data['product'])) { + $additional = $data; + } else { + $additional = $item->additional; + } + if($item->type == 'configurable') { $product = $this->product->findOneByField('id', $item->child->product_id); @@ -341,6 +338,11 @@ class Cart { return false; } + + $attributeDetails = $this->getProductAttributeOptionDetails($product); + unset($attributeDetails['html']); + + $additional = array_merge($additional, $attributeDetails); } else { $product = $this->product->findOneByField('id', $item->product_id); @@ -358,7 +360,8 @@ class Cart { 'total' => core()->convertPrice($item->price * ($quantity)), 'base_total' => $item->price * ($quantity), 'total_weight' => $item->weight * ($quantity), - 'base_total_weight' => $item->weight * ($quantity) + 'base_total_weight' => $item->weight * ($quantity), + 'additional' => $additional ]); $this->collectTotals(); @@ -366,7 +369,7 @@ class Cart { if($result) { session()->flash('success', trans('shop::app.checkout.cart.quantity.success')); - return $result; + return $item; } else { session()->flash('warning', trans('shop::app.checkout.cart.quantity.error')); @@ -790,7 +793,8 @@ class Cart { $item->update(['name' => $item->product->name]); } else if($item->child->product->price != $item->price) { - $price = $item->custom_price ? $item->custom_price : $item->child->product->price; + $price = (float) $item->custom_price ? $item->custom_price : $item->child->product->price; + $item->update([ 'price' => $price, 'base_price' => $price, @@ -807,7 +811,8 @@ class Cart { $item->update(['name' => $item->product->name]); } else if($item->product->price != $item->price) { - $price = $item->custom_price ? $item->custom_price : $item->product->price; + $price = (float) $item->custom_price ? $item->custom_price : $item->product->price; + $item->update([ 'price' => $price, 'base_price' => $price,