Merge branch 'prashant' of https://github.com/bagisto/bagisto into rahul
This commit is contained in:
commit
00b31edd81
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -1,650 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Webkul\Cart\Repositories\CartRepository;
|
||||
use Webkul\Cart\Repositories\CartItemRepository;
|
||||
use Webkul\Cart\Repositories\CartAddressRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Cart\Models\CartPayment;
|
||||
use Cookie;
|
||||
|
||||
/**
|
||||
* Facade for all the methods to be implemented in Cart.
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class CartItem extends Model
|
||||
{
|
||||
protected $table = 'cart_items';
|
||||
|
||||
protected $fillable = ['product_id', 'quantity', 'cart_id', 'sku', 'type', 'name', 'parent_id','tax_category_id', 'coupon_code', 'weight', 'item_total_weight', 'base_item_total_weight', 'price', 'item_total', 'item_total_with_discount', 'base_item_total_with_discount', 'base_price', 'custom_price', 'discount_percent', 'discount_amount', 'base_discount_amount', 'no_discount', 'free_shipping', 'additional'];
|
||||
|
||||
public function product() {
|
||||
return $this->hasOne('Webkul\Product\Models\Product', 'id', 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phone record associated with the user.
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the phone record associated with the user.
|
||||
*/
|
||||
public function child()
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -0,0 +1,802 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Checkout;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\Checkout\Repositories\CartAddressRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Checkout\Models\CartPayment;
|
||||
|
||||
/**
|
||||
* Facade for all the methods to be implemented in Cart.
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Facades;
|
||||
namespace Webkul\Checkout\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Requests;
|
||||
namespace Webkul\Checkout\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\ViewComposers;
|
||||
namespace Webkul\Checkout\Http\ViewComposers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use Webkul\Cart\Repositories\CartRepository;
|
||||
use Webkul\Cart\Repositories\CartItemRepository;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
|
||||
//Product Image Helper Class
|
||||
use Webkul\Product\Product\ProductImage;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
use Webkul\Cart\Cart;
|
||||
use Webkul\Checkout\Cart;
|
||||
|
||||
if (! function_exists('cart')) {
|
||||
function cart()
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
namespace Webkul\Checkout\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Product\Models\Product;
|
||||
use Webkul\Cart\Models\CartItem;
|
||||
use Webkul\Cart\Models\CartAddress;
|
||||
use Webkul\Cart\Models\CartPayment;
|
||||
use Webkul\Cart\Models\CartShippingRate;
|
||||
use Webkul\Checkout\Models\CartItem;
|
||||
use Webkul\Checkout\Models\CartAddress;
|
||||
use Webkul\Checkout\Models\CartPayment;
|
||||
use Webkul\Checkout\Models\CartShippingRate;
|
||||
|
||||
class Cart extends Model
|
||||
{
|
||||
|
|
@ -21,6 +21,10 @@ class Cart extends Model
|
|||
return $this->hasMany(CartItem::class)->whereNull('parent_id');
|
||||
}
|
||||
|
||||
public function all_items() {
|
||||
return $this->hasMany(CartItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the addresses for the cart.
|
||||
*/
|
||||
|
|
@ -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()
|
||||
{
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
namespace Webkul\Checkout\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Cart\Models\CartShippingRate;
|
||||
use Webkul\Checkout\Models\CartShippingRate;
|
||||
|
||||
class CartAddress extends Model
|
||||
{
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Checkout\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
class CartItem extends Model
|
||||
{
|
||||
protected $table = 'cart_items';
|
||||
|
||||
protected $fillable = ['product_id', 'quantity', 'cart_id', 'sku', 'type', 'name', 'parent_id','tax_category_id', 'coupon_code', 'weight', 'total_weight', 'base_total_weight', 'price', 'total', 'base_total', 'total_with_discount', 'base_total_with_discount', 'base_price', 'custom_price', 'discount_percent', 'discount_amount', 'base_discount_amount', 'no_discount', 'free_shipping', 'additional'];
|
||||
|
||||
public function product() {
|
||||
return $this->hasOne('Webkul\Product\Models\Product', 'id', 'product_id');
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the 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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
namespace Webkul\Checkout\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
namespace Webkul\Checkout\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Cart\Models\CartAddress;
|
||||
use Webkul\Checkout\Models\CartAddress;
|
||||
|
||||
class CartShippingRate extends Model
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Providers;
|
||||
namespace Webkul\Checkout\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
|
@ -8,10 +8,10 @@ use Illuminate\Routing\Router;
|
|||
use Illuminate\Foundation\AliasLoader;
|
||||
use Webkul\User\Http\Middleware\RedirectIfNotAdmin;
|
||||
use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer;
|
||||
use Webkul\Cart\Facades\Cart;
|
||||
use Webkul\Cart\Providers\ComposerServiceProvider;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
use Webkul\Checkout\Providers\ComposerServiceProvider;
|
||||
|
||||
class CartServiceProvider extends ServiceProvider
|
||||
class CheckoutServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
public function boot(Router $router)
|
||||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Providers;
|
||||
namespace Webkul\Checkout\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
|
|
@ -17,7 +17,7 @@ class ComposerServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
//using the class based composers...
|
||||
View::composer(['shop::layouts.header.index'], 'Webkul\Cart\Http\ViewComposers\CartComposer');
|
||||
View::composer(['shop::layouts.header.index'], 'Webkul\Checkout\Http\ViewComposers\CartComposer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Repositories;
|
||||
namespace Webkul\Checkout\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
|
|
@ -20,6 +20,6 @@ class CartAddressRepository extends Repository
|
|||
*/
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\Cart\Models\CartAddress';
|
||||
return 'Webkul\Checkout\Models\CartAddress';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Repositories;
|
||||
namespace Webkul\Checkout\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class CartItemRepository extends Repository
|
|||
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\Cart\Models\CartItem';
|
||||
return 'Webkul\Checkout\Models\CartItem';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Repositories;
|
||||
namespace Webkul\Checkout\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class CartRepository extends Repository
|
|||
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\Cart\Models\Cart';
|
||||
return 'Webkul\Checkout\Models\Cart';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -30,8 +30,9 @@ class CustomerEventsHandler {
|
|||
Cart::mergeCart();
|
||||
}
|
||||
|
||||
//use this when there is very uttermost need to use it.
|
||||
public function onCustomerLogout($event) {
|
||||
//Customer Logout Event Handler.
|
||||
public function onCustomerLogout($event)
|
||||
{
|
||||
Cart::destroyCart();
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +40,8 @@ class CustomerEventsHandler {
|
|||
* Register the listeners for the subscriber.
|
||||
*
|
||||
* @param Illuminate\Events\Dispatcher $events
|
||||
* @return void */
|
||||
|
||||
* @return void
|
||||
*/
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin');
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@
|
|||
"email": "jitendra@webkul.com"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
"require": {
|
||||
"konekt/concord": "^1.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webkul\\Sales\\": "src/"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface Invoice
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface InvoiceItem
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface Order
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface OrderAddress
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface OrderItem
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface Shipment
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Contracts;
|
||||
|
||||
interface ShipmentItem
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('orders', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateOrderItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('order_items', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateOrderAddressTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('order_address', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateShipmentsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('shipments', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateShipmentItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('shipment_items', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('invoices', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateInvoiceItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('invoice_items', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\Invoice as InvoiceContract;
|
||||
|
||||
class Invoice extends Model implements InvoiceContract
|
||||
{
|
||||
/**
|
||||
* Get the invoice items record associated with the invoice.
|
||||
*/
|
||||
public function items() {
|
||||
return $this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\InvoiceItem as InvoiceItemContract;
|
||||
|
||||
class InvoiceItem extends Model implements InvoiceItemContract
|
||||
{
|
||||
/**
|
||||
* Get the invoice record associated with the invoice item.
|
||||
*/
|
||||
public function invoice()
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class InvoiceItemProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class InvoiceProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\Order as OrderContract;
|
||||
|
||||
class Order extends Model implements OrderContract
|
||||
{
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Get the order items record associated with the order.
|
||||
*/
|
||||
public function items() {
|
||||
return $this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\OrderAddress as OrderAddressContract;
|
||||
use Webkul\Customer\Models\Customer;
|
||||
|
||||
class OrderAddress extends Model implements OrderAddressContract
|
||||
{
|
||||
protected $table = 'order_address';
|
||||
|
||||
/**
|
||||
* Get of the customer fullname.
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->first_name . ' ' . $this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the customer record associated with the order.
|
||||
*/
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class OrderAddressProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\OrderItem as OrderItemContract;
|
||||
|
||||
class OrderItem extends Model implements OrderItemContract
|
||||
{
|
||||
/**
|
||||
* Get the order record associated with the order item.
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class OrderItemProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class OrderProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\Shipment as ShipmentContract;
|
||||
|
||||
class Shipment extends Model implements ShipmentContract
|
||||
{
|
||||
/**
|
||||
* Get the shipment items record associated with the shipment.
|
||||
*/
|
||||
public function items() {
|
||||
return $this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Sales\Contracts\ShipmentItem as ShipmentItemContract;
|
||||
|
||||
class ShipmentItem extends Model implements ShipmentItemContract
|
||||
{
|
||||
/**
|
||||
* Get the shipment record associated with the shipment item.
|
||||
*/
|
||||
public function shipment()
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class ShipmentItemProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class ShipmentProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Providers;
|
||||
|
||||
use Konekt\Concord\BaseModuleServiceProvider;
|
||||
|
||||
class ModuleServiceProvider extends BaseModuleServiceProvider
|
||||
{
|
||||
protected $models = [
|
||||
\Webkul\Sales\Models\OrderAddress::class,
|
||||
\Webkul\Sales\Models\Order::class,
|
||||
\Webkul\Sales\Models\OrderItem::class,
|
||||
\Webkul\Sales\Models\Invoice::class,
|
||||
\Webkul\Sales\Models\InvoiceItem::class,
|
||||
\Webkul\Sales\Models\Shipment::class,
|
||||
\Webkul\Sales\Models\ShipmentItem::class,
|
||||
];
|
||||
}
|
||||
|
|
@ -3,16 +3,16 @@
|
|||
namespace Webkul\Sales\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Webkul\Sales\Providers\ModuleServiceProvider;
|
||||
|
||||
class SalesServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
||||
|
||||
$this->app->register(ModuleServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Invoice Item Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Invoice Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Order Address Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* OrderItem Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Order Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Shipment Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Sales\Repositories;
|
||||
|
||||
use Illuminate\Container\Container as App;
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* ShipmentItem Reposotory
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Webkul\\Cart\\Providers\\ShippingServiceProvider"
|
||||
"Webkul\\Shipping\\Providers\\ShippingServiceProvider"
|
||||
],
|
||||
"aliases": {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace Webkul\Shipping;
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Webkul\Cart\Facades\Cart;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
|
||||
/**
|
||||
* Class Shipping.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Controllers;
|
||||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Cart\Repositories\CartRepository;
|
||||
use Webkul\Cart\Repositories\CartItemRepository;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Product\Product\ProductImage;
|
||||
|
|
@ -85,6 +85,7 @@ class CartController extends Controller
|
|||
* @return Mixed
|
||||
*/
|
||||
public function index() {
|
||||
// dd(Cart::getCart());
|
||||
return view($this->_config['view'])->with('cart', Cart::getCart());
|
||||
}
|
||||
|
||||
|
|
@ -97,10 +98,6 @@ class CartController extends Controller
|
|||
*/
|
||||
|
||||
public function add($id) {
|
||||
// session()->forget('cart');
|
||||
|
||||
// return redirect()->back();
|
||||
|
||||
$data = request()->input();
|
||||
|
||||
Cart::add($id, $data);
|
||||
|
|
@ -108,46 +105,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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Controllers;
|
||||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Auth;
|
||||
use Webkul\Cart\Facades\Cart;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
use Webkul\Shipping\Facades\Shipping;
|
||||
use Webkul\Payment\Facades\Payment;
|
||||
use Webkul\Cart\Http\Requests\CustomerAddressForm;
|
||||
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
|
||||
|
||||
/**
|
||||
* Chekout controller for the customer
|
||||
* and guest for placing order
|
||||
* Chekout controller for the customer and guest for placing order
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @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)
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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' => [
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@
|
|||
<div class="cart-content">
|
||||
|
||||
<div class="left-side">
|
||||
<form action="{{ route('shop.checkout.cart.update') }}" method="POST">
|
||||
|
||||
<div class="cart-item-list" style="margin-top: 0">
|
||||
@csrf
|
||||
@foreach($cart->items as $item)
|
||||
|
||||
<?php
|
||||
|
|
@ -47,47 +49,49 @@
|
|||
@if ($product->type == 'configurable')
|
||||
|
||||
<div class="summary">
|
||||
@foreach (cart()->getItemAttributeOptionDetails($item) as $key => $option)
|
||||
{{-- @foreach (cart::getItemAttributeOptionDetails($item) as $key => $option)
|
||||
|
||||
{{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }}
|
||||
|
||||
@endforeach
|
||||
@endforeach --}}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="misc">
|
||||
<div class="qty-text">Quantity</div>
|
||||
<div class="box">{{ $item->quantity }}</div>
|
||||
<span class="remove">Remove</span>
|
||||
<span class="towishlist">Move to Wishlist</span>
|
||||
<div class="qty-text">{{ __('shop::app.checkout.cart.quantity') }}</div>
|
||||
{{-- <div class="box">{{ $item->quantity }}</div> --}}
|
||||
<input class="box" type="text" v-validate="'required|numeric|min_value:1'" name="qty[{{$item->id}}]" value="{{ $item->quantity }}">
|
||||
<span class="control-error" v-if="errors.has('qty[{{$item->qty}}]')">@{{ errors.first('quantity') }}</span>
|
||||
{{-- @if($product->type == 'configurable')
|
||||
<span class="remove"><a href="{{ route('shop.checkout.cart.remove', $item->child->id) }}">{{ __('shop::app.checkout.cart.remove') }}</a></span>
|
||||
@else --}}
|
||||
<span class="remove"><a href="{{ route('shop.checkout.cart.remove', $item->id) }}">{{ __('shop::app.checkout.cart.remove') }}</a></span>
|
||||
{{-- @endif --}}
|
||||
<span class="towishlist">{{ __('shop::app.checkout.cart.move-to-wishlist') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="misc-controls">
|
||||
<a href="{{ route('shop.home.index') }}" class="link">{{ __('shop::app.checkout.cart.continue-shopping') }}</a>
|
||||
|
||||
<div>
|
||||
<input type="submit" class="btn btn-lg btn-primary" value="Update Cart" />
|
||||
<a href="{{ route('shop.checkout.onepage.index') }}" class="btn btn-lg btn-primary">
|
||||
{{ __('shop::app.checkout.cart.proceed-to-checkout') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="right-side">
|
||||
|
||||
@include('shop::checkout.total.summary', ['cart' => $cart])
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@else
|
||||
|
||||
<div class="title">
|
||||
{{ __('shop::app.checkout.cart.empty') }}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -35,9 +35,10 @@
|
|||
{{ $product->short_description }}
|
||||
</div>
|
||||
|
||||
<div class="quantity control-group">
|
||||
<div class="quantity control-group" :class="[errors.has('quantity') ? 'has-error' : '']">
|
||||
<label class="reqiured">Quantity</label>
|
||||
<input name="quantity" class="control" value="1" v-validate="'numeric'" required style="width: 60px;">
|
||||
<input name="quantity" class="control" value="1" v-validate="'required|numeric|min_value:1'" style="width: 60px;">
|
||||
<span class="control-error" v-if="errors.has('quantity')">@{{ errors.first('quantity') }}</span>
|
||||
</div>
|
||||
|
||||
@if ($product->type == 'configurable')
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
<div v-for='(attribute, index) in childAttributes' class="attribute control-group" :class="[errors.has('super_attribute[' + attribute.id + ']') ? 'has-error' : '']">
|
||||
<label class="reqiured">@{{ attribute.label }}</label>
|
||||
|
||||
<select v-validate="'required'" class="control" :name="['super_attribute[' + attribute.id + ']']" :disabled="attribute.disabled" @change="configure(attribute, $event.target.value)" :id="['attribute_' + attribute.id]" required>
|
||||
<select v-validate="'required'" class="control" :name="['super_attribute[' + attribute.id + ']']" :disabled="attribute.disabled" @change="configure(attribute, $event.target.value)" :id="['attribute_' + attribute.id]">
|
||||
|
||||
<option v-for='(option, index) in attribute.options' :value="option.id">@{{ option.label }}</option>
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue