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..328d1a18f 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\CheckoutServiceProvider::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/Cart.php b/packages/Webkul/Cart/src/Cart.php deleted file mode 100644 index e2d810f48..000000000 --- a/packages/Webkul/Cart/src/Cart.php +++ /dev/null @@ -1,650 +0,0 @@ - - * @author Jitendra Singh - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -class Cart { - - /** - * CartRepository model - * - * @var mixed - */ - protected $cart; - - /** - * CartItemRepository model - * - * @var mixed - */ - protected $cartItem; - - /** - * CustomerRepository model - * - * @var mixed - */ - protected $customer; - - /** - * CartAddressRepository model - * - * @var mixed - */ - protected $cartAddress; - - /** - * ProductRepository model - * - * @var mixed - */ - protected $product; - - /** - * Create a new controller instance. - * - * @param Webkul\Cart\Repositories\CartRepository $cart - * @param Webkul\Cart\Repositories\CartItemRepository $cartItem - * @param Webkul\Cart\Repositories\CartAddressRepository $cartAddress - * @param Webkul\Customer\Repositories\CustomerRepository $customer - * @param Webkul\Product\Repositories\ProductRepository $product - * @return void - */ - public function __construct( - CartRepository $cart, - CartItemRepository $cartItem, - CartAddressRepository $cartAddress, - CustomerRepository $customer, - ProductRepository $product) - { - $this->customer = $customer; - - $this->cart = $cart; - - $this->cartItem = $cartItem; - - $this->cartAddress = $cartAddress; - - $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. - * - * @param integer $id - * @param array $data - * - * @return Response - */ - public function createNewCart($id, $data) - { - $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['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; - } - - $cartData['items_count'] = 1; - - $cartData['items_quantity'] = $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; - if($child = $this->cartItem->create($itemData['child'])) { - session()->put('cart', $cart); - - session()->flash('success', 'Item Added To Cart Successfully'); - - return redirect()->back(); - } - } - - } 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(); - } - } - } - - session()->flash('error', 'Some Error Occured'); - - return redirect()->back(); - } - - /** - * Prepare the other data for the product to be added. - * - * @param integer $id - * @param array $data - * - * @return array - */ - public function prepareItemData($productId, $data) - { - $product = $this->product->findOneByField('id', $productId); - - unset($data['_token']); - - //Check if the product is salable - 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(); - } - } - - if($product->type == 'configurable') { - //Check if the product is salable - $child = $this->product->findOneByField('id', $data['selected_configurable_option']); - - $parentData = [ - 'sku' => $product->sku, - 'product_id' => $productId, - 'quantity' => $data['quantity'], - 'type' => 'configurable', - 'name' => $product->name, - 'price' => ($price = $child->price), //This shoulf final price - 'base_price' => $price, - 'item_total' => $price * $data['quantity'], - 'base_item_total' => $price * $data['quantity'], - 'weight' => ($weight = $child->weight), - 'item_weight' => $weight * $parentData['quantity'], - 'base_item_weight' => $weight * $parentData['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; - - return ['parent' => $parentData, 'child' => $childData]; - } else { - $data['product_id'] = $productId; - unset($data['product']); - - $data['type'] = 'simple'; - - $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]; - } - } - - /** - * Add Items in a cart with some cart and item details. - * - * @param @id - * @param $data - * - * @return void - */ - public function add($id, $data) - { - // session()->forget('cart'); - - // return redirect()->back(); - - $itemData = $this->prepareItemData($id, $data); - - if(session()->has('cart')) { - $cart = session()->get('cart'); - - $cartItems = $cart->items()->get(); - - if(isset($cartItems)) { - foreach($cartItems as $cartItem) { - if($data['is_configurable'] == "false") { - - if($cartItem->product_id == $id) { - $prevQty = $cartItem->quantity; - - $newQty = $data['quantity']; - - $cartItem->update(['quantity' => $prevQty + $newQty]); - - session()->flash('success', "Product Quantity Successfully Updated"); - - return redirect()->back(); - } - } else if($data['is_configurable'] == "true") { - - //check the parent and child records that holds info abt this product. - if($cartItem->product_id == $data['selected_configurable_option']) { - $child = $cartItem; - - $parentId = $child->parent_id; - - $parent = $this->cartItem->findOneByField('id', $parentId); - - $parentPrice = $parent->price; - - $prevQty = $parent->quantity; - - $newQty = $data['quantity']; - - $parent->update(['quantity' => $prevQty + $newQty, 'item_total' => $parentPrice * ($prevQty + $newQty)]); - - session()->flash('success', "Product Quantity Successfully Updated"); - - return redirect()->back(); - } - } - } - - $parent = $cart->items()->create($itemData['parent']); - - $itemData['child']['parent_id'] = $parent->id; - - $cart->items()->create($itemData['child']); - - session()->flash('success', 'Item Successfully Added To Cart'); - - return redirect()->back(); - } else { - if(isset($cart)) { - $this->cart->delete($cart->id); - } else { - $this->createNewCart($id, $data); - } - } - } else { - $this->createNewCart($id, $data); - } - } - - /** - * Use detach to remove the current product from cart tables - * - * @param Integer $id - * @return Mixed - */ - public function remove($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(); - } - } else { - return redirect()->back(); - } - } - - /** - * 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 - * - * @return Mixed - */ - public function getItemAttributeOptionDetails($item) - { - $data = []; - - 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, - ]; - } - - return $data; - } - - /** - * Save customer address - * - * @return Mixed - */ - public function saveCustomerAddress($data) - { - if(!$cart = $this->getCart()) - return false; - - $billingAddress = $data['billing']; - $shippingAddress = $data['shipping']; - $billingAddress['cart_id'] = $shippingAddress['cart_id'] = $cart->id; - - if($billingAddressModel = $cart->biling_address) { - $this->cartAddress->update($billingAddress, $billingAddressModel->id); - - if($shippingAddress = $cart->shipping_address) { - if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { - $this->cartAddress->update($billingAddress, $shippingAddress->id); - } else { - $this->cartAddress->update($shippingAddress, $shippingAddress->id); - } - } else { - if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { - $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'shipping'])); - } else { - $this->cartAddress->create(array_merge($shippingAddress, ['address_type' => 'shipping'])); - } - } - } else { - $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'billing'])); - - if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { - $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'shipping'])); - } else { - $this->cartAddress->create(array_merge($shippingAddress, ['address_type' => 'shipping'])); - } - } - - return true; - } - - /** - * Save shipping method for cart - * - * @param string $shippingMethodCode - * @return Mixed - */ - public function saveShippingMethod($shippingMethodCode) - { - if(!$cart = $this->getCart()) - return false; - - $cart->shipping_method = $shippingMethodCode; - $cart->save(); - - // foreach($cart->shipping_rates as $rate) { - // if($rate->method != $shippingMethodCode) { - // $rate->delete(); - // } - // } - - return true; - } - - /** - * Save payment method for cart - * - * @param string $payment - * @return Mixed - */ - public function savePaymentMethod($payment) - { - if(!$cart = $this->getCart()) - return false; - - if($cartPayment = $cart->payment) - $cartPayment->delete(); - - $cartPayment = new CartPayment; - - $cartPayment->method = $payment['method']; - $cartPayment->cart_id = $cart->id; - $cartPayment->save(); - - return $cartPayment; - } - - /** - * Updates cart totals - * - * @return void - */ - public function collectTotals() - { - if(!$cart = $this->getCart()) - return false; - - $cart->grand_total = 0; - $cart->base_grand_total = 0; - $cart->sub_total = 0; - $cart->base_sub_total = 0; - $cart->sub_total_with_discount = 0; - $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->sub_total = (float) $cart->sub_total + $item->price; - $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_price; - } - - if($shipping = $cart->selected_shipping_rate) { - $cart->grand_total = (float) $cart->grand_total + $shipping->price; - $cart->base_grand_total = (float) $cart->base_grand_total + $shipping->base_price; - } - - $cart->save(); - } -} \ No newline at end of file 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 @@ -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 phone record associated with the user. - */ - public function child() - { - return $this->belongsTo(self::class, 'parent_id'); - } -} diff --git a/packages/Webkul/Cart/.gitignore b/packages/Webkul/Checkout/.gitignore similarity index 100% rename from packages/Webkul/Cart/.gitignore rename to packages/Webkul/Checkout/.gitignore diff --git a/packages/Webkul/Cart/composer.json b/packages/Webkul/Checkout/composer.json similarity index 71% rename from packages/Webkul/Cart/composer.json rename to packages/Webkul/Checkout/composer.json index 205719c18..a89da709c 100644 --- a/packages/Webkul/Cart/composer.json +++ b/packages/Webkul/Checkout/composer.json @@ -1,5 +1,5 @@ { - "name": "webkul/laravel-cart", + "name": "webkul/laravel-checkout", "license": "MIT", "authors": [ { @@ -10,13 +10,13 @@ "require": {}, "autoload": { "psr-4": { - "Webkul\\Cart\\": "src/" + "Webkul\\Checkout\\": "src/" } }, "extra": { "laravel": { "providers": [ - "Webkul\\Cart\\CartServiceProvider" + "Webkul\\Checkout\\CheckoutServiceProvider" ] } }, diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php new file mode 100644 index 000000000..bf7306a77 --- /dev/null +++ b/packages/Webkul/Checkout/src/Cart.php @@ -0,0 +1,802 @@ + + * @author Jitendra Singh + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class Cart { + + /** + * CartRepository model + * + * @var mixed + */ + protected $cart; + + /** + * CartItemRepository model + * + * @var mixed + */ + protected $cartItem; + + /** + * CustomerRepository model + * + * @var mixed + */ + protected $customer; + + /** + * CartAddressRepository model + * + * @var mixed + */ + protected $cartAddress; + + /** + * ProductRepository model + * + * @var mixed + */ + protected $product; + + /** + * Create a new controller instance. + * + * @param Webkul\Checkout\Repositories\CartRepository $cart + * @param Webkul\Checkout\Repositories\CartItemRepository $cartItem + * @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress + * @param Webkul\Customer\Repositories\CustomerRepository $customer + * @param Webkul\Product\Repositories\ProductRepository $product + * @return void + */ + public function __construct( + CartRepository $cart, + CartItemRepository $cartItem, + CartAddressRepository $cartAddress, + CustomerRepository $customer, + ProductRepository $product) + { + $this->customer = $customer; + + $this->cart = $cart; + + $this->cartItem = $cartItem; + + $this->cartAddress = $cartAddress; + + $this->product = $product; + } + + /** + * Prepare the other data for the product to be added. + * + * @param integer $id + * @param array $data + * + * @return array + */ + public function prepareItemData($productId, $data) + { + $product = $this->product->findOneByField('id', $productId); + + unset($data['_token']); + + //Check if the product is salable + if(!isset($data['product']) ||!isset($data['quantity'])) { + session()->flash('error', 'Cart System Integrity Violation, Some Required Fields Missing.'); + + 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.'); + + return redirect()->back(); + } + } + + if($product->type == 'configurable') { + //Check if the product is salable + $child = $this->product->findOneByField('id', $data['selected_configurable_option']); + + $parentData = [ + 'sku' => $product->sku, + 'product_id' => $productId, + 'quantity' => $data['quantity'], + 'type' => 'configurable', + 'name' => $product->name, + 'price' => ($price = $child->price), //This should be price from the price helper + 'base_price' => $price, + 'total' => $price * $data['quantity'], + 'base_total' => $price * $data['quantity'], + 'weight' => ($weight = $child->weight), + 'total_weight' => $weight * $data['quantity'], + 'base_total_weight' => $weight * $data['quantity'], + ]; + + //child row data + $childData = [ + 'product_id' => $data['selected_configurable_option'], + 'quantity' => 1, + 'sku' => $child->sku, + 'type' => $child->type, + 'name' => $child->name + ]; + + return ['parent' => $parentData, 'child' => $childData]; + } else { + $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'], + ]; + + // dd(['parent' => $parentData, 'child' => null]); + + return ['parent' => $parentData, 'child' => null]; + } + } + + /** + * 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. + * + * @param @id + * @param $data + * + * @return void + */ + public function add($id, $data) + { + $itemData = $this->prepareItemData($id, $data); + + if(session()->has('cart')) { + $cart = session()->get('cart'); + + $cartItems = $cart->items()->get(); + + if(isset($cartItems)) { + foreach($cartItems as $cartItem) { + if($data['is_configurable'] == "false") { + + if($cartItem->product_id == $id) { + $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' => $cartItem->price * ($prevQty + $newQty), + 'base_total' => $cartItem->price * ($prevQty + $newQty) + ]); + + $this->collectQuantities(); + + $this->collectTotals(); + + session()->flash('success', "Product Quantity Successfully Updated"); + + return redirect()->back(); + } + } else if($data['is_configurable'] == "true") { + if($cartItem->type == "configurable") { + $temp = $this->cartItem->findOneByField('parent_id', $cartItem->id); + if($temp->product_id == $data['selected_configurable_option']) { + $child = $temp->child; + + $parent = $cartItem; + $parentPrice = $parent->price; + + $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->collectQuantities(); + + $this->collectTotals(); + + session()->flash('success', "Product Quantity Successfully Updated"); + + return redirect()->back(); + } + } + } + } + + if($data['is_configurable'] == "true") { + $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); + + $parent = $cart->items()->create($itemData['parent']); + } + + $this->collectQuantities(); + + $this->collectTotals(); + + session()->flash('success', 'Item Successfully Added To Cart'); + + return redirect()->back(); + } else { + if(isset($cart)) { + $this->cart->delete($cart->id); + } else { + $this->createNewCart($id, $data); + } + } + } else { + $this->createNewCart($id, $data); + } + } + + /** + * 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 + * + * @return response + */ + public function removeItem($itemId) + { + if(session()->has('cart')) { + $cart = session()->get('cart'); + + $items = $cart->items; + + 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(); + } + + /** + * Returns cart + * + * @return Mixed + */ + public function getItemAttributeOptionDetails($item) + { + $data = []; + + 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, + ]; + } + + return $data; + } + + /** + * Save customer address + * + * @return Mixed + */ + public function saveCustomerAddress($data) + { + if(!$cart = $this->getCart()) + return false; + + $billingAddress = $data['billing']; + $shippingAddress = $data['shipping']; + $billingAddress['cart_id'] = $shippingAddress['cart_id'] = $cart->id; + + if($billingAddressModel = $cart->biling_address) { + $this->cartAddress->update($billingAddress, $billingAddressModel->id); + + if($shippingAddress = $cart->shipping_address) { + if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { + $this->cartAddress->update($billingAddress, $shippingAddress->id); + } else { + $this->cartAddress->update($shippingAddress, $shippingAddress->id); + } + } else { + if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { + $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'shipping'])); + } else { + $this->cartAddress->create(array_merge($shippingAddress, ['address_type' => 'shipping'])); + } + } + } else { + $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'billing'])); + + if(isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) { + $this->cartAddress->create(array_merge($billingAddress, ['address_type' => 'shipping'])); + } else { + $this->cartAddress->create(array_merge($shippingAddress, ['address_type' => 'shipping'])); + } + } + + return true; + } + + /** + * Save shipping method for cart + * + * @param string $shippingMethodCode + * @return Mixed + */ + public function saveShippingMethod($shippingMethodCode) + { + if(!$cart = $this->getCart()) + return false; + + $cart->shipping_method = $shippingMethodCode; + $cart->save(); + + // foreach($cart->shipping_rates as $rate) { + // if($rate->method != $shippingMethodCode) { + // $rate->delete(); + // } + // } + + return true; + } + + /** + * Save payment method for cart + * + * @param string $payment + * @return Mixed + */ + public function savePaymentMethod($payment) + { + if(!$cart = $this->getCart()) + return false; + + if($cartPayment = $cart->payment) + $cartPayment->delete(); + + $cartPayment = new CartPayment; + + $cartPayment->method = $payment['method']; + $cartPayment->cart_id = $cart->id; + $cartPayment->save(); + + 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 + * + * @return void + */ + public function collectTotals() + { + if(!$cart = $this->getCart()) + return false; + + $cart->grand_total = 0; + $cart->base_grand_total = 0; + $cart->sub_total = 0; + $cart->base_sub_total = 0; + $cart->sub_total_with_discount = 0; + $cart->base_sub_total_with_discount = 0; + + foreach ($cart->items()->get() as $item) { + $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 * $item->quantity; + $cart->base_sub_total = (float) $cart->base_sub_total + $item->base_price * $item->quantity; + } + + if($shipping = $cart->selected_shipping_rate) { + $cart->grand_total = (float) $cart->grand_total + $shipping->price; + $cart->base_grand_total = (float) $cart->base_grand_total + $shipping->base_price; + } + + $cart->save(); + } + + /** + * 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; + + $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), + '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($guestCartItem->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; + + $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), + '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($guestCartItem->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->collectQuantities(); + + $this->collectTotals(); + + return redirect()->back(); + } else { + return redirect()->back(); + } + } + + /** + * 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_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..99ab8d31c 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,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/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 @@ hasMany(CartItem::class)->whereNull('parent_id'); } + public function all_items() { + return $this->hasMany(CartItem::class); + } + /** * Get the addresses for the cart. */ @@ -38,7 +42,7 @@ class Cart extends Model } /** - * Get all of the attributes for the attribute groups. + * Get billing address for the cart. */ public function getBillingAddressAttribute() { @@ -54,7 +58,7 @@ class Cart extends Model } /** - * Get all of the attributes for the attribute groups. + * Get shipping address for the cart. */ public function getShippingAddressAttribute() { diff --git a/packages/Webkul/Cart/src/Models/CartAddress.php b/packages/Webkul/Checkout/src/Models/CartAddress.php similarity index 89% rename from packages/Webkul/Cart/src/Models/CartAddress.php rename to packages/Webkul/Checkout/src/Models/CartAddress.php index 935b09eb0..6af3f6a8f 100644 --- a/packages/Webkul/Cart/src/Models/CartAddress.php +++ b/packages/Webkul/Checkout/src/Models/CartAddress.php @@ -1,9 +1,9 @@ hasOne('Webkul\Product\Models\Product', 'id', 'product_id'); + } + + // /** + // * Get the parent item + // */ + // public function parent() + // { + // return $this->hasOne(self::class, 'parent_id', 'id'); + // } + + /** + * Get the child item. + */ + public function child() + { + return $this->belongsTo(self::class, 'id', 'parent_id'); + } +} diff --git a/packages/Webkul/Cart/src/Models/CartPayment.php b/packages/Webkul/Checkout/src/Models/CartPayment.php similarity index 77% rename from packages/Webkul/Cart/src/Models/CartPayment.php rename to packages/Webkul/Checkout/src/Models/CartPayment.php index 1d0487e40..3fd158615 100644 --- a/packages/Webkul/Cart/src/Models/CartPayment.php +++ b/packages/Webkul/Checkout/src/Models/CartPayment.php @@ -1,6 +1,6 @@ loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $router->aliasMiddleware('admin', RedirectIfNotAdmin::class); @@ -55,6 +55,6 @@ class CartServiceProvider extends ServiceProvider return new cart(); }); - $this->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 @@ listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin'); diff --git a/packages/Webkul/Sales/composer.json b/packages/Webkul/Sales/composer.json index 96628ca1c..ec9b362a3 100644 --- a/packages/Webkul/Sales/composer.json +++ b/packages/Webkul/Sales/composer.json @@ -7,7 +7,9 @@ "email": "jitendra@webkul.com" } ], - "require": {}, + "require": { + "konekt/concord": "^1.2" + }, "autoload": { "psr-4": { "Webkul\\Sales\\": "src/" diff --git a/packages/Webkul/Sales/src/Contracts/Invoice.php b/packages/Webkul/Sales/src/Contracts/Invoice.php new file mode 100644 index 000000000..8f900a272 --- /dev/null +++ b/packages/Webkul/Sales/src/Contracts/Invoice.php @@ -0,0 +1,7 @@ +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/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": {} } 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/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Shop/src/Http/Controllers/CartController.php similarity index 62% rename from packages/Webkul/Cart/src/Http/Controllers/CartController.php rename to packages/Webkul/Shop/src/Http/Controllers/CartController.php index 01a9f145f..537f8d112 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/CartController.php @@ -1,11 +1,11 @@ _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,32 @@ class CartController extends Controller return redirect()->back(); } - public function remove($id) { + /** + * Removes the item from + * the cart if it exists + * + * @param integer $itemId + */ + public function remove($itemId) { + Cart::removeItem($itemId); - if(auth()->guard('customer')->check()) { - Cart::remove($id); - } else { - Cart::guestUnitRemove($id); - } + 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(); } 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/Http/Controllers/CheckoutController.php b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php similarity index 88% rename from packages/Webkul/Cart/src/Http/Controllers/CheckoutController.php rename to packages/Webkul/Shop/src/Http/Controllers/OnepageController.php index d9271ad56..3d8a45707 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CheckoutController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php @@ -1,23 +1,22 @@ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class CheckoutController extends Controller +class OnepageController extends Controller { /** * Contains route related configuration @@ -52,7 +51,7 @@ class CheckoutController extends Controller /** * Saves customer address. * - * @param \Webkul\Cart\Http\Requests\CustomerAddressForm $request + * @param \Webkul\Checkout\Http\Requests\CustomerAddressForm $request * @return \Illuminate\Http\Response */ public function saveAddress(CustomerAddressForm $request) diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index 904b265f3..d4f7abe6f 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -10,37 +10,47 @@ 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::get('test', 'Webkul\Cart\Http\Controllers\CartController@test'); + Route::post('/checkout/save-address', 'Webkul\Shop\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address'); - Route::get('mtest', 'Webkul\Cart\Http\Controllers\CartController@mergeTest'); + Route::post('/checkout/save-shipping', 'Webkul\Shop\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping'); - Route::post('/checkout/save-address', 'Webkul\Cart\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address'); + Route::post('/checkout/save-payment', 'Webkul\Shop\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment'); - Route::post('/checkout/save-shipping', 'Webkul\Cart\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping'); + Route::get('test', 'Webkul\Shop\Http\Controllers\CartController@test'); - Route::post('/checkout/save-payment', 'Webkul\Cart\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment'); - - /* dummy routes ends here */ + Route::get('mtest', 'Webkul\Shop\Http\Controllers\CartController@mergeTest'); + //dummy + Route::get('test', 'Webkul\Shop\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\Shop\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('product/cart/add/{id}', 'Webkul\Shop\Http\Controllers\CartController@add')->name('cart.add'); - Route::post('checkout/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove'); + Route::get('product/cart/remove/{id}', 'Webkul\Shop\Http\Controllers\CartController@remove')->name('cart.remove'); + Route::post('/checkout/cart', 'Webkul\Shop\Http\Controllers\CartController@updateBeforeCheckout')->defaults('_config',[ + 'redirect' => 'shop.checkout.cart.index' + ])->name('shop.checkout.cart.update'); + + Route::get('/checkout/cart/remove/{id}', 'Webkul\Shop\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 1498b0b69..b6d994808 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; @@ -1749,7 +1753,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 { @@ -1813,14 +1821,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/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..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,80 +19,84 @@
+
-
- @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 -
-
Quantity
-
{{ $item->quantity }}
- Remove - Move to Wishlist +
+ {{ 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.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') }}
@endif - + @endsection \ No newline at end of file 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 ce67c3c5c..b35f5cf70 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 45a439e25..c431917d7 100644 --- a/public/themes/default/assets/css/shop.css +++ b/public/themes/default/assets/css/shop.css @@ -87,6 +87,10 @@ body { font-family: "Montserrat", sans-serif; } +.btn.btn-primary { + border-radius: 0px; +} + .header { margin-top: 16px; margin-bottom: 21px; @@ -1788,7 +1792,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; } @@ -1869,14 +1882,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 {