From 683b18e42470ff5b531a31a47caad4a56fc3d1d0 Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Thu, 25 Oct 2018 13:49:23 +0530 Subject: [PATCH 1/3] Cart Bug Fixes and Category items fixes for visible in menu only --- .../Admin/src/DataGrids/CategoryDataGrid.php | 17 +- .../src/Providers/EventServiceProvider.php | 2 +- .../src/Repositories/CategoryRepository.php | 13 + packages/Webkul/Checkout/src/Cart.php | 102 +- .../Controllers/RegistrationController.php | 4 +- .../Http/ViewComposers/CategoryComposer.php | 2 +- .../assets/js/components/category-item.vue | 2 +- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 17 +- .../Webkul/Ui/src/DataGrid/ProductGrid.php | 968 ------------------ public/themes/default/assets/js/shop.js | 6 +- .../themes/default/assets/mix-manifest.json | 2 +- 11 files changed, 129 insertions(+), 1006 deletions(-) delete mode 100644 packages/Webkul/Ui/src/DataGrid/ProductGrid.php diff --git a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php index 08012cfb2..b27c5a1c8 100644 --- a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php @@ -76,31 +76,35 @@ class CategoryDataGrid 'columns' => [ [ 'name' => 'cat.id', - 'alias' => 'catID', + 'alias' => 'cat_id', 'type' => 'number', 'label' => 'Category ID', 'sortable' => true, + 'filter' => [ + 'function' => 'where', + 'condition' => ['cta.locale', app()->getLocale()] + ], ], [ 'name' => 'ct.name', - 'alias' => 'catName', + 'alias' => 'cat_name', 'type' => 'string', 'label' => 'Category Name', 'sortable' => false, ], [ 'name' => 'cat.position', - 'alias' => 'catPosition', + 'alias' => 'cat_position', 'type' => 'string', 'label' => 'Category Position', 'sortable' => false, ], [ 'name' => 'cta.name', - 'alias' => 'parentName', + 'alias' => 'parent_name', 'type' => 'string', 'label' => 'Parent Name', 'sortable' => true, ], [ 'name' => 'cat.status', - 'alias' => 'catStatus', + 'alias' => 'cat_status', 'type' => 'string', 'label' => 'Visible in Menu', 'sortable' => true, @@ -110,8 +114,7 @@ class CategoryDataGrid else return "True"; }, - ], - + ] ], 'filterable' => [ diff --git a/packages/Webkul/Admin/src/Providers/EventServiceProvider.php b/packages/Webkul/Admin/src/Providers/EventServiceProvider.php index a9608eded..b3ce36c5f 100644 --- a/packages/Webkul/Admin/src/Providers/EventServiceProvider.php +++ b/packages/Webkul/Admin/src/Providers/EventServiceProvider.php @@ -165,7 +165,7 @@ class EventServiceProvider extends ServiceProvider 'icon-class' => '', ], [ 'key' => 'settings.sliders', - 'name' => 'Create Sliders', + 'name' => 'Sliders', 'route' => 'admin.sliders.index', 'sort' => 7, 'icon-class' => '', diff --git a/packages/Webkul/Category/src/Repositories/CategoryRepository.php b/packages/Webkul/Category/src/Repositories/CategoryRepository.php index d4574759b..d54b1db53 100644 --- a/packages/Webkul/Category/src/Repositories/CategoryRepository.php +++ b/packages/Webkul/Category/src/Repositories/CategoryRepository.php @@ -74,6 +74,19 @@ class CategoryRepository extends Repository : Category::orderBy('position', 'ASC')->get()->toTree(); } + /** + * get visible category tree + * + * @param integer $id + * @return mixed + */ + public function getVisibleCategoryTree($id = null) + { + return $id + ? Category::orderBy('position', 'ASC')->where('id', '!=', $id)->where('status', '=', '1')->get()->toTree() + : Category::orderBy('position', 'ASC')->where('status', '=', '1')->get()->toTree(); + } + /** * Checks slug is unique or not based on locale * diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 0f1761bdb..25b284ab8 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -509,25 +509,51 @@ class Cart { if($id == $item->id) { if($item->type == "configurable") { $canBe = $this->canAddOrUpdate($item->child->id, $quantity); + + if($canBe == false) { + session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning')); + + return $cart; + } + + $item->update([ + 'quantity' => $quantity, + 'total' => core()->convertPrice($item->price * ($quantity)), + 'base_total' => $item->price * ($quantity), + 'total_weight' => $item->weight * ($quantity), + 'base_total_weight' => $item->weight * ($quantity) + ]); } else { $canBe = $this->canAddOrUpdate($id, $quantity); + + if($canBe == false) { + session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning')); + + return $cart; + } + $prevQty = $item->quantity; + + $item->update([ + 'quantity' => $quantity, + 'total' => core()->convertPrice($item->price * ($quantity)), + 'base_total' => $item->price * ($quantity), + 'total_weight' => $item->weight * ($quantity), + 'base_total_weight' => $item->weight * ($quantity) + ]); } - - if($canBe == false) { - session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning')); - - return $cart; - } - - $item->update(['quantity' => $quantity]); } } } + $this->collectTotals(); session()->flash('success', trans('shop::app.checkout.cart.quantity.success')); - } - return $cart; + return $cart; + } else { + session()->flash('warning', trans('shop::app.checkout.cart.integrity.missing_fields')); + + return false; + } } /** @@ -758,6 +784,8 @@ class Cart { if(!$cart = $this->getCart()) return false; + $this->validateItems(); + $this->calculateItemsTax(); $cart->grand_total = $cart->base_grand_total = 0; @@ -792,6 +820,60 @@ class Cart { $cart->save(); } + /** + * To validate if the product information is changed by admin and the items have + * been added to the cart before it. + * + * @return boolean + */ + public function validateItems() { + $cart = $this->getCart(); + + if(count($cart->items) == 0) { + $this->cart->delete($cart->id); + + return redirect()->route('shop.home.index'); + } else { + $items = $cart->items; + + foreach($items as $item) { + if($item->product->type == 'configurable') { + if($item->product->sku != $item->sku) { + $item->update(['sku' => $item->product->sku]); + + } else if($item->product->name != $item->name) { + $item->update(['name' => $item->product->name]); + + } else if($item->child->product->price != $item->price) { + $item->update([ + 'price' => $item->child->product->price, + 'base_price' => $item->child->product->price, + 'total' => core()->convertPrice($item->child->product->price * ($item->quantity)), + 'base_total' => $item->child->product->price * ($item->quantity), + ]); + } + + } else if($item->product->type == 'simple') { + if($item->product->sku != $item->sku) { + $item->update(['sku' => $item->product->sku]); + + } else if($item->product->name != $item->name) { + $item->update(['name' => $item->product->name]); + + } else if($item->product->price != $item->price) { + $item->update([ + 'price' => $item->product->price, + 'base_price' => $item->product->price, + 'total' => core()->convertPrice($item->child->product->price * ($item->quantity)), + 'base_total' => $item->child->product->price * ($item->quantity), + ]); + } + } + } + return true; + } + } + /** * Calculates cart items tax * diff --git a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php index 53b389bd1..d3c2b17c7 100644 --- a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php @@ -67,12 +67,12 @@ class RegistrationController extends Controller if ($this->customer->create($data)) { - session()->flash('success', 'Account created successfully.'); + session()->flash('success', 'Account Created Successfully'); return redirect()->route($this->_config['redirect']); } else { - session()->flash('error', 'Cannot Create Your Account.'); + session()->flash('error', 'Cannot Create Your Account'); return redirect()->back(); } diff --git a/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php b/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php index c4885ea34..b9f59a470 100644 --- a/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php +++ b/packages/Webkul/Shop/src/Http/ViewComposers/CategoryComposer.php @@ -44,7 +44,7 @@ class CategoryComposer { $categories = []; - foreach ($this->category->getCategoryTree() as $category) { + foreach ($this->category->getVisibleCategoryTree() as $category) { array_push($categories, collect($category)); } diff --git a/packages/Webkul/Shop/src/Resources/assets/js/components/category-item.vue b/packages/Webkul/Shop/src/Resources/assets/js/components/category-item.vue index 5c5ef5f18..d821519ca 100644 --- a/packages/Webkul/Shop/src/Resources/assets/js/components/category-item.vue +++ b/packages/Webkul/Shop/src/Resources/assets/js/components/category-item.vue @@ -1,4 +1,3 @@ - +