From 2328d5e98b832897cee9b4655d7f912a9a3f2e0e Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Fri, 28 Sep 2018 00:34:56 +0530 Subject: [PATCH 1/5] Cart Working, manual test before next commit --- packages/Webkul/Cart/src/Cart.php | 547 ++++++++++-------- ...8_09_05_150915_create_cart_items_table.php | 12 +- .../src/Http/Controllers/CartController.php | 43 +- packages/Webkul/Cart/src/Models/Cart.php | 4 + packages/Webkul/Cart/src/Models/CartItem.php | 20 +- .../Http/Listeners/CustomerEventsHandler.php | 9 +- packages/Webkul/Shop/src/Http/routes.php | 20 +- .../Webkul/Shop/src/Resources/lang/en/app.php | 5 +- .../views/checkout/cart/index.blade.php | 30 +- 9 files changed, 356 insertions(+), 334 deletions(-) diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php index e2d810f48..e1a07c11f 100644 --- a/packages/Webkul/Cart/src/Cart.php +++ b/packages/Webkul/Cart/src/Cart.php @@ -9,7 +9,6 @@ use Webkul\Cart\Repositories\CartAddressRepository; use Webkul\Customer\Repositories\CustomerRepository; use Webkul\Product\Repositories\ProductRepository; use Webkul\Cart\Models\CartPayment; -use Cookie; /** * Facade for all the methods to be implemented in Cart. @@ -83,58 +82,6 @@ class Cart { $this->product = $product; } - /** - * Method to check if the product is available and its required quantity - * is available or not in the inventory sources. - * - * @param integer $id - * - * @return Array - */ - public function canCheckOut($id) { - $cart = $this->cart->findOneByField('id', 144); - - $items = $cart->items; - - $allProdQty = array(); - - $allProdQty1 = array(); - - $totalQty = 0; - - foreach($items as $item) { - $inventories = $item->product->inventories; - - $inventory_sources = $item->product->inventory_sources; - - $totalQty = 0; - - foreach($inventory_sources as $inventory_source) { - if($inventory_source->status!=0) { - foreach($inventories as $inventory) { - $totalQty = $totalQty + $inventory->qty; - } - - array_push($allProdQty1, $totalQty); - - $allProdQty[$item->product->id] = $totalQty; - } - } - } - - foreach ($items as $item) { - $inventories = $item->product->inventory_sources->where('status', '=', '1'); - - foreach($inventories as $inventory) { - dump($inventory->status); - } - } - - dd($allProdQty); - - dd([true, false]); - } - /** * Create new cart instance with the current item added. * @@ -147,22 +94,22 @@ class Cart { { $itemData = $this->prepareItemData($id, $data); - // dd($itemData); - $cartData['channel_id'] = core()->getCurrentChannel()->id; // this will auto set the customer id for the cart instances if customer is authenticated if(auth()->guard('customer')->check()) { $cartData['customer_id'] = auth()->guard('customer')->user()->id; - $cartData['is_guest'] = 1; + $cartData['is_guest'] = 0; $cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; } + $cartData['is_guest'] = 1; + $cartData['items_count'] = 1; - $cartData['items_quantity'] = $data['quantity']; + $cartData['items_qty'] = $data['quantity']; if($cart = $this->cart->create($cartData)) { $itemData['parent']['cart_id'] = $cart->id; @@ -173,6 +120,7 @@ class Cart { if($parent = $this->cartItem->create($itemData['parent'])) { $itemData['child']['parent_id'] = $parent->id; + $itemData['child']['cart_id'] = $cart->id; if($child = $this->cartItem->create($itemData['child'])) { session()->put('cart', $cart); @@ -182,6 +130,11 @@ class Cart { } } + // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); + $this->collectTotals(); + + $this->collectQuantities(); + } else if($data['is_configurable'] == "false") { if($result = $this->cartItem->create($itemData['parent'])) { session()->put('cart', $cart); @@ -190,6 +143,11 @@ class Cart { return redirect()->back(); } + + // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); + $this->collectTotals(); + + $this->collectQuantities(); } } @@ -216,15 +174,11 @@ class Cart { if(!isset($data['product']) ||!isset($data['quantity'])) { session()->flash('error', 'Cart System Integrity Violation, Some Required Fields Missing.'); - dd('Missing Essential Parameters, Cannot Proceed Further'); - return redirect()->back(); } else { if($product->type == 'configurable' && !isset($data['super_attribute'])) { session()->flash('error', 'Cart System Integrity Violation, Configurable Options Not Found In Request.'); - dd('Super Attributes Missing From the Request Parameters.'); - return redirect()->back(); } } @@ -239,54 +193,44 @@ class Cart { 'quantity' => $data['quantity'], 'type' => 'configurable', 'name' => $product->name, - 'price' => ($price = $child->price), //This shoulf final price + 'price' => ($price = $child->price), //This should be price from the price helper 'base_price' => $price, - 'item_total' => $price * $data['quantity'], - 'base_item_total' => $price * $data['quantity'], + 'total' => $price * $data['quantity'], + 'base_total' => $price * $data['quantity'], 'weight' => ($weight = $child->weight), - 'item_weight' => $weight * $parentData['quantity'], - 'base_item_weight' => $weight * $parentData['quantity'], + 'total_weight' => $weight * $data['quantity'], + 'base_total_weight' => $weight * $data['quantity'], ]; - - - $parentData['base_item_weight'] = $parentData['weight'] * $parentData['quantity']; - //child row data - $childData['product_id'] = $data['selected_configurable_option']; - - $childData['quantity'] = 1; - - $childData['sku'] = $this->product->findOneByField('id', $data['selected_configurable_option'])->sku; - - $childData['type'] = $this->product->findOneByField('id', $data['selected_configurable_option'])->type; - - $childData['name'] = $this->product->findOneByField('id', $data['selected_configurable_option'])->name; + $childData = [ + 'product_id' => $data['selected_configurable_option'], + 'quantity' => 1, + 'sku' => $child->sku, + 'type' => $child->type, + 'name' => $child->name + ]; return ['parent' => $parentData, 'child' => $childData]; } else { - $data['product_id'] = $productId; - unset($data['product']); + $parentData = [ + 'sku' => $product->sku, + 'product_id' => $productId, + 'quantity' => $data['quantity'], + 'type' => 'simple', + 'name' => $product->name, + 'price' => $product->price, + 'base_price' => $product->price, + 'total' => $product->price * $data['quantity'], + 'base_total' => $product->price * $data['quantity'], + 'weight' => $product->weight, + 'total_weight' => $product->weight * $data['quantity'], + 'base_total_weight' => $product->weight * $data['quantity'], + ]; - $data['type'] = 'simple'; + // dd(['parent' => $parentData, 'child' => null]); - $data['name'] = $this->product->findOneByField('id', $productId)->name; - - $data['price'] = $this->product->findOneByField('id', $productId)->price; - - $data['base_price'] = $data['price']; - - $data['item_total'] = $data['price'] * $data['quantity']; - - $data['base_item_total'] = $data['price'] * $data['quantity']; - - $data['weight'] = $this->product->findOneByField('id', $productId)->weight; - - $data['item_weight'] = $data['weight'] * $data['quantity']; - - $data['base_item_weight'] = $data['weight'] * $data['quantity']; - - return ['parent' => $data, 'child' => null]; + return ['parent' => $parentData, 'child' => null]; } } @@ -300,10 +244,6 @@ class Cart { */ public function add($id, $data) { - // session()->forget('cart'); - - // return redirect()->back(); - $itemData = $this->prepareItemData($id, $data); if(session()->has('cart')) { @@ -317,45 +257,64 @@ class Cart { if($cartItem->product_id == $id) { $prevQty = $cartItem->quantity; - $newQty = $data['quantity']; - $cartItem->update(['quantity' => $prevQty + $newQty]); + $cartItem->update([ + 'quantity' => $prevQty + $newQty, + 'total' => $parentPrice * ($prevQty + $newQty), + 'base_total' => $parentPrice * ($prevQty + $newQty) + ]); + + $this->collectTotals(); + + $this->collectQuantities(); session()->flash('success', "Product Quantity Successfully Updated"); return redirect()->back(); } } else if($data['is_configurable'] == "true") { + if($cartItem->type == "configurable") { + if($cartItem->child->product_id == $data['selected_configurable_option']) { + $child = $cartItem->child; - //check the parent and child records that holds info abt this product. - if($cartItem->product_id == $data['selected_configurable_option']) { - $child = $cartItem; + $parent = $cartItem; + $parentPrice = $parent->price; - $parentId = $child->parent_id; + $prevQty = $parent->quantity; + $newQty = $data['quantity']; - $parent = $this->cartItem->findOneByField('id', $parentId); + $parent->update([ + 'quantity' => $prevQty + $newQty, + 'total' => $parentPrice * ($prevQty + $newQty), + 'base_total' => $parentPrice * ($prevQty + $newQty) + ]); - $parentPrice = $parent->price; + $this->collectTotals(); - $prevQty = $parent->quantity; + $this->collectQuantities(); - $newQty = $data['quantity']; + session()->flash('success', "Product Quantity Successfully Updated"); - $parent->update(['quantity' => $prevQty + $newQty, 'item_total' => $parentPrice * ($prevQty + $newQty)]); - - session()->flash('success', "Product Quantity Successfully Updated"); - - return redirect()->back(); + return redirect()->back(); + } } } } - $parent = $cart->items()->create($itemData['parent']); + if($data['is_configurable'] == "true") { + $parent = $cart->items()->create($itemData['parent']); - $itemData['child']['parent_id'] = $parent->id; + $itemData['child']['parent_id'] = $parent->id; - $cart->items()->create($itemData['child']); + $cart->items()->create($itemData['child']); + } else if($data['is_configurable'] == "false"){ + $parent = $cart->items()->create($itemData['parent']); + } + + $this->collectTotals(); + + $this->collectQuantities(); session()->flash('success', 'Item Successfully Added To Cart'); @@ -376,135 +335,22 @@ class Cart { * Use detach to remove the current product from cart tables * * @param Integer $id - * @return Mixed + * @return response */ public function remove($id) { + $item = $this->cartItem->findOneByField('id', $id); - dd("Removing Item from Cart"); - } - - /** - * This function handles when guest has some of cart products and then logs in. - * - * @return Response - */ - public function mergeCart() - { - if(session()->has('cart')) { - $cart = session()->get('cart'); - - $cartItems = $cart->items; - - $customerCart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id); - - if(isset($customerCart)) { - $customerCartItems = $this->cart->items($customerCart['id']); - - if(isset($customerCart)) { - foreach($cartItems as $key => $cartItem) { - // foreach($customerCartItems as $customerCartItem) { - - // // dd($customerCartItems, $cartItems[0]->parent_id); - - // if($cartItem->type == "simple" && $cartItem->parent_id == "null") { - // if($customerCartItem->type == "simple" && $customerCartItem->parent_id == "null") { - // //update the customer cart item details and delete the guest instance - - // if($customerCartItem->product_id == $cartItem->productId) { - - // $prevQty = $cartItem->quantity; - // $newQty = $customerCartItem->quantity; - - // $customerCartItem->update([ - // 'quantity' => $prevQty + $newQty, - // 'item_total' => $customerCartItem->price * ($prevQty + $newQty), - // 'base_item_total' => $customerCartItem->price * ($prevQty + $newQty), - // 'item_total_weight' => $customerCartItem->weight * ($prevQty + $newQty), - // 'base_item_total_weight' => $customerCartItem->weight * ($prevQty + $newQty) - // ]); - - // $cartItems->forget($key); - // } - // } - - // } else if($cartItem->type == "simple" && $cartItem->parent_id != "null") { - - // if($customerCartItem->type == "simple" && $customerCartItem->parent_id != "null") { - // //guest cartParent - // $cartItemParentId = $cartItem->parent_id; - // $cartItemParent = $this->cartItem->findOneByField('id', $cartItemParentId); - - // //customer cartParent - // $customerItemParentId = $customerCartItem->parent_id; - // $customerItemParent = $this->cartItem->findOneByField('id', $customerItemParentId); - - // if($cartItem->product_id == $customerCartItem->product_id) { - // $cartItemQuantity = $cartItemParent->quantity; - - // $customerCartItemQuantity = $customerItemParent->quantity; - - // $customerCartItem->update([ - // 'quantity' => $cartItemQuantity + $customerCartItemQuantity, - // 'item_total' => $customerItemParent->price * ($cartItemQuantity + $customerCartItemQuantity), - // 'base_item_total' => $customerItemParent->price * ($cartItemQuantity + $customerCartItemQuantity), - // 'item_total_weight' => $customerItemParent->weight * ($cartItemQuantity + $customerCartItemQuantity), - // 'base_item_total_weight' => $customerItemParent->weight * ($cartItemQuantity + $customerCartItemQuantity), - // ]); - - // $cartItems->forget($key); - // } - // } - // } - // } - } - - foreach($cartItems as $cartItem) { - $cartItem->update(['cart_id' => $customerCart['id']]); - } - $this->cart->delete($cart->id); - - return redirect()->back(); - } - } else { - foreach($cartItems as $cartItem) { - $this->cart->update(['customer_id' => auth()->guard('customer')->user()->id], $cart->id); - } - - return redirect()->back(); - } + dd($item); + if($item->parent_id != "null") { + $item->delete($id); } else { - return redirect()->back(); + $parentItem = $item->child; + + dd($parentItem, $item); } } - /** - * Destroys the session - * maintained for cart - * on customer logout. - * - * @return Mixed - */ - public function destroyCart() { - if(session()->has('cart')) { - session()->forget('cart'); - return redirect()->back(); - } - } - - /** - * Returns cart - * - * @return Mixed - */ - public function getCart() - { - if(!$cart = session()->get('cart')) - return false; - - return $this->cart->find($cart->id); - } - /** * Returns cart * @@ -516,7 +362,6 @@ class Cart { foreach($item->product->super_attributes as $attribute) { $option = $attribute->options()->where('id', $item->child->{$attribute->code})->first(); - $data['attributes'][$attribute->code] = [ 'attribute_name' => $attribute->name, 'option_label' => $option->label, @@ -633,11 +478,11 @@ class Cart { $cart->base_sub_total_with_discount = 0; foreach ($cart->items()->get() as $item) { - $cart->grand_total = (float) $cart->grand_total + $item->price; - $cart->base_grand_total = (float) $cart->base_grand_total + $item->base_price; + $cart->grand_total = (float) $cart->grand_total + $item->price * $item->quantity; + $cart->base_grand_total = (float) $cart->base_grand_total + $item->base_price * $item->quantity; - $cart->sub_total = (float) $cart->sub_total + $item->price; - $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_price; + $cart->sub_total = (float) $cart->sub_total + $item->price * $item->quantity; + $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_price * $item->quantity; } if($shipping = $cart->selected_shipping_rate) { @@ -647,4 +492,212 @@ class Cart { $cart->save(); } + + /** + * Update Cart Quantities, Weight + * + * @return void + */ + public function collectQuantities() { + if(!$cart = $this->getCart()) + return false; + + $quantities = 0; + + foreach($cart->items as $item) { + $quantities = $quantities + $item->quantity; + } + + $itemCount = $cart->items->count(); + + $cart->update(['items_count' => $itemCount, 'items_qty' => $quantities]); + + } + + /** + * This function handles when guest has some of cart products and then logs in. + * + * @return Response + */ + public function mergeCart() + { + if(session()->has('cart')) { + $cart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id); + + $guestCart = session()->get('cart'); + + if(!isset($cart)) { + $guestCart->update(['customer_id' => auth()->guard('customer')->user()->id]); + + session()->forget('cart'); + + session()->put('cart', $guestCart); + + return redirect()->back(); + } + + $cartItems = $cart->items; + + $guestCartId = $guestCart->id; + + $guestCartItems = $this->cart->findOneByField('id', $guestCartId)->items; + + foreach($guestCartItems as $key => $guestCartItem) { + foreach($cartItems as $cartItem) { + + if($guestCartItem->type == "simple") { + if($cartItem->product_id == $guestCartItem->product_id) { + $prevQty = $cartItem->quantity; + + $newQty = $guestCartItem->quantity; + + $cartItem->update([ + 'quantity' => $prevQty + $newQty, + 'total' => $cartItem->price * ($prevQty + $newQty), + 'base_total' => $cartItem->price * ($prevQty + $newQty), + 'total_weight' => $cartItem->weight * ($prevQty + $newQty), + 'base_total_weight' => $cartItem->weight * ($prevQty + $newQty) + ]); + + $guestCartItems->forget($key); + $this->cartItem->delete($guestCart->id); + } + } else if($guestCartItem->type == "configurable" && $cartItem->type == "configurable") { + $guestCartItemChild = $guestCartItem->child; + + $cartItemChild = $cartItem->child; + + if($guestCartItemChild->product_id == $cartItemChild->product_id) { + $prevQty = $guestCartItem->quantity; + $newQty = $cartItem->quantity; + + $cartItem->update([ + 'quantity' => $prevQty + $newQty, + 'total' => $cartItem->price * ($prevQty + $newQty), + 'base_total' => $cartItem->price * ($prevQty + $newQty), + 'total_weight' => $cartItem->weight * ($prevQty + $newQty), + 'base_total_weight' => $cartItem->weight * ($prevQty + $newQty) + ]); + + $guestCartItems->forget($key); + + //child will be deleted first + $this->cartItem->delete($guestCartItemChild->id); + + //then parent will get deleted + $this->cartItem->delete($guestCart->id); + } + } + } + } + + //now handle the products that are not deleted. + foreach($guestCartItems as $guestCartItem) { + + if($guestCartItem->type == "configurable") { + $guestCartItem->update(['cart_id' => $cart->id]); + + $guestCartItem->child->update(['cart_id' => $cart->id]); + } else{ + $guestCartItem->update(['cart_id' => $cart->id]); + } + } + + //delete the guest cart instance. + $this->cart->delete($guestCartId); + + //forget the guest cart instance + session()->forget('cart'); + + //put the customer cart instance + session()->put('cart', $cart); + + $this->collectTotals(); + + $this->collectQuantities(); + + return redirect()->back(); + } else { + return redirect()->back(); + } + } + + /** + * Method to check if the product is available and its required quantity + * is available or not in the inventory sources. + * + * @param integer $id + * + * @return Array + */ + public function canCheckOut($productId, $quantity) + { + $items = $cart->items; + + $allProdQty = array(); + + $allProdQty1 = array(); + + $totalQty = 0; + + foreach($items as $item) { + $inventories = $item->product->inventories; + + $inventory_sources = $item->product->inventory_sources; + + $totalQty = 0; + + foreach($inventory_sources as $inventory_source) { + if($inventory_source->status!=0) { + foreach($inventories as $inventory) { + $totalQty = $totalQty + $inventory->qty; + } + + array_push($allProdQty1, $totalQty); + + $allProdQty[$item->product->id] = $totalQty; + } + } + } + + foreach ($items as $item) { + $inventories = $item->product->inventory_sources->where('status', '=', '1'); + + foreach($inventories as $inventory) { + dump($inventory->status); + } + } + dd([true, false]); + } + + /** + * Returns cart + * + * @return Mixed + */ + public function getCart() + { + if(!$cart = session()->get('cart')) + return false; + + return $this->cart->find($cart->id); + } + + /** + * Destroys the session + * maintained for cart + * on customer logout. + * + * @return response + */ + public function destroyCart() + { + if(session()->has('cart')) { + session()->forget('cart'); + + return redirect()->back(); + } else { + return redirect()->back(); + } + } } \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php b/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php index e60bd6dd4..99ab8d31c 100644 --- a/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php +++ b/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php @@ -28,15 +28,15 @@ class CreateCartItemsTable extends Migration $table->foreign('tax_category_id')->references('id')->on('tax_categories'); $table->string('coupon_code')->nullable(); $table->decimal('weight', 12,4)->default(1); - $table->decimal('item_total_weight', 12,4)->default(0); - $table->decimal('base_item_total_weight', 12,4)->default(0); + $table->decimal('total_weight', 12,4)->default(0); + $table->decimal('base_total_weight', 12,4)->default(0); $table->decimal('price', 12,4)->default(1); - $table->decimal('item_total', 12,4)->default(0); - $table->decimal('base_item_total', 12,4)->default(0); - $table->decimal('item_total_with_discount', 12,4)->default(0); - $table->decimal('base_item_total_with_discount', 12,4)->default(0); $table->decimal('base_price', 12,4)->default(0); $table->decimal('custom_price', 12,4)->default(0); + $table->decimal('total', 12,4)->default(0); + $table->decimal('base_total', 12,4)->default(0); + $table->decimal('total_with_discount', 12,4)->default(0); + $table->decimal('base_total_with_discount', 12,4)->default(0); $table->decimal('discount_percent', 12,4)->default(0); $table->decimal('discount_amount', 12,4)->default(0); $table->decimal('base_discount_amount', 12,4)->default(0); diff --git a/packages/Webkul/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Cart/src/Http/Controllers/CartController.php index 01a9f145f..c4f03f063 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Cart/src/Http/Controllers/CartController.php @@ -85,6 +85,7 @@ class CartController extends Controller * @return Mixed */ public function index() { + // dd(Cart::getCart()); return view($this->_config['view'])->with('cart', Cart::getCart()); } @@ -97,10 +98,6 @@ class CartController extends Controller */ public function add($id) { - // session()->forget('cart'); - - // return redirect()->back(); - $data = request()->input(); Cart::add($id, $data); @@ -108,46 +105,12 @@ class CartController extends Controller return redirect()->back(); } - public function remove($id) { - - if(auth()->guard('customer')->check()) { - Cart::remove($id); - } else { - Cart::guestUnitRemove($id); - } + public function remove($itemId) { + Cart::remove($itemId); return redirect()->back(); } public function test() { - $cart = $this->cart->findOneByField('id', 144); - - $cartItems = $this->cart->items($cart['id']); - - $products = array(); - - foreach($cartItems as $cartItem) { - $image = $this->productImage->getGalleryImages($cartItem->product); - - dump($cartItem->product); - - if(isset($image[0]['small_image_url'])) { - $products[$cartItem->product->id] = [$cartItem->product->name, $cartItem->price, $image[0]['small_image_url'], $cartItem->quantity]; - } - else { - $products[$cartItem->product->id] = [$cartItem->product->name, $cartItem->price, 'null', $cartItem->quantity]; - } - } - dd($products); - } - - public function mergeTest() { - $cartItems = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id)->items; - - $tempId = 15; - - foreach($cartItems as $cartItem) { - - } } } \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Models/Cart.php b/packages/Webkul/Cart/src/Models/Cart.php index ada8f206d..f98e39861 100644 --- a/packages/Webkul/Cart/src/Models/Cart.php +++ b/packages/Webkul/Cart/src/Models/Cart.php @@ -21,6 +21,10 @@ class Cart extends Model return $this->hasMany(CartItem::class)->whereNull('parent_id'); } + public function all_items() { + return $this->hasMany(CartItem::class); + } + /** * Get the addresses for the cart. */ diff --git a/packages/Webkul/Cart/src/Models/CartItem.php b/packages/Webkul/Cart/src/Models/CartItem.php index f447dfa19..5d2ca9e6d 100644 --- a/packages/Webkul/Cart/src/Models/CartItem.php +++ b/packages/Webkul/Cart/src/Models/CartItem.php @@ -9,25 +9,25 @@ class CartItem extends Model { protected $table = 'cart_items'; - protected $fillable = ['product_id', 'quantity', 'cart_id', 'sku', 'type', 'name', 'parent_id','tax_category_id', 'coupon_code', 'weight', 'item_total_weight', 'base_item_total_weight', 'price', 'item_total', 'item_total_with_discount', 'base_item_total_with_discount', 'base_price', 'custom_price', 'discount_percent', 'discount_amount', 'base_discount_amount', 'no_discount', 'free_shipping', 'additional']; + protected $fillable = ['product_id', 'quantity', 'cart_id', 'sku', 'type', 'name', 'parent_id','tax_category_id', 'coupon_code', 'weight', 'total_weight', 'base_total_weight', 'price', 'total', 'base_total', 'total_with_discount', 'base_total_with_discount', 'base_price', 'custom_price', 'discount_percent', 'discount_amount', 'base_discount_amount', 'no_discount', 'free_shipping', 'additional']; public function product() { return $this->hasOne('Webkul\Product\Models\Product', 'id', 'product_id'); } - /** - * Get the phone record associated with the user. - */ - public function parent() - { - return $this->hasOne(self::class, 'parent_id'); - } + // /** + // * Get the parent item + // */ + // public function parent() + // { + // return $this->hasOne(self::class, 'parent_id', 'id'); + // } /** - * Get the phone record associated with the user. + * Get the child item. */ public function child() { - return $this->belongsTo(self::class, 'parent_id'); + return $this->belongsTo(self::class, 'id', 'parent_id'); } } diff --git a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php index c8411d440..ff92b9051 100644 --- a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php +++ b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php @@ -30,8 +30,9 @@ class CustomerEventsHandler { Cart::mergeCart(); } - //use this when there is very uttermost need to use it. - public function onCustomerLogout($event) { + //Customer Logout Event Handler. + public function onCustomerLogout($event) + { Cart::destroyCart(); } @@ -39,8 +40,8 @@ class CustomerEventsHandler { * Register the listeners for the subscriber. * * @param Illuminate\Events\Dispatcher $events - * @return void */ - + * @return void + */ public function subscribe($events) { $events->listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin'); diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index 904b265f3..e07372626 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -10,37 +10,31 @@ Route::group(['middleware' => ['web']], function () { 'view' => 'shop::products.index' ]); - Route::get('/checkout/cart', 'Webkul\Cart\Http\Controllers\CartController@index')->defaults('_config', [ - 'view' => 'shop::checkout.cart.index' - ])->name('shop.checkout.cart.index'); - Route::get('/checkout/onepage', 'Webkul\Cart\Http\Controllers\CheckoutController@index')->defaults('_config', [ 'view' => 'shop::checkout.onepage' ])->name('shop.checkout.onepage.index'); - Route::get('test', 'Webkul\Cart\Http\Controllers\CartController@test'); - - Route::get('mtest', 'Webkul\Cart\Http\Controllers\CartController@mergeTest'); - Route::post('/checkout/save-address', 'Webkul\Cart\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address'); Route::post('/checkout/save-shipping', 'Webkul\Cart\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping'); Route::post('/checkout/save-payment', 'Webkul\Cart\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment'); - /* dummy routes ends here */ - + //dummy + Route::get('test', 'Webkul\Cart\Http\Controllers\CartController@test'); Route::get('/products/{slug}', 'Webkul\Shop\Http\Controllers\ProductController@index')->defaults('_config', [ 'view' => 'shop::products.view' ])->name('shop.products.index'); // //Routes for product cart + Route::get('/checkout/cart', 'Webkul\Cart\Http\Controllers\CartController@index')->defaults('_config', [ + 'view' => 'shop::checkout.cart.index' + ])->name('shop.checkout.cart.index'); - Route::post('checkout/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add'); - - Route::post('checkout/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove'); + Route::post('product/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add'); + Route::get('product/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove'); //Routes for product cart ends // Product Review routes diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index d87981178..0e99b874f 100644 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -63,7 +63,10 @@ return [ 'title' => 'Shopping Cart', 'empty' => 'Shopping Cart Is Empty', 'continue-shopping' => 'Continue Shopping', - 'proceed-to-checkout' => 'Proceed To Checkout' + 'proceed-to-checkout' => 'Proceed To Checkout', + 'quantity' => 'Quantity', + 'remove' => 'Remove', + 'move-to-wishlist' => 'Move to Wishlist' ], 'onepage' => [ diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php index ddd754cbc..7065900c3 100644 --- a/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php @@ -23,8 +23,8 @@
@foreach($cart->items as $item) - product; + product; $productBaseImage = $productImageHelper->getProductBaseImage($product); ?> @@ -45,21 +45,25 @@
@if ($product->type == 'configurable') - -
- @foreach (cart()->getItemAttributeOptionDetails($item) as $key => $option) + +
+ {{-- @foreach (cart::getItemAttributeOptionDetails($item) as $key => $option) {{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }} - - @endforeach + + @endforeach --}}
@endif
-
Quantity
+
{{ __('shop::app.checkout.cart.quantity') }}
{{ $item->quantity }}
- Remove - Move to Wishlist + @if($product->type == 'configurable') + {{ __('shop::app.checkout.cart.remove') }} + @else + {{ __('shop::app.checkout.cart.remove') }} + @endif + {{ __('shop::app.checkout.cart.move-to-wishlist') }}
@@ -67,7 +71,7 @@ @endforeach - +
{{ __('shop::app.checkout.cart.continue-shopping') }} @@ -85,7 +89,7 @@
- + @else
@@ -94,5 +98,5 @@ @endif - + @endsection \ No newline at end of file From 0bb851d5187e91302bc39e728f88b12bdf47e9fc Mon Sep 17 00:00:00 2001 From: jitendra Date: Fri, 28 Sep 2018 18:24:26 +0530 Subject: [PATCH 2/5] Sale package schema added and renamed package cart to checkout --- composer.json | 5 +- composer.lock | 169 +++++++++++++++++- config/app.php | 5 +- .../Cart/src/Http/Controllers/Controller.php | 13 -- packages/Webkul/{Cart => Checkout}/.gitignore | 0 .../Webkul/{Cart => Checkout}/composer.json | 6 +- .../Webkul/{Cart => Checkout}/src/Cart.php | 24 +-- .../2018_09_05_150444_create_cart_table.php | 0 ...8_09_05_150915_create_cart_items_table.php | 12 +- .../2018_09_19_092845_create_cart_address.php | 0 .../2018_09_19_093453_create_cart_payment.php | 0 ...93508_create_cart_shipping_rates_table.php | 0 .../{Cart => Checkout}/src/Facades/Cart.php | 2 +- .../src/Http/Requests/CustomerAddressForm.php | 2 +- .../src/Http/ViewComposers/CartComposer.php | 2 +- .../{Cart => Checkout}/src/Http/helpers.php | 2 +- .../{Cart => Checkout}/src/Models/Cart.php | 14 +- .../src/Models/CartAddress.php | 4 +- .../src/Models/CartItem.php | 2 +- .../src/Models/CartPayment.php | 2 +- .../src/Models/CartShippingRate.php | 4 +- .../src/Providers/CartServiceProvider.php | 8 +- .../src/Providers/ComposerServiceProvider.php | 4 +- .../Repositories/CartAddressRepository.php | 4 +- .../src/Repositories/CartItemRepository.php | 4 +- .../src/Repositories/CartRepository.php | 4 +- packages/Webkul/Sales/composer.json | 4 +- .../Webkul/Sales/src/Contracts/Invoice.php | 7 + .../Sales/src/Contracts/InvoiceItem.php | 7 + packages/Webkul/Sales/src/Contracts/Order.php | 7 + .../Sales/src/Contracts/OrderAddress.php | 7 + .../Webkul/Sales/src/Contracts/OrderItem.php | 7 + .../Webkul/Sales/src/Contracts/Shipment.php | 7 + .../Sales/src/Contracts/ShipmentItem.php | 7 + .../2018_09_27_113154_create_orders_table.php | 92 ++++++++++ ..._09_27_113207_create_order_items_table.php | 78 ++++++++ ...9_27_113405_create_order_address_table.php | 46 +++++ ...18_09_27_115022_create_shipments_table.php | 46 +++++ ..._27_115029_create_shipment_items_table.php | 50 ++++++ ...018_09_27_115135_create_invoices_table.php | 68 +++++++ ...9_27_115144_create_invoice_items_table.php | 54 ++++++ packages/Webkul/Sales/src/Models/Invoice.php | 72 ++++++++ .../Webkul/Sales/src/Models/InvoiceItem.php | 41 +++++ .../Sales/src/Models/InvoiceItemProxy.php | 10 ++ .../Webkul/Sales/src/Models/InvoiceProxy.php | 10 ++ packages/Webkul/Sales/src/Models/Order.php | 88 +++++++++ .../Webkul/Sales/src/Models/OrderAddress.php | 28 +++ .../Sales/src/Models/OrderAddressProxy.php | 10 ++ .../Webkul/Sales/src/Models/OrderItem.php | 33 ++++ .../Sales/src/Models/OrderItemProxy.php | 10 ++ .../Webkul/Sales/src/Models/OrderProxy.php | 10 ++ packages/Webkul/Sales/src/Models/Shipment.php | 64 +++++++ .../Webkul/Sales/src/Models/ShipmentItem.php | 41 +++++ .../Sales/src/Models/ShipmentItemProxy.php | 10 ++ .../Webkul/Sales/src/Models/ShipmentProxy.php | 10 ++ .../src/Providers/ModuleServiceProvider.php | 18 ++ .../src/Providers/SalesServiceProvider.php | 6 +- .../Repositories/InvoiceItemRepository.php | 27 +++ .../src/Repositories/InvoiceRepository.php | 27 +++ .../Repositories/OrderAddressRepository.php | 27 +++ .../src/Repositories/OrderItemRepository.php | 27 +++ .../src/Repositories/OrderRepository.php | 61 +++++++ .../src/Repositories/ShipmentRepository.php | 27 +++ .../Repositories/ShipmenttemRepository.php | 27 +++ .../src/Http/Controllers/CartController.php | 11 +- .../Http/Controllers/OnepageController.php} | 7 +- packages/Webkul/Shop/src/Http/routes.php | 16 +- 67 files changed, 1405 insertions(+), 92 deletions(-) delete mode 100644 packages/Webkul/Cart/src/Http/Controllers/Controller.php rename packages/Webkul/{Cart => Checkout}/.gitignore (100%) rename packages/Webkul/{Cart => Checkout}/composer.json (71%) rename packages/Webkul/{Cart => Checkout}/src/Cart.php (97%) rename packages/Webkul/{Cart => Checkout}/src/Database/Migrations/2018_09_05_150444_create_cart_table.php (100%) rename packages/Webkul/{Cart => Checkout}/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php (84%) rename packages/Webkul/{Cart => Checkout}/src/Database/Migrations/2018_09_19_092845_create_cart_address.php (100%) rename packages/Webkul/{Cart => Checkout}/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php (100%) rename packages/Webkul/{Cart => Checkout}/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php (100%) rename packages/Webkul/{Cart => Checkout}/src/Facades/Cart.php (88%) rename packages/Webkul/{Cart => Checkout}/src/Http/Requests/CustomerAddressForm.php (97%) rename packages/Webkul/{Cart => Checkout}/src/Http/ViewComposers/CartComposer.php (98%) rename packages/Webkul/{Cart => Checkout}/src/Http/helpers.php (79%) rename packages/Webkul/{Cart => Checkout}/src/Models/Cart.php (87%) rename packages/Webkul/{Cart => Checkout}/src/Models/CartAddress.php (89%) rename packages/Webkul/{Cart => Checkout}/src/Models/CartItem.php (96%) rename packages/Webkul/{Cart => Checkout}/src/Models/CartPayment.php (77%) rename packages/Webkul/{Cart => Checkout}/src/Models/CartShippingRate.php (76%) rename packages/Webkul/{Cart => Checkout}/src/Providers/CartServiceProvider.php (87%) rename packages/Webkul/{Cart => Checkout}/src/Providers/ComposerServiceProvider.php (87%) rename packages/Webkul/{Cart => Checkout}/src/Repositories/CartAddressRepository.php (79%) rename packages/Webkul/{Cart => Checkout}/src/Repositories/CartItemRepository.php (91%) rename packages/Webkul/{Cart => Checkout}/src/Repositories/CartRepository.php (93%) create mode 100644 packages/Webkul/Sales/src/Contracts/Invoice.php create mode 100644 packages/Webkul/Sales/src/Contracts/InvoiceItem.php create mode 100644 packages/Webkul/Sales/src/Contracts/Order.php create mode 100644 packages/Webkul/Sales/src/Contracts/OrderAddress.php create mode 100644 packages/Webkul/Sales/src/Contracts/OrderItem.php create mode 100644 packages/Webkul/Sales/src/Contracts/Shipment.php create mode 100644 packages/Webkul/Sales/src/Contracts/ShipmentItem.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113154_create_orders_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113207_create_order_items_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113405_create_order_address_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115022_create_shipments_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115029_create_shipment_items_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115135_create_invoices_table.php create mode 100644 packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115144_create_invoice_items_table.php create mode 100644 packages/Webkul/Sales/src/Models/Invoice.php create mode 100644 packages/Webkul/Sales/src/Models/InvoiceItem.php create mode 100644 packages/Webkul/Sales/src/Models/InvoiceItemProxy.php create mode 100644 packages/Webkul/Sales/src/Models/InvoiceProxy.php create mode 100644 packages/Webkul/Sales/src/Models/Order.php create mode 100644 packages/Webkul/Sales/src/Models/OrderAddress.php create mode 100644 packages/Webkul/Sales/src/Models/OrderAddressProxy.php create mode 100644 packages/Webkul/Sales/src/Models/OrderItem.php create mode 100644 packages/Webkul/Sales/src/Models/OrderItemProxy.php create mode 100644 packages/Webkul/Sales/src/Models/OrderProxy.php create mode 100644 packages/Webkul/Sales/src/Models/Shipment.php create mode 100644 packages/Webkul/Sales/src/Models/ShipmentItem.php create mode 100644 packages/Webkul/Sales/src/Models/ShipmentItemProxy.php create mode 100644 packages/Webkul/Sales/src/Models/ShipmentProxy.php create mode 100644 packages/Webkul/Sales/src/Providers/ModuleServiceProvider.php create mode 100644 packages/Webkul/Sales/src/Repositories/InvoiceItemRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/InvoiceRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/OrderAddressRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/OrderItemRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/OrderRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/ShipmentRepository.php create mode 100644 packages/Webkul/Sales/src/Repositories/ShipmenttemRepository.php rename packages/Webkul/{Cart => Shop}/src/Http/Controllers/CartController.php (93%) rename packages/Webkul/{Cart/src/Http/Controllers/CheckoutController.php => Shop/src/Http/Controllers/OnepageController.php} (94%) diff --git a/composer.json b/composer.json index 7fe23c407..3db3c622d 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "intervention/image": "^2.4", "intervention/imagecache": "^2.3", "kalnoy/nestedset": "^4.3", + "konekt/concord": "^1.2", "laravel/framework": "5.6.*", "laravel/tinker": "^1.0", "nwidart/laravel-modules": "^3.2", @@ -34,7 +35,7 @@ "webkul/laravel-ui": "self.version", "webkul/laravel-core": "self.version", "webkul/laravel-attribute": "self.version", - "webkul/laravel-cart": "self.version", + "webkul/laravel-checkout": "self.version", "webkul/laravel-customer": "self.version", "webkul/laravel-inventory": "self.version", "webkul/laravel-category": "self.version", @@ -56,7 +57,7 @@ "Webkul\\Admin\\": "packages/Webkul/Admin/src", "Webkul\\Ui\\": "packages/Webkul/Ui/src", "Webkul\\Category\\": "packages/Webkul/Category/src", - "Webkul\\Cart\\": "packages/Webkul/Cart/src", + "Webkul\\Checkout\\": "packages/Webkul/Checkout/src", "Webkul\\Attribute\\": "packages/Webkul/Attribute/src", "Webkul\\Shop\\": "packages/Webkul/Shop/src", "Webkul\\Core\\": "packages/Webkul/Core/src", diff --git a/composer.lock b/composer.lock index ec992ced6..d3653b9fa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0c2a23aa2502c590b2ccf7975329ce1", + "content-hash": "762c5c196d8a9a7814101fd53d60b1cf", "packages": [ { "name": "commerceguys/intl", @@ -922,6 +922,173 @@ ], "time": "2018-02-04T08:47:55+00:00" }, + { + "name": "konekt/concord", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/artkonekt/concord.git", + "reference": "7379f847fe1e90f9b71ce3f435dd9617ab8dfff5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/artkonekt/concord/zipball/7379f847fe1e90f9b71ce3f435dd9617ab8dfff5", + "reference": "7379f847fe1e90f9b71ce3f435dd9617ab8dfff5", + "shasum": "" + }, + "require": { + "illuminate/console": "~5.4", + "illuminate/support": "~5.4", + "konekt/enum": "~2.1", + "konekt/enum-eloquent": "^1.1.3", + "php": ">=7.0.0" + }, + "require-dev": { + "orchestra/testbench": "^3.4.2", + "phpunit/phpunit": "6.0 - 7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Konekt\\Concord\\ConcordServiceProvider" + ], + "aliases": { + "Concord": "Konekt\\Concord\\Facades\\Concord", + "Helper": "Konekt\\Concord\\Facades\\Helper" + } + } + }, + "autoload": { + "psr-4": { + "Konekt\\Concord\\": "src" + }, + "files": [ + "src/Support/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Attila Fulop", + "homepage": "https://github.com/fulopattila122" + } + ], + "description": "Concord is a Laravel Extension for building modular Laravel Applications", + "time": "2018-08-11T08:25:39+00:00" + }, + { + "name": "konekt/enum", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/artkonekt/enum.git", + "reference": "ab37d89e1a6f88a76f25c6dd88b56b8892de86f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/artkonekt/enum/zipball/ab37d89e1a6f88a76f25c6dd88b56b8892de86f2", + "reference": "ab37d89e1a6f88a76f25c6dd88b56b8892de86f2", + "shasum": "" + }, + "require": { + "php": ">=7.0.0" + }, + "require-dev": { + "phpunit/phpunit": "6.2 - 7.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "psr-4": { + "Konekt\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Attila Fulop", + "homepage": "https://github.com/fulopattila122" + } + ], + "description": "SPL inspired PHP enum class implementation", + "keywords": [ + "artkonekt", + "enum", + "konekt" + ], + "time": "2018-06-09T13:03:01+00:00" + }, + { + "name": "konekt/enum-eloquent", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/artkonekt/enum-eloquent.git", + "reference": "f67c981d549f69cddb9956ef51d16267c050a0c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/artkonekt/enum-eloquent/zipball/f67c981d549f69cddb9956ef51d16267c050a0c9", + "reference": "f67c981d549f69cddb9956ef51d16267c050a0c9", + "shasum": "" + }, + "require": { + "illuminate/database": "5.*", + "konekt/enum": "^2.0.2", + "php": ">=7.0.0" + }, + "require-dev": { + "illuminate/events": "5.*", + "phpunit/phpunit": "~6.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Konekt\\Enum\\Eloquent\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Attila Fulop", + "homepage": "https://github.com/fulopattila122" + } + ], + "description": "Enum attribute casting for Eloquent models", + "keywords": [ + "artkonekt", + "eloquent", + "enum", + "konekt", + "laravel" + ], + "time": "2017-12-08T17:57:42+00:00" + }, { "name": "laravel/framework", "version": "v5.6.29", diff --git a/config/app.php b/config/app.php index 56e8a7b5a..a42f0875f 100644 --- a/config/app.php +++ b/config/app.php @@ -175,6 +175,7 @@ return [ //Repository Prettus\Repository\Providers\RepositoryServiceProvider::class, + Konekt\Concord\ConcordServiceProvider::class, //Webkul packages Webkul\User\Providers\UserServiceProvider::class, @@ -188,7 +189,7 @@ return [ Webkul\Inventory\Providers\InventoryServiceProvider::class, Webkul\Product\Providers\ProductServiceProvider::class, Webkul\Theme\Providers\ThemeServiceProvider::class, - Webkul\Cart\Providers\CartServiceProvider::class, + Webkul\Checkout\Providers\CartServiceProvider::class, Webkul\Shipping\Providers\ShippingServiceProvider::class, Webkul\Payment\Providers\PaymentServiceProvider::class, Webkul\Sales\Providers\SalesServiceProvider::class, @@ -243,7 +244,7 @@ return [ 'Datagrid' => Webkul\Ui\DataGrid\Facades\DataGrid::class, 'ProductGrid' => Webkul\Ui\DataGrid\Facades\ProductGrid::class, 'Image' => Intervention\Image\Facades\Image::class, - 'Cart' => Webkul\Cart\Facades\Cart::class, + 'Cart' => Webkul\Checkout\Facades\Cart::class, 'Core' => Webkul\Core\Facades\Core::class ], diff --git a/packages/Webkul/Cart/src/Http/Controllers/Controller.php b/packages/Webkul/Cart/src/Http/Controllers/Controller.php deleted file mode 100644 index 3b56110cc..000000000 --- a/packages/Webkul/Cart/src/Http/Controllers/Controller.php +++ /dev/null @@ -1,13 +0,0 @@ -base_sub_total_with_discount = 0; foreach ($cart->items()->get() as $item) { - $cart->grand_total = (float) $cart->grand_total + $item->price; - $cart->base_grand_total = (float) $cart->base_grand_total + $item->base_price; + $cart->grand_total = (float) $cart->grand_total + $item->total; + $cart->base_grand_total = (float) $cart->base_grand_total + $item->base_total; - $cart->sub_total = (float) $cart->sub_total + $item->price; - $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_price; + $cart->sub_total = (float) $cart->sub_total + $item->total; + $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_total; } if($shipping = $cart->selected_shipping_rate) { diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150444_create_cart_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php similarity index 100% rename from packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150444_create_cart_table.php rename to packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150444_create_cart_table.php diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php similarity index 84% rename from packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php rename to packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php index e60bd6dd4..fb4222ee6 100644 --- a/packages/Webkul/Cart/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php +++ b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_05_150915_create_cart_items_table.php @@ -28,13 +28,13 @@ class CreateCartItemsTable extends Migration $table->foreign('tax_category_id')->references('id')->on('tax_categories'); $table->string('coupon_code')->nullable(); $table->decimal('weight', 12,4)->default(1); - $table->decimal('item_total_weight', 12,4)->default(0); - $table->decimal('base_item_total_weight', 12,4)->default(0); + $table->decimal('total_weight', 12,4)->default(0); + $table->decimal('base_total_weight', 12,4)->default(0); $table->decimal('price', 12,4)->default(1); - $table->decimal('item_total', 12,4)->default(0); - $table->decimal('base_item_total', 12,4)->default(0); - $table->decimal('item_total_with_discount', 12,4)->default(0); - $table->decimal('base_item_total_with_discount', 12,4)->default(0); + $table->decimal('total', 12,4)->default(0); + $table->decimal('base_total', 12,4)->default(0); + $table->decimal('total_with_discount', 12,4)->default(0); + $table->decimal('base_total_with_discount', 12,4)->default(0); $table->decimal('base_price', 12,4)->default(0); $table->decimal('custom_price', 12,4)->default(0); $table->decimal('discount_percent', 12,4)->default(0); diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_19_092845_create_cart_address.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php similarity index 100% rename from packages/Webkul/Cart/src/Database/Migrations/2018_09_19_092845_create_cart_address.php rename to packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_092845_create_cart_address.php diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php similarity index 100% rename from packages/Webkul/Cart/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php rename to packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093453_create_cart_payment.php diff --git a/packages/Webkul/Cart/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php b/packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php similarity index 100% rename from packages/Webkul/Cart/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php rename to packages/Webkul/Checkout/src/Database/Migrations/2018_09_19_093508_create_cart_shipping_rates_table.php diff --git a/packages/Webkul/Cart/src/Facades/Cart.php b/packages/Webkul/Checkout/src/Facades/Cart.php similarity index 88% rename from packages/Webkul/Cart/src/Facades/Cart.php rename to packages/Webkul/Checkout/src/Facades/Cart.php index 10481133b..bc4c52c07 100644 --- a/packages/Webkul/Cart/src/Facades/Cart.php +++ b/packages/Webkul/Checkout/src/Facades/Cart.php @@ -1,6 +1,6 @@ app->bind('cart', 'Webkul\Cart\Cart'); + $this->app->bind('cart', 'Webkul\Checkout\Cart'); } } \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php b/packages/Webkul/Checkout/src/Providers/ComposerServiceProvider.php similarity index 87% rename from packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php rename to packages/Webkul/Checkout/src/Providers/ComposerServiceProvider.php index 3f62d51c7..73007f3fa 100644 --- a/packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php +++ b/packages/Webkul/Checkout/src/Providers/ComposerServiceProvider.php @@ -1,6 +1,6 @@ increments('id'); + $table->string('increment_id'); + + $table->boolean('is_guest')->nullable(); + $table->string('customer_email')->nullable(); + $table->string('customer_first_name')->nullable(); + $table->string('customer_last_name')->nullable(); + + $table->string('shipping_method')->nullable(); + $table->string('shipping_description')->nullable(); + $table->string('coupon_code')->nullable(); + $table->boolean('is_gift')->default(0); + + $table->integer('total_item_count')->nullable(); + $table->integer('total_qty_ordered')->nullable(); + + $table->string('base_currency_code')->nullable(); + $table->string('channel_currency_code')->nullable(); + $table->string('order_currency_code')->nullable(); + + $table->decimal('grand_total', 12, 4)->default(0)->nullable(); + $table->decimal('base_grand_total', 12, 4)->default(0)->nullable(); + $table->decimal('grand_total_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_grand_total_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('grand_total_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_grand_total_refunded', 12, 4)->default(0)->nullable(); + + $table->decimal('sub_total', 12, 4)->default(0)->nullable(); + $table->decimal('base_sub_total', 12, 4)->default(0)->nullable(); + $table->decimal('sub_total_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_sub_total_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('sub_total_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_sub_total_refunded', 12, 4)->default(0)->nullable(); + + $table->decimal('discount_percent', 12, 4)->default(0)->nullable(); + $table->decimal('discount_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_amount', 12, 4)->default(0)->nullable(); + $table->decimal('discount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('discount_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_refunded', 12, 4)->default(0)->nullable(); + + $table->decimal('tax_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount', 12, 4)->default(0)->nullable(); + $table->decimal('tax_amount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('tax_amount_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount_refunded', 12, 4)->default(0)->nullable(); + + $table->decimal('shipping_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_shipping_amount', 12, 4)->default(0)->nullable(); + $table->decimal('shipping_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_shipping_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('shipping_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_shipping_refunded', 12, 4)->default(0)->nullable(); + + $table->integer('customer_id')->unsigned()->nullable(); + $table->string('customer_type')->nullable(); + $table->foreign('customer_id')->references('id')->on('customers')->onDelete('set null'); + $table->integer('channel_id')->unsigned()->nullable(); + $table->string('channel_type')->nullable(); + $table->foreign('channel_id')->references('id')->on('channels')->onDelete('set null'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('orders'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113207_create_order_items_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113207_create_order_items_table.php new file mode 100644 index 000000000..930724305 --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113207_create_order_items_table.php @@ -0,0 +1,78 @@ +increments('id'); + $table->string('sku')->nullable(); + $table->string('type')->nullable(); + $table->string('name')->nullable(); + $table->string('coupon_code')->nullable(); + + $table->decimal('weight', 12,4)->default(0)->nullable(); + $table->decimal('total_weight', 12,4)->default(0)->nullable(); + + $table->integer('qty_ordered')->default(0)->nullable(); + $table->integer('qty_shipped')->default(0)->nullable(); + $table->integer('qty_invoiced')->default(0)->nullable(); + $table->integer('qty_refunded')->default(0)->nullable(); + + $table->decimal('price', 12,4)->default(0); + $table->decimal('base_price', 12,4)->default(0); + + $table->decimal('total', 12,4)->default(0); + $table->decimal('base_total', 12,4)->default(0); + $table->decimal('total_invoiced', 12,4)->default(0); + $table->decimal('base_total_invoiced', 12,4)->default(0); + $table->decimal('amount_refunded', 12,4)->default(0); + $table->decimal('base_amount_refunded', 12,4)->default(0); + + $table->decimal('discount_percent', 12, 4)->default(0)->nullable(); + $table->decimal('discount_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_amount', 12, 4)->default(0)->nullable(); + $table->decimal('discount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('discount_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_refunded', 12, 4)->default(0)->nullable(); + + $table->decimal('tax_percent', 12, 4)->default(0)->nullable(); + $table->decimal('tax_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount', 12, 4)->default(0)->nullable(); + $table->decimal('tax_amount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount_invoiced', 12, 4)->default(0)->nullable(); + $table->decimal('tax_amount_refunded', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount_refunded', 12, 4)->default(0)->nullable(); + + $table->integer('product_id')->unsigned()->nullable(); + $table->string('product_type')->nullable(); + $table->integer('order_id')->unsigned()->nullable(); + $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade'); + $table->integer('parent_id')->unsigned()->nullable(); + $table->foreign('parent_id')->references('id')->on('order_items')->onDelete('cascade'); + + $table->json('additional')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('order_items'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113405_create_order_address_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113405_create_order_address_table.php new file mode 100644 index 000000000..7083fc8ca --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_113405_create_order_address_table.php @@ -0,0 +1,46 @@ +increments('id'); + $table->string('first_name'); + $table->string('last_name'); + $table->string('email'); + $table->string('address1'); + $table->string('address2')->nullable(); + $table->string('country'); + $table->string('state'); + $table->string('city'); + $table->integer('postcode'); + $table->string('phone'); + $table->string('address_type'); + $table->integer('order_id')->unsigned(); + $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade'); + $table->integer('customer_id')->unsigned()->nullable(); + $table->foreign('customer_id')->references('id')->on('customers')->onDelete('set null'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('order_address'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115022_create_shipments_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115022_create_shipments_table.php new file mode 100644 index 000000000..8e7357c02 --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115022_create_shipments_table.php @@ -0,0 +1,46 @@ +increments('id'); + $table->string('status')->nullable(); + + $table->integer('total_qty')->nullable(); + $table->integer('total_weight')->nullable(); + $table->string('carrier_code')->nullable(); + $table->string('carrier_title')->nullable(); + $table->text('track_number')->nullable(); + $table->boolean('email_sent')->default(0); + + $table->integer('customer_id')->unsigned()->nullable(); + $table->string('customer_type')->nullable(); + $table->integer('order_id')->unsigned(); + $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade'); + $table->integer('order_address_id')->unsigned()->nullable(); + $table->foreign('order_address_id')->references('id')->on('order_address')->onDelete('set null'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('shipments'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115029_create_shipment_items_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115029_create_shipment_items_table.php new file mode 100644 index 000000000..2d92a3802 --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115029_create_shipment_items_table.php @@ -0,0 +1,50 @@ +increments('id'); + $table->string('name')->nullable(); + $table->string('description')->nullable(); + $table->string('sku')->nullable(); + $table->integer('qty')->nullable(); + $table->integer('weight')->nullable(); + + $table->decimal('price', 12, 4)->default(0)->nullable(); + $table->decimal('base_price', 12, 4)->default(0)->nullable(); + $table->decimal('base_total', 12, 4)->default(0)->nullable(); + + $table->integer('product_id')->unsigned()->nullable(); + $table->string('product_type')->nullable(); + $table->integer('order_item_id')->unsigned()->nullable(); + $table->integer('shipment_id')->unsigned(); + $table->foreign('shipment_id')->references('id')->on('shipments')->onDelete('cascade'); + $table->integer('parent_id')->unsigned()->nullable(); + $table->foreign('parent_id')->references('id')->on('shipment_items')->onDelete('cascade'); + + $table->json('additional')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('shipment_items'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115135_create_invoices_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115135_create_invoices_table.php new file mode 100644 index 000000000..8499953d8 --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115135_create_invoices_table.php @@ -0,0 +1,68 @@ +increments('id'); + $table->string('increment_id'); + $table->string('state')->nullable(); + $table->boolean('email_sent')->default(0); + $table->string('shipping_method')->nullable(); + $table->string('shipping_description')->nullable(); + $table->string('coupon_code')->nullable(); + $table->boolean('is_gift')->default(0); + + $table->integer('total_item_count')->nullable(); + $table->integer('total_qty_ordered')->nullable(); + + $table->string('base_currency_code')->nullable(); + $table->string('channel_currency_code')->nullable(); + $table->string('order_currency_code')->nullable(); + + $table->decimal('sub_total', 12, 4)->default(0)->nullable(); + $table->decimal('base_sub_total', 12, 4)->default(0)->nullable(); + + $table->decimal('grand_total', 12, 4)->default(0)->nullable(); + $table->decimal('base_grand_total', 12, 4)->default(0)->nullable(); + + $table->decimal('shipping_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_shipping_amount', 12, 4)->default(0)->nullable(); + + $table->decimal('tax_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_tax_amount', 12, 4)->default(0)->nullable(); + + $table->decimal('discount_amount', 12, 4)->default(0)->nullable(); + $table->decimal('base_discount_amount', 12, 4)->default(0)->nullable(); + + $table->integer('customer_id')->unsigned()->nullable(); + $table->string('customer_type')->nullable(); + $table->integer('channel_id')->unsigned()->nullable(); + $table->string('channel_type')->nullable(); + $table->foreign('channel_id')->references('id')->on('channels')->onDelete('set null'); + $table->integer('order_address_id')->unsigned()->nullable(); + $table->foreign('order_address_id')->references('id')->on('order_address')->onDelete('set null'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('invoices'); + } +} diff --git a/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115144_create_invoice_items_table.php b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115144_create_invoice_items_table.php new file mode 100644 index 000000000..93b98a143 --- /dev/null +++ b/packages/Webkul/Sales/src/Database/Migrations/2018_09_27_115144_create_invoice_items_table.php @@ -0,0 +1,54 @@ +increments('id'); + $table->string('name')->nullable(); + $table->string('description')->nullable(); + $table->string('sku')->nullable(); + $table->integer('qty')->nullable(); + + $table->decimal('price', 12,4)->default(0); + $table->decimal('base_price', 12,4)->default(0); + + $table->decimal('total', 12,4)->default(0); + $table->decimal('base_total', 12,4)->default(0); + + $table->decimal('tax_amount', 12,4)->default(0)->nullable(); + $table->decimal('base_tax_amount', 12,4)->default(0)->nullable(); + + $table->integer('product_id')->unsigned()->nullable(); + $table->string('product_type')->nullable(); + $table->integer('order_item_id')->unsigned()->nullable(); + $table->integer('invoice_id')->unsigned()->nullable(); + $table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); + $table->integer('parent_id')->unsigned()->nullable(); + $table->foreign('parent_id')->references('id')->on('shipment_items')->onDelete('cascade'); + + $table->json('additional')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('invoice_items'); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/Invoice.php b/packages/Webkul/Sales/src/Models/Invoice.php new file mode 100644 index 000000000..35a8d782d --- /dev/null +++ b/packages/Webkul/Sales/src/Models/Invoice.php @@ -0,0 +1,72 @@ +hasMany(InvoiceItemProxy::modelClass())->whereNull('parent_id'); + } + + /** + * Get the customer record associated with the invoice. + */ + public function customer() + { + return $this->morphTo(); + } + + /** + * Get the channel record associated with the invoice. + */ + public function channel() + { + return $this->morphTo(); + } + + /** + * Get the addresses for the invoice. + */ + public function addresses() + { + return $this->hasMany(OrderAddressProxy::modelClass()); + } + + /** + * Get the biling address for the invoice. + */ + public function billing_address() + { + return $this->addresses()->where('address_type', 'billing'); + } + + /** + * Get billing address for the invoice. + */ + public function getBillingAddressAttribute() + { + return $this->billing_address()->first(); + } + + /** + * Get the shipping address for the invoice. + */ + public function shipping_address() + { + return $this->addresses()->where('address_type', 'shipping'); + } + + /** + * Get shipping address for the invoice. + */ + public function getShippingAddressAttribute() + { + return $this->shipping_address()->first(); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/InvoiceItem.php b/packages/Webkul/Sales/src/Models/InvoiceItem.php new file mode 100644 index 000000000..908096afd --- /dev/null +++ b/packages/Webkul/Sales/src/Models/InvoiceItem.php @@ -0,0 +1,41 @@ +belongsTo(InvoiceProxy::modelClass()); + } + + /** + * Get the order item record associated with the invoice item. + */ + public function order_item() + { + return $this->belongsTo(OrderItemProxy::modelClass()); + } + + /** + * Get the invoice record associated with the invoice item. + */ + public function product() + { + return $this->morphTo(); + } + + /** + * Get the child item record associated with the invoice item. + */ + public function child() + { + return $this->belongsTo(InvoiceItemProxy::modelClass(), 'parent_id'); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/InvoiceItemProxy.php b/packages/Webkul/Sales/src/Models/InvoiceItemProxy.php new file mode 100644 index 000000000..9d7dc640b --- /dev/null +++ b/packages/Webkul/Sales/src/Models/InvoiceItemProxy.php @@ -0,0 +1,10 @@ +hasMany(CartItemProxy::modelClass())->whereNull('parent_id'); + } + + /** + * Get the order shipments record associated with the order. + */ + public function shipments() { + return $this->hasMany(ShipmentProxy::modelClass()); + } + + /** + * Get the order invoices record associated with the order. + */ + public function invoices() { + return $this->hasMany(InvoiceProxy::modelClass()); + } + + /** + * Get the customer record associated with the order. + */ + public function customer() + { + return $this->morphTo(); + } + + /** + * Get the addresses for the order. + */ + public function addresses() + { + return $this->hasMany(OrderAddressProxy::modelClass()); + } + + /** + * Get the biling address for the order. + */ + public function billing_address() + { + return $this->addresses()->where('address_type', 'billing'); + } + + /** + * Get billing address for the order. + */ + public function getBillingAddressAttribute() + { + return $this->billing_address()->first(); + } + + /** + * Get the shipping address for the order. + */ + public function shipping_address() + { + return $this->addresses()->where('address_type', 'shipping'); + } + + /** + * Get shipping address for the order. + */ + public function getShippingAddressAttribute() + { + return $this->shipping_address()->first(); + } + + /** + * Get the channel record associated with the order. + */ + public function channel() + { + return $this->morphTo(); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderAddress.php b/packages/Webkul/Sales/src/Models/OrderAddress.php new file mode 100644 index 000000000..e34b97b0e --- /dev/null +++ b/packages/Webkul/Sales/src/Models/OrderAddress.php @@ -0,0 +1,28 @@ +first_name . ' ' . $this->last_name; + } + + /** + * Get the customer record associated with the order. + */ + public function customer() + { + return $this->belongsTo(Customer::class); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderAddressProxy.php b/packages/Webkul/Sales/src/Models/OrderAddressProxy.php new file mode 100644 index 000000000..5adb02378 --- /dev/null +++ b/packages/Webkul/Sales/src/Models/OrderAddressProxy.php @@ -0,0 +1,10 @@ +belongsTo(OrderProxy::modelClass()); + } + + /** + * Get the order record associated with the order item. + */ + public function product() + { + return $this->morphTo(); + } + + /** + * Get the child item record associated with the order item. + */ + public function child() + { + return $this->belongsTo(OrderItemProxy::modelClass(), 'parent_id'); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/OrderItemProxy.php b/packages/Webkul/Sales/src/Models/OrderItemProxy.php new file mode 100644 index 000000000..2a50233ff --- /dev/null +++ b/packages/Webkul/Sales/src/Models/OrderItemProxy.php @@ -0,0 +1,10 @@ +hasMany(ShipmentItemProxy::modelClass())->whereNull('parent_id'); + } + + /** + * Get the customer record associated with the shipment. + */ + public function customer() + { + return $this->morphTo(); + } + + /** + * Get the addresses for the shipment. + */ + public function addresses() + { + return $this->hasMany(OrderAddressProxy::modelClass()); + } + + /** + * Get the biling address for the shipment. + */ + public function billing_address() + { + return $this->addresses()->where('address_type', 'billing'); + } + + /** + * Get billing address for the shipment. + */ + public function getBillingAddressAttribute() + { + return $this->billing_address()->first(); + } + + /** + * Get the shipping address for the shipment. + */ + public function shipping_address() + { + return $this->addresses()->where('address_type', 'shipping'); + } + + /** + * Get shipping address for the shipment. + */ + public function getShippingAddressAttribute() + { + return $this->shipping_address()->first(); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/ShipmentItem.php b/packages/Webkul/Sales/src/Models/ShipmentItem.php new file mode 100644 index 000000000..2b849ee69 --- /dev/null +++ b/packages/Webkul/Sales/src/Models/ShipmentItem.php @@ -0,0 +1,41 @@ +belongsTo(ShipmentProxy::modelClass()); + } + + /** + * Get the order item record associated with the shipment item. + */ + public function order_item() + { + return $this->belongsTo(OrderItemProxy::modelClass()); + } + + /** + * Get the shipment record associated with the shipment item. + */ + public function product() + { + return $this->morphTo(); + } + + /** + * Get the child item record associated with the shipment item. + */ + public function child() + { + return $this->belongsTo(ShipmentItemProxy::modelClass(), 'parent_id'); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Models/ShipmentItemProxy.php b/packages/Webkul/Sales/src/Models/ShipmentItemProxy.php new file mode 100644 index 000000000..906cf7f08 --- /dev/null +++ b/packages/Webkul/Sales/src/Models/ShipmentItemProxy.php @@ -0,0 +1,10 @@ +loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + + $this->app->register(ModuleServiceProvider::class); } /** diff --git a/packages/Webkul/Sales/src/Repositories/InvoiceItemRepository.php b/packages/Webkul/Sales/src/Repositories/InvoiceItemRepository.php new file mode 100644 index 000000000..f8fb0fa2a --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/InvoiceItemRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class InvoiceItemRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\InvoiceItem'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php new file mode 100644 index 000000000..173305183 --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class InvoiceRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\Invoice'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/OrderAddressRepository.php b/packages/Webkul/Sales/src/Repositories/OrderAddressRepository.php new file mode 100644 index 000000000..99d41f932 --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/OrderAddressRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class OrderAddressRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\OrderAddress'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php b/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php new file mode 100644 index 000000000..d9cb23486 --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/OrderItemRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class OrderItemRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\OrderItem'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/OrderRepository.php b/packages/Webkul/Sales/src/Repositories/OrderRepository.php new file mode 100644 index 000000000..9c13d441d --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/OrderRepository.php @@ -0,0 +1,61 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class OrderRepository extends Repository +{ + /** + * OrderItemRepository object + * + * @var Object + */ + protected $orderItem; + + /** + * Create a new repository instance. + * + * @param Webkul\Sales\Repositories\OrderItemRepository $orderItem + * @return void + */ + public function __construct( + OrderItemRepository $orderItem, + App $app + ) + { + $this->orderItem = $orderItem; + + parent::__construct($app); + } + + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\Order'; + } + + /** + * @param array $data + * @return mixed + */ + public function create(array $data) + { + $order = $this->find(2); + + dd($order->customer); + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/ShipmentRepository.php b/packages/Webkul/Sales/src/Repositories/ShipmentRepository.php new file mode 100644 index 000000000..4bb2ccc56 --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/ShipmentRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class ShipmentRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\Shipment'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Sales/src/Repositories/ShipmenttemRepository.php b/packages/Webkul/Sales/src/Repositories/ShipmenttemRepository.php new file mode 100644 index 000000000..2e5428c65 --- /dev/null +++ b/packages/Webkul/Sales/src/Repositories/ShipmenttemRepository.php @@ -0,0 +1,27 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + +class ShipmentItemRepository extends Repository +{ + /** + * Specify Model class name + * + * @return Mixed + */ + + function model() + { + return 'Webkul\Sales\Contracts\ShipmentItem'; + } +} \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php similarity index 93% rename from packages/Webkul/Cart/src/Http/Controllers/CartController.php rename to packages/Webkul/Shop/src/Http/Controllers/CartController.php index 01a9f145f..16d38e87e 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -1,6 +1,6 @@ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) @@ -25,9 +22,7 @@ class CartController extends Controller { /** - * Protected Variables that - * holds instances of the - * repository classes. + * Protected Variables that holds instances of the repository classes. * * @param Array $_config * @param $cart diff --git a/packages/Webkul/Cart/src/Http/Controllers/CheckoutController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php similarity index 94% rename from packages/Webkul/Cart/src/Http/Controllers/CheckoutController.php rename to packages/Webkul/Shop/src/Http/Controllers/OnepageController.php index d9271ad56..b7009390a 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CheckoutController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php @@ -1,6 +1,6 @@ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CheckoutController extends Controller +class OnepageController extends Controller { /** * Contains route related configuration diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index 904b265f3..602020739 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -10,24 +10,24 @@ Route::group(['middleware' => ['web']], function () { 'view' => 'shop::products.index' ]); - Route::get('/checkout/cart', 'Webkul\Cart\Http\Controllers\CartController@index')->defaults('_config', [ + Route::get('/checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@index')->defaults('_config', [ 'view' => 'shop::checkout.cart.index' ])->name('shop.checkout.cart.index'); - Route::get('/checkout/onepage', 'Webkul\Cart\Http\Controllers\CheckoutController@index')->defaults('_config', [ + Route::get('/checkout/onepage', 'Webkul\Shop\Http\Controllers\OnepageController@index')->defaults('_config', [ 'view' => 'shop::checkout.onepage' ])->name('shop.checkout.onepage.index'); + Route::post('/checkout/save-address', 'Webkul\Shop\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address'); + + Route::post('/checkout/save-shipping', 'Webkul\Shop\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping'); + + Route::post('/checkout/save-payment', 'Webkul\Shop\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment'); + Route::get('test', 'Webkul\Cart\Http\Controllers\CartController@test'); Route::get('mtest', 'Webkul\Cart\Http\Controllers\CartController@mergeTest'); - Route::post('/checkout/save-address', 'Webkul\Cart\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address'); - - Route::post('/checkout/save-shipping', 'Webkul\Cart\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping'); - - Route::post('/checkout/save-payment', 'Webkul\Cart\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment'); - /* dummy routes ends here */ From fe0ffca9ee85b9520260d867be0aa6f5c9b5e40b Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Fri, 28 Sep 2018 18:25:48 +0530 Subject: [PATCH 3/5] Cart Module Almost Completed --- packages/Webkul/Cart/src/Cart.php | 454 +++++++++++------- .../src/Http/Controllers/CartController.php | 22 +- packages/Webkul/Shop/src/Http/routes.php | 8 + .../Shop/src/Resources/assets/sass/app.scss | 14 +- .../views/checkout/cart/index.blade.php | 104 ++-- .../Resources/views/products/view.blade.php | 5 +- .../view/configurable-options.blade.php | 2 +- public/themes/default/assets/css/shop.css | 19 +- 8 files changed, 390 insertions(+), 238 deletions(-) diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php index e1a07c11f..f481dc51f 100644 --- a/packages/Webkul/Cart/src/Cart.php +++ b/packages/Webkul/Cart/src/Cart.php @@ -82,80 +82,6 @@ class Cart { $this->product = $product; } - /** - * Create new cart instance with the current item added. - * - * @param integer $id - * @param array $data - * - * @return Response - */ - public function createNewCart($id, $data) - { - $itemData = $this->prepareItemData($id, $data); - - $cartData['channel_id'] = core()->getCurrentChannel()->id; - - // this will auto set the customer id for the cart instances if customer is authenticated - if(auth()->guard('customer')->check()) { - $cartData['customer_id'] = auth()->guard('customer')->user()->id; - - $cartData['is_guest'] = 0; - - $cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; - } - - $cartData['is_guest'] = 1; - - $cartData['items_count'] = 1; - - $cartData['items_qty'] = $data['quantity']; - - if($cart = $this->cart->create($cartData)) { - $itemData['parent']['cart_id'] = $cart->id; - - if ($data['is_configurable'] == "true") { - //parent product entry - $itemData['parent']['additional'] = json_encode($data); - if($parent = $this->cartItem->create($itemData['parent'])) { - - $itemData['child']['parent_id'] = $parent->id; - $itemData['child']['cart_id'] = $cart->id; - if($child = $this->cartItem->create($itemData['child'])) { - session()->put('cart', $cart); - - session()->flash('success', 'Item Added To Cart Successfully'); - - return redirect()->back(); - } - } - - // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); - $this->collectTotals(); - - $this->collectQuantities(); - - } else if($data['is_configurable'] == "false") { - if($result = $this->cartItem->create($itemData['parent'])) { - session()->put('cart', $cart); - - session()->flash('success', 'Item Added To Cart Successfully'); - - return redirect()->back(); - } - - // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); - $this->collectTotals(); - - $this->collectQuantities(); - } - } - - session()->flash('error', 'Some Error Occured'); - - return redirect()->back(); - } - /** * Prepare the other data for the product to be added. * @@ -234,6 +160,129 @@ class Cart { } } + /** + * Create new cart instance with the current item added. + * + * @param integer $id + * @param array $data + * + * @return Response + */ + public function createNewCart($id, $data) + { + $itemData = $this->prepareItemData($id, $data); + + $cartData['channel_id'] = core()->getCurrentChannel()->id; + + // this will auto set the customer id for the cart instances if customer is authenticated + if(auth()->guard('customer')->check()) { + $cartData['customer_id'] = auth()->guard('customer')->user()->id; + + $cartData['is_guest'] = 0; + + $cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; + } else { + $cartData['is_guest'] = 1; + } + + $cartData['items_count'] = 1; + + $cartData['items_qty'] = $data['quantity']; + + if($cart = $this->cart->create($cartData)) { + $itemData['parent']['cart_id'] = $cart->id; + + if ($data['is_configurable'] == "true") { + //parent product entry + $itemData['parent']['additional'] = json_encode($data); + if($parent = $this->cartItem->create($itemData['parent'])) { + + $itemData['child']['parent_id'] = $parent->id; + $itemData['child']['cart_id'] = $cart->id; + if($child = $this->cartItem->create($itemData['child'])) { + session()->put('cart', $cart); + + session()->flash('success', 'Item Added To Cart Successfully'); + + return redirect()->back(); + } + } + + // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); + $this->collectQuantities(); + + $this->collectTotals(); + } else if($data['is_configurable'] == "false") { + if($result = $this->cartItem->create($itemData['parent'])) { + session()->put('cart', $cart); + + session()->flash('success', 'Item Added To Cart Successfully'); + + return redirect()->back(); + } + + // $cart->update(['subtotal' => $itemData['parent']['price'], 'base_sub_total' => $itemData['parent']['price']]); + $this->collectQuantities(); + + $this->collectTotals(); + } + } + + session()->flash('error', 'Some Error Occured'); + + return redirect()->back(); + } + + /** + * Returns cart + * + * @return Mixed + */ + public function getCart() + { + if(!$cart = session()->get('cart')) + return false; + + return $this->cart->find($cart->id); + } + + /** + * Method to check if the product is available and its required quantity + * is available or not in the inventory sources. + * + * @param integer $id + * + * @return Array + */ + public function canAddOrUpdate($itemId, $quantity) + { + $item = $this->cartItem->findOneByField('id', $itemId); + + $inventories = $item->product->inventories; + + $inventory_sources = $item->product->inventory_sources; + + $totalQty = 0; + + foreach($inventory_sources as $inventory_source) { + if($inventory_source->status && $inventory_source->toArray()['pivot']['qty']) { + $totalQty = $totalQty + $inventory_source->toArray()['pivot']['qty']; + } + } + + if ($quantity < 1) { + session()->flash('warning', 'Cannot Add Or Update Lesser than 1'); + + return redirect()->back(); + } + + if($quantity < $totalQty) { + return true; + } else { + return false; + } + } + /** * Add Items in a cart with some cart and item details. * @@ -259,16 +308,24 @@ class Cart { $prevQty = $cartItem->quantity; $newQty = $data['quantity']; + $canBe = $this->canAddOrUpdate($cartItem->id, $prevQty + $newQty); + + if($canBe == false) { + session()->flash('warning', 'The requested quantity is not available, please try back later.'); + + return redirect()->back(); + } + $cartItem->update([ 'quantity' => $prevQty + $newQty, - 'total' => $parentPrice * ($prevQty + $newQty), - 'base_total' => $parentPrice * ($prevQty + $newQty) + 'total' => $cartItem->price * ($prevQty + $newQty), + 'base_total' => $cartItem->price * ($prevQty + $newQty) ]); - $this->collectTotals(); - $this->collectQuantities(); + $this->collectTotals(); + session()->flash('success', "Product Quantity Successfully Updated"); return redirect()->back(); @@ -284,16 +341,24 @@ class Cart { $prevQty = $parent->quantity; $newQty = $data['quantity']; + $canBe = $this->canAddOrUpdate($cartItem->child->id, $prevQty + $newQty); + + if($canBe == false) { + session()->flash('warning', 'The requested quantity is not available, please try back later.'); + + return redirect()->back(); + } + $parent->update([ 'quantity' => $prevQty + $newQty, 'total' => $parentPrice * ($prevQty + $newQty), 'base_total' => $parentPrice * ($prevQty + $newQty) ]); - $this->collectTotals(); - $this->collectQuantities(); + $this->collectTotals(); + session()->flash('success', "Product Quantity Successfully Updated"); return redirect()->back(); @@ -303,19 +368,23 @@ class Cart { } if($data['is_configurable'] == "true") { + $this->canAddOrUpdate($parent->child->id, $parent->quantity); + $parent = $cart->items()->create($itemData['parent']); $itemData['child']['parent_id'] = $parent->id; $cart->items()->create($itemData['child']); } else if($data['is_configurable'] == "false"){ + // $this->canAddOrUpdate($parent->id, $parent->quantity); + $parent = $cart->items()->create($itemData['parent']); } - $this->collectTotals(); - $this->collectQuantities(); + $this->collectTotals(); + session()->flash('success', 'Item Successfully Added To Cart'); return redirect()->back(); @@ -332,23 +401,96 @@ class Cart { } /** - * Use detach to remove the current product from cart tables + * Update the cart on + * cart checkout page + */ + public function update($itemIds) + { + if(session()->has('cart')) { + $cart = session()->get('cart'); + + $items = $cart->items; + + foreach($items as $item) { + foreach($itemIds['qty'] as $id => $quantity) { + if($id == $item->id) { + if($item->type == "configurable") { + $canBe = $this->canAddOrUpdate($item->child->id, $quantity); + } else { + $canBe = $this->canAddOrUpdate($id, $quantity); + } + + if($canBe == false) { + session()->flash('warning', 'The requested quantity is not available, please try back later.'); + + return redirect()->back(); + } + + $item->update(['quantity' => $quantity]); + } + } + } + + $items = $cart->items; + + session()->flash('success', 'Cart Updated Successfully'); + + return redirect()->back(); + } + } + + /** + * Remove the item from the cart * - * @param Integer $id * @return response */ - public function remove($id) + public function removeItem($itemId) { - $item = $this->cartItem->findOneByField('id', $id); + if(session()->has('cart')) { + $cart = session()->get('cart'); - dd($item); - if($item->parent_id != "null") { - $item->delete($id); - } else { - $parentItem = $item->child; + $items = $cart->items; - dd($parentItem, $item); + foreach($items as $item) { + if($item->id == $itemId) { + if($item->type == "configurable") { + $child = $item->child; + + //delete the child first + $result = $this->cartItem->delete($child->id); + if($result) + $result = $this->cartItem->delete($item->id); + + $this->collectQuantities(); + $this->collectTotals(); + } else if($item->type == "simple" && $item->parent_id == null){ + $result = $this->cartItem->delete($item->id); + + $this->collectQuantities(); + $this->collectTotals(); + } + } + } + $countItems = $this->cart->findOneByField('id', $cart->id)->items->count(); + + //delete the cart instance if no items are there + if($countItems == 0) { + $result = $this->cart->delete($cart->id); + + session()->forget('cart'); + } else { + session()->forget('cart'); + + session()->put('cart', $this->cart->findOneByField('id', $cart->id)); + } + + if ($result) { + session()->flash('sucess', 'Item Successfully Removed From Cart'); + } else { + session()->flash('error', 'Item Cannot Be Removed From Cart'); + } } + return redirect()->back(); } /** @@ -460,6 +602,28 @@ class Cart { return $cartPayment; } + /** + * Update Cart Quantities, Weight + * + * @return void + */ + public function collectQuantities() + { + if(!$cart = $this->getCart()) + return false; + + $quantities = 0; + + foreach($cart->items as $item) { + $quantities = $quantities + $item->quantity; + } + + $itemCount = $cart->items->count(); + + $cart->update(['items_count' => $itemCount, 'items_qty' => $quantities]); + + } + /** * Updates cart totals * @@ -493,27 +657,6 @@ class Cart { $cart->save(); } - /** - * Update Cart Quantities, Weight - * - * @return void - */ - public function collectQuantities() { - if(!$cart = $this->getCart()) - return false; - - $quantities = 0; - - foreach($cart->items as $item) { - $quantities = $quantities + $item->quantity; - } - - $itemCount = $cart->items->count(); - - $cart->update(['items_count' => $itemCount, 'items_qty' => $quantities]); - - } - /** * This function handles when guest has some of cart products and then logs in. * @@ -551,6 +694,14 @@ class Cart { $newQty = $guestCartItem->quantity; + $canBe = $this->canAddOrUpdate($cartItem->id, $prevQty + $newQty); + + if($canBe == false) { + session()->flash('warning', 'The requested quantity is not available, please try back later.'); + + return redirect()->back(); + } + $cartItem->update([ 'quantity' => $prevQty + $newQty, 'total' => $cartItem->price * ($prevQty + $newQty), @@ -560,7 +711,7 @@ class Cart { ]); $guestCartItems->forget($key); - $this->cartItem->delete($guestCart->id); + $this->cartItem->delete($guestCartItem->id); } } else if($guestCartItem->type == "configurable" && $cartItem->type == "configurable") { $guestCartItemChild = $guestCartItem->child; @@ -571,6 +722,14 @@ class Cart { $prevQty = $guestCartItem->quantity; $newQty = $cartItem->quantity; + $canBe = $this->canAddOrUpdate($cartItem->child->id, $prevQty + $newQty); + + if($canBe == false) { + session()->flash('warning', 'The requested quantity is not available, please try back later.'); + + return redirect()->back(); + } + $cartItem->update([ 'quantity' => $prevQty + $newQty, 'total' => $cartItem->price * ($prevQty + $newQty), @@ -585,7 +744,7 @@ class Cart { $this->cartItem->delete($guestCartItemChild->id); //then parent will get deleted - $this->cartItem->delete($guestCart->id); + $this->cartItem->delete($guestCartItem->id); } } } @@ -612,77 +771,16 @@ class Cart { //put the customer cart instance session()->put('cart', $cart); - $this->collectTotals(); - $this->collectQuantities(); + $this->collectTotals(); + return redirect()->back(); } else { return redirect()->back(); } } - /** - * Method to check if the product is available and its required quantity - * is available or not in the inventory sources. - * - * @param integer $id - * - * @return Array - */ - public function canCheckOut($productId, $quantity) - { - $items = $cart->items; - - $allProdQty = array(); - - $allProdQty1 = array(); - - $totalQty = 0; - - foreach($items as $item) { - $inventories = $item->product->inventories; - - $inventory_sources = $item->product->inventory_sources; - - $totalQty = 0; - - foreach($inventory_sources as $inventory_source) { - if($inventory_source->status!=0) { - foreach($inventories as $inventory) { - $totalQty = $totalQty + $inventory->qty; - } - - array_push($allProdQty1, $totalQty); - - $allProdQty[$item->product->id] = $totalQty; - } - } - } - - foreach ($items as $item) { - $inventories = $item->product->inventory_sources->where('status', '=', '1'); - - foreach($inventories as $inventory) { - dump($inventory->status); - } - } - dd([true, false]); - } - - /** - * Returns cart - * - * @return Mixed - */ - public function getCart() - { - if(!$cart = session()->get('cart')) - return false; - - return $this->cart->find($cart->id); - } - /** * Destroys the session * maintained for cart diff --git a/packages/Webkul/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Cart/src/Http/Controllers/CartController.php index c4f03f063..2aad9aaaa 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Cart/src/Http/Controllers/CartController.php @@ -105,8 +105,28 @@ class CartController extends Controller return redirect()->back(); } + /** + * Removes the item from + * the cart if it exists + * + * @param integer $itemId + */ public function remove($itemId) { - Cart::remove($itemId); + Cart::removeItem($itemId); + + return redirect()->back(); + } + + /** + * Updates the quantity of the + * items present in the cart. + * + * @return response + */ + public function updateBeforeCheckout() { + $data = request()->except('_token'); + + Cart::update($data); return redirect()->back(); } diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index e07372626..65e12566d 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -35,6 +35,14 @@ Route::group(['middleware' => ['web']], function () { Route::post('product/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add'); Route::get('product/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove'); + + Route::post('/checkout/cart', 'Webkul\Cart\Http\Controllers\CartController@updateBeforeCheckout')->defaults('_config',[ + 'redirect' => 'shop.checkout.cart.index' + ])->name('shop.checkout.cart.update'); + + Route::get('/checkout/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->defaults('_config',[ + 'redirect' => 'shop.checkout.cart.index' + ])->name('shop.checkout.cart.remove'); //Routes for product cart ends // Product Review routes diff --git a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss index e6723503e..97f608e66 100644 --- a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss +++ b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss @@ -17,6 +17,10 @@ body { font-family: "Montserrat", sans-serif; } +.btn.btn-primary{ + border-radius: 0px; +} + .header { margin-top: 16px; margin-bottom: 21px; @@ -1960,7 +1964,11 @@ section.cart { float: left; .misc-controls { - float: right; + width: 100%; + display: inline-flex; + align-items: center; + justify-content: space-between; + margin-top: 20px; a.link { @@ -2024,14 +2032,16 @@ section.cart { margin-right: 10px; } - div.box { + input.box { height: 38px; width: 60px; + font-size: 16px; text-align: center; line-height: 38px; border: 1px solid $border-color; border-radius: 3px; margin-right: 30px; + border-radius: 0px; } .remove { diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php index 7065900c3..18ae5c9e1 100644 --- a/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/cart/index.blade.php @@ -19,79 +19,79 @@
+
-
- @foreach($cart->items as $item) +
+ @csrf + @foreach($cart->items as $item) - product; + product; - $productBaseImage = $productImageHelper->getProductBaseImage($product); - ?> + $productBaseImage = $productImageHelper->getProductBaseImage($product); + ?> -
-
- -
- -
- -
- {{ $product->name }} +
+
+
-
- {{ core()->currency($item->base_price) }} -
+
- @if ($product->type == 'configurable') - -
- {{-- @foreach (cart::getItemAttributeOptionDetails($item) as $key => $option) - - {{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }} - - @endforeach --}} +
+ {{ $product->name }}
- @endif -
-
{{ __('shop::app.checkout.cart.quantity') }}
-
{{ $item->quantity }}
- @if($product->type == 'configurable') - {{ __('shop::app.checkout.cart.remove') }} - @else - {{ __('shop::app.checkout.cart.remove') }} +
+ {{ core()->currency($item->base_price) }} +
+ + @if ($product->type == 'configurable') + +
+ {{-- @foreach (cart::getItemAttributeOptionDetails($item) as $key => $option) + + {{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }} + + @endforeach --}} +
@endif - {{ __('shop::app.checkout.cart.move-to-wishlist') }} + +
+
{{ __('shop::app.checkout.cart.quantity') }}
+ {{--
{{ $item->quantity }}
--}} + + @{{ errors.first('quantity') }} + {{-- @if($product->type == 'configurable') + {{ __('shop::app.checkout.cart.remove') }} + @else --}} + {{ __('shop::app.checkout.cart.remove') }} + {{-- @endif --}} + {{ __('shop::app.checkout.cart.move-to-wishlist') }} +
+
+ @endforeach +
+ - - - +
+
- @include('shop::checkout.total.summary', ['cart' => $cart]) -
-
- @else -
{{ __('shop::app.checkout.cart.empty') }}
diff --git a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php index 8ff545cc2..521d467c0 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php @@ -35,9 +35,10 @@ {{ $product->short_description }}
-
+
- + + @{{ errors.first('quantity') }}
@if ($product->type == 'configurable') diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index 317e4c5ca..53e7d6939 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -27,7 +27,7 @@
- diff --git a/public/themes/default/assets/css/shop.css b/public/themes/default/assets/css/shop.css index c7ab7b824..18c6e0e45 100644 --- a/public/themes/default/assets/css/shop.css +++ b/public/themes/default/assets/css/shop.css @@ -81,6 +81,10 @@ body { font-family: "Montserrat", sans-serif; } +.btn.btn-primary { + border-radius: 0px; +} + .header { margin-top: 16px; margin-bottom: 21px; @@ -1983,7 +1987,16 @@ section.cart .cart-content .left-side { } section.cart .cart-content .left-side .misc-controls { - float: right; + width: 100%; + display: -webkit-inline-box; + display: -ms-inline-flexbox; + display: inline-flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: justify; + -ms-flex-pack: justify; + justify-content: space-between; margin-top: 20px; } @@ -2064,14 +2077,16 @@ section.cart .cart-content .right-side { margin-right: 10px; } -.cart-item-list .item .item-details .misc div.box { +.cart-item-list .item .item-details .misc input.box { height: 38px; width: 60px; + font-size: 16px; text-align: center; line-height: 38px; border: 1px solid #E8E8E8; border-radius: 3px; margin-right: 30px; + border-radius: 0px; } .cart-item-list .item .item-details .misc .remove { From 34833ff9958feca9504f657b13a1468a30039a37 Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Fri, 28 Sep 2018 18:58:54 +0530 Subject: [PATCH 4/5] Path Errors Fixed --- config/app.php | 2 +- packages/Webkul/Checkout/src/Cart.php | 16 ++++++++-------- .../src/Http/ViewComposers/CartComposer.php | 4 ++-- ...eProvider.php => CheckoutServiceProvider.php} | 4 ++-- .../Webkul/Shipping/src/Carriers/FlatRate.php | 2 +- packages/Webkul/Shipping/src/Carriers/Free.php | 2 +- packages/Webkul/Shipping/src/Shipping.php | 6 +++--- .../Shop/src/Http/Controllers/CartController.php | 6 +++--- .../src/Http/Controllers/OnepageController.php | 6 +++--- 9 files changed, 24 insertions(+), 24 deletions(-) rename packages/Webkul/Checkout/src/Providers/{CartServiceProvider.php => CheckoutServiceProvider.php} (95%) diff --git a/config/app.php b/config/app.php index a42f0875f..328d1a18f 100644 --- a/config/app.php +++ b/config/app.php @@ -189,7 +189,7 @@ return [ Webkul\Inventory\Providers\InventoryServiceProvider::class, Webkul\Product\Providers\ProductServiceProvider::class, Webkul\Theme\Providers\ThemeServiceProvider::class, - Webkul\Checkout\Providers\CartServiceProvider::class, + Webkul\Checkout\Providers\CheckoutServiceProvider::class, Webkul\Shipping\Providers\ShippingServiceProvider::class, Webkul\Payment\Providers\PaymentServiceProvider::class, Webkul\Sales\Providers\SalesServiceProvider::class, diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index f481dc51f..ec1c41953 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -1,14 +1,14 @@ loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $router->aliasMiddleware('admin', RedirectIfNotAdmin::class); diff --git a/packages/Webkul/Shipping/src/Carriers/FlatRate.php b/packages/Webkul/Shipping/src/Carriers/FlatRate.php index 715f11538..6f9e48953 100644 --- a/packages/Webkul/Shipping/src/Carriers/FlatRate.php +++ b/packages/Webkul/Shipping/src/Carriers/FlatRate.php @@ -3,7 +3,7 @@ namespace Webkul\Shipping\Carriers; use Config; -use Webkul\Cart\Models\CartShippingRate; +use Webkul\Checkout\Models\CartShippingRate; use Webkul\Shipping\Facades\Shipping; /** diff --git a/packages/Webkul/Shipping/src/Carriers/Free.php b/packages/Webkul/Shipping/src/Carriers/Free.php index 5ef07c928..784de27ba 100644 --- a/packages/Webkul/Shipping/src/Carriers/Free.php +++ b/packages/Webkul/Shipping/src/Carriers/Free.php @@ -3,7 +3,7 @@ namespace Webkul\Shipping\Carriers; use Config; -use Webkul\Cart\Models\CartShippingRate; +use Webkul\Checkout\Models\CartShippingRate; use Webkul\Shipping\Facades\Shipping; /** diff --git a/packages/Webkul/Shipping/src/Shipping.php b/packages/Webkul/Shipping/src/Shipping.php index fb8d06406..33f96fae7 100644 --- a/packages/Webkul/Shipping/src/Shipping.php +++ b/packages/Webkul/Shipping/src/Shipping.php @@ -3,7 +3,7 @@ namespace Webkul\Shipping; use Illuminate\Support\Facades\Config; -use Webkul\Cart\Facades\Cart; +use Webkul\Checkout\Facades\Cart; /** * Class Shipping. @@ -49,7 +49,7 @@ class Shipping 'html' => view('shop::checkout.onepage.shipping', ['shippingRateGroups' => $this->getGroupedAllShippingRates()])->render() ]; } - + /** * Persist shipping rate to database * @@ -64,7 +64,7 @@ class Shipping $rate->delete(); } } - + /** * Persist shipping rate to database * diff --git a/packages/Webkul/Shop/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php index 2aad9aaaa..537f8d112 100644 --- a/packages/Webkul/Shop/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -1,11 +1,11 @@ Date: Fri, 28 Sep 2018 19:44:54 +0530 Subject: [PATCH 5/5] Cart Bugs Fixes --- packages/Webkul/Checkout/src/Cart.php | 9 +++++---- packages/Webkul/Shipping/composer.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index ec1c41953..bf7306a77 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -332,8 +332,9 @@ class Cart { } } else if($data['is_configurable'] == "true") { if($cartItem->type == "configurable") { - if($cartItem->child->product_id == $data['selected_configurable_option']) { - $child = $cartItem->child; + $temp = $this->cartItem->findOneByField('parent_id', $cartItem->id); + if($temp->product_id == $data['selected_configurable_option']) { + $child = $temp->child; $parent = $cartItem; $parentPrice = $parent->price; @@ -368,12 +369,12 @@ class Cart { } if($data['is_configurable'] == "true") { - $this->canAddOrUpdate($parent->child->id, $parent->quantity); - $parent = $cart->items()->create($itemData['parent']); $itemData['child']['parent_id'] = $parent->id; + // $this->canAddOrUpdate($parent->child->id, $parent->quantity); + $cart->items()->create($itemData['child']); } else if($data['is_configurable'] == "false"){ // $this->canAddOrUpdate($parent->id, $parent->quantity); diff --git a/packages/Webkul/Shipping/composer.json b/packages/Webkul/Shipping/composer.json index 7e3676e4f..f894797bb 100644 --- a/packages/Webkul/Shipping/composer.json +++ b/packages/Webkul/Shipping/composer.json @@ -17,7 +17,7 @@ "extra": { "laravel": { "providers": [ - "Webkul\\Cart\\Providers\\ShippingServiceProvider" + "Webkul\\Shipping\\Providers\\ShippingServiceProvider" ], "aliases": {} }