From ac093c465bc5850dbc2896e6378ea36706bca30a Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Thu, 13 Sep 2018 16:36:17 +0530 Subject: [PATCH] Cart Module being modified accodrding to session --- composer.json | 8 +- config/app.php | 2 +- packages/Webkul/Cart/composer.json | 13 +- packages/Webkul/Cart/src/Cart.php | 343 +++++++++++++++++- packages/Webkul/Cart/src/Facades/Cart.php | 1 - .../src/Http/Controllers/CartController.php | 297 +-------------- .../src/Providers/CartServiceProvider.php | 27 +- .../Cart/src/Repositories/CartRepository.php | 30 ++ .../src/Providers/CoreServiceProvider.php | 2 +- packages/Webkul/Customer/composer.json | 2 +- .../Http/Controllers/SessionController.php | 15 +- .../Http/Listeners/CustomerEventsHandler.php | 7 +- packages/Webkul/Shop/composer.json | 5 +- packages/Webkul/Shop/src/Http/routes.php | 8 +- .../Shop/src/Resources/assets/sass/app.scss | 1 - .../src/Resources/views/home/index.blade.php | 2 +- .../Resources/views/products/view.blade.php | 4 +- .../views/products/view/gallery.blade.php | 2 + .../views/datagrid/table/default.blade.php | 1 - public/themes/default/assets/css/shop.css | 1 - 20 files changed, 438 insertions(+), 333 deletions(-) diff --git a/composer.json b/composer.json index 7d5185860..c3504fdef 100644 --- a/composer.json +++ b/composer.json @@ -33,12 +33,12 @@ "webkul/laravel-ui": "self.version", "webkul/laravel-core": "self.version", "webkul/laravel-attribute": "self.version", + "webkul/laravel-cart": "self.version", "webkul/laravel-customer": "self.version", "webkul/laravel-category": "self.version", "webkul/laravel-product": "self.version", "webkul/laravel-shop": "self.version", - "webkul/laravel-theme": "self.version", - "webkul/laravel-cart": "self.version" + "webkul/laravel-theme": "self.version" }, "autoload": { "classmap": [ @@ -51,14 +51,14 @@ "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\\Attribute\\": "packages/Webkul/Attribute/src", "Webkul\\Shop\\": "packages/Webkul/Shop/src", "Webkul\\Core\\": "packages/Webkul/Core/src", "Webkul\\Customer\\": "packages/Webkul/Customer/src", "Webkul\\Inventory\\": "packages/Webkul/Inventory/src", "Webkul\\Product\\": "packages/Webkul/Product/src", - "Webkul\\Theme\\": "packages/Webkul/Theme/src", - "Webkul\\Cart\\": "packages/Webkul/Cart/src" + "Webkul\\Theme\\": "packages/Webkul/Theme/src" } }, "autoload-dev": { diff --git a/config/app.php b/config/app.php index 2f57f8e5c..e4ce4cc51 100644 --- a/config/app.php +++ b/config/app.php @@ -180,7 +180,7 @@ return [ Webkul\User\Providers\UserServiceProvider::class, Webkul\Admin\Providers\AdminServiceProvider::class, Webkul\Ui\Providers\UiServiceProvider::class, - Webkul\Category\Providers\CategoryServiceProvider::class, + // Webkul\Category\Providers\CategoryServiceProvider::class, Webkul\Attribute\Providers\AttributeServiceProvider::class, Webkul\Core\Providers\CoreServiceProvider::class, Webkul\Shop\Providers\ShopServiceProvider::class, diff --git a/packages/Webkul/Cart/composer.json b/packages/Webkul/Cart/composer.json index 6422107ef..205719c18 100644 --- a/packages/Webkul/Cart/composer.json +++ b/packages/Webkul/Cart/composer.json @@ -3,13 +3,11 @@ "license": "MIT", "authors": [ { - "name": "Prashant", - "email": "prashant@webkul.com" + "name": "Prashant Singh", + "email": "prashant.singh852@webkul.com" } ], - "require": { - "webkul/laravel-core": "dev-master" - }, + "require": {}, "autoload": { "psr-4": { "Webkul\\Cart\\": "src/" @@ -18,9 +16,8 @@ "extra": { "laravel": { "providers": [ - "Webkul\\Cart\\Providers\\CartServiceProvider" - ], - "aliases": {} + "Webkul\\Cart\\CartServiceProvider" + ] } }, "minimum-stability": "dev" diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php index 318a81811..a2f0ed6be 100644 --- a/packages/Webkul/Cart/src/Cart.php +++ b/packages/Webkul/Cart/src/Cart.php @@ -4,23 +4,344 @@ namespace Webkul\Cart; use Carbon\Carbon; -use Webkul\Cart\Models\Cart as Cartmodel; -use Webkul\Cart\Models\CartProduct; +//Cart repositories +use Webkul\Cart\Repositories\CartRepository; +use Webkul\Cart\Repositories\CartProductRepository; -use Webkul\Core\Models\Channel as ChannelModel; -use Webkul\Core\Models\Locale as LocaleModel; -use Webkul\Core\Models\TaxCategory as TaxCategory; -use Webkul\Core\Models\TaxRate as TaxRate; +//Customer repositories +use Webkul\Customer\Repositories\CustomerRepository; -use Webkul\Customer\Models\Customer; use Cookie; +/** + * Cart facade for all + * the methods to be + * implemented for Cart. + * + * @author Prashant Singh + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ + class Cart { - public function getCart($id) { - dd('juice', $id); + + protected $_config; + + protected $cart; + + protected $cartProduct; + + protected $customer; + + public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer) { + + $this->customer = $customer; + + $this->cart = $cart; + + $this->cartProduct = $cartProduct; } - public function getProducts($id) { - dd('juice 1', $id); + public function guestUnitAdd($id) { + + $products = array(); + + $minutes = 10; + + // if(Session::get('current_session_id')) + + if(Cookie::has('session_c')) { + $products = unserialize(Cookie::get('session_c')); + + foreach($products as $key => $value) { + if($value == $id) { + dump($products); + + dd('product already in the cart'); + + return redirect()->back(); + } + } + array_push($products, $id); + + Cookie::queue('session_c', serialize($products)); + + return redirect()->back(); + + } else { + array_push($products, $id); + + Cookie::queue('session_c', serialize($products), $minutes); + + return redirect()->back(); + } + } + + /** + * Function for guests + * user to remove the product + * in the cart. + * + * @return Mixed + */ + public function guestUnitRemove($id) { + + //remove the products here + if(Cookie::has('session_c')) { + $products = unserialize(Cookie::get('session_c')); + + foreach($products as $key => $value) { + if($value == $id) { + unset($products[$key]); + + array_push($products, $id); + + Cookie::queue('session_c', serialize($products)); + + return redirect()->back(); + } + } + } + } + + /* + handle the after login event for the customers + when their are pruoducts in the session or cookie + of the logged in user. + */ + + public function add($id) { + + $products = array(); + + // $customerLoggedIn = auth()->guard('customer')->check(); + + // //customer is authenticated + // if ($customerLoggedIn) { + //assuming that there is data in cookie and customer's cart also. + + $data['customer_id'] = auth()->guard('customer')->user()->id; + + $data['channel_id'] = core()->getCurrentChannel()->id; + + $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']); + + //if there are products already in cart of that customer. + $customerCartId = $customerCart->id ?? $customerCart['id']; + + $customerCartProducts = $this->cart->getProducts($customerCartId); + + if (isset($customerCartProducts)) { + + foreach ($customerCartProducts as $previousCartProduct) { + + if($previousCartProduct->id == $id) { + dd('product already exists in cart'); + + session()->flash('error', 'Product already exists in cart'); + + return redirect()->back(); + } + } + //add the product in the cart + + $product['product_id'] = $id; + + $product['quantity'] = 1; + + $product['cart_id'] = $customerCartId; + + $this->cartProduct->create($product); + + return redirect()->back(); + } + // } + + // //case when cookie has products and customer also have data in cart tables + // if(isset($customerCart) && isset($cartCookie)) { + // //for unsetting the cookie for the cart uncomment after all done + // // Cookie::queue(Cookie::forget('session_c')); + + // //check if there is any repetition in the products + // $customerCartId = $customerCart->id ?? $customerCart['id']; + + // //to check if the customer is also having some products saved in the pivot + // //for the products. + // $customerCartProducts = $this->cart->getProducts($customerCartId); + + // //if there are products already in cart of that customer + // if(isset($customerCartProducts)) { + + // foreach($customerCartProducts as $previousCartProduct) { + + // dump($customerCartProducts); + + // foreach($cookieProducts as $key => $cookieProduct) { + + // if($previousCartProduct->id == $cookieProduct) { + + // unset($cookieProducts[$key]); + // } + // } + // } + // } + + // /*if the above block executes it will remove duplicates + // else product in cookies will be stored in the database.*/ + + // foreach($cookieProducts as $key => $cookieProduct) { + + // $product['product_id'] = $cookieProduct; + + // $product['quantity'] = 1; + + // $product['cart_id'] = $customerCartId; + + // $this->cartProduct->create($product); + // } + + // dump('Products in the cart synced.'); + + // return redirect()->back(); + + // } else if(isset($customerCart) && !isset($cartCookie)) { + // //case when there is no data in guest's cart + + // $customerCartId = $customerCart->id ?? $customerCart['id']; + + // $customerCartProducts = $this->cart->getProducts($customerCartId); + + // foreach($customerCartProducts as $previousCartProduct) { + + // if($previousCartProduct->id == $id) { + + // dd('product already in the cart::AUTH'); + + // return redirect()->back(); + // } + // } + // $product['product_id'] = $id; + + // $product['quantity'] = 1; + + // $product['cart_id'] = $customerCartId; + + // $this->cartProduct->create($product); + + // dump('new item added in the cart'); + + // return redirect()->back(); + + // } else if(!isset($customerCart) && isset($cartCookie)) { + + // $products = unserialize(Cookie::get('session_c')); + + // if ($cart = $this->cart->create($data)) { + + // foreach($products as $product) { + + // $product['product_id'] = $id; + + // $product['quantity'] = 1; + + // $product['cart_id'] = $cart; + + // $this->cartProduct->create($product); + // } + // return redirect()->back(); + + // } else { + // session()->flash('error', 'Cannot Add Your Items To Cart'); + + // return redirect()->back(); + // } + // } + // } + } + + /** + * use detach to remove the + * current product from cart tables + * + * @return Mixed + */ + public function remove($id) { + + dd("Removing Item from Cart"); + } + + /** + * Function to handle merge + * and sync the cookies products + * with the existing data of cart + * in the cart tables; + */ + public function handleMerge() { + + $productsInCookie = unserialize(Cookie::get('session_c')); + + $data['customer_id'] = auth()->guard('customer')->user()->id; + + $data['channel_id'] = core()->getCurrentChannel()->id; + + $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']); + + if(isset($customerCart)) { + + $customerCartId = $customerCart->id ?? $customerCart['id']; + + $customerCartProducts = $this->cart->getProducts($customerCartId); + + if(isset($customerCartProducts)) { + + foreach($customerCartProducts as $previousCartProduct) { + + foreach($productsInCookie as $key => $productInCookie) { + + if($previousCartProduct->id == $productInCookie) { + + unset($productsInCookie[$key]); + } + } + } + } + + /*if the above block executes it will remove duplicates + else product in cookies will be stored in the database.*/ + + foreach($productsInCookie as $key => $cookieProduct) { + + $product['product_id'] = $cookieProduct; + + $product['quantity'] = 1; + + $product['cart_id'] = $customerCartId; + + $this->cartProduct->create($product); + } + + //forget that cookie here. + Cookie::queue(Cookie::forget('session_c')); + } else { + + if($cart = $this->cart->create($data)) { + + foreach($productsInCookie as $productInCookie) { + + $product['product_id'] = $cookieProduct; + + $product['quantity'] = 1; + + $product['cart_id'] = $cart->id; + + $this->cartProduct->create($product); + } + } + //forget the Cookie + Cookie::queue(Cookie::forget('session_c')); + + return redirect()->back(); + } + + } } \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Facades/Cart.php b/packages/Webkul/Cart/src/Facades/Cart.php index b3ed2b68f..10481133b 100644 --- a/packages/Webkul/Cart/src/Facades/Cart.php +++ b/packages/Webkul/Cart/src/Facades/Cart.php @@ -2,7 +2,6 @@ namespace Webkul\Cart\Facades; -use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Facade; class Cart extends Facade diff --git a/packages/Webkul/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Cart/src/Http/Controllers/CartController.php index aa7c363fb..cbb144943 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Cart/src/Http/Controllers/CartController.php @@ -4,10 +4,15 @@ namespace Webkul\Cart\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; -// use Illuminate\Routing\Controller; -use Webkul\Cart\Repositories\CartRepository as Cart; -use Webkul\Cart\Repositories\CartProductRepository as cartProduct; + +//Cart repositories +use Webkul\Cart\Repositories\CartRepository; +use Webkul\Cart\Repositories\CartProductRepository; + +//Customer repositories use Webkul\Customer\Repositories\CustomerRepository; + +use Cart; use Cookie; /** @@ -35,8 +40,9 @@ class CartController extends Controller protected $customer; - public function __construct(Cart $cart, cartProduct $cartProduct, CustomerRepository $customer) { - $this->middleware('customer')->except(['guestUnitAdd', 'guestUnitRemove']); + public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer) { + + $this->middleware('customer')->except(['add', 'remove']); $this->customer = $customer; @@ -52,287 +58,22 @@ class CartController extends Controller * * @return Mixed */ - public function guestUnitAdd($id) { - //this will handle the products and the cart - //when the user is not logged in - - $products = array(); - - $minutes = 5; - if(Cookie::has('session_c')) { - $products = unserialize(Cookie::get('session_c')); - - foreach($products as $key => $value) { - if($value == $id) { - dump($products); - - dd('product already in the cart'); - - return redirect()->back(); - } - } - array_push($products, $id); - - Cookie::queue('session_c', serialize($products)); - - return redirect()->back(); - - } else { - array_push($products, $id); - - Cookie::queue('session_c', serialize($products), $minutes); - - // dump($products); - - return redirect()->back(); - } - } - - /** - * Function for guests - * user to remove the product - * in the cart. - * - * @return Mixed - */ - public function guestUnitRemove($id) { - - //remove the products here - if(Cookie::has('session_c')) { - $products = unserialize(Cookie::get('session_c')); - - foreach($products as $key => $value) { - if($value == $id) { - unset($products[$key]); - - array_push($products, $id); - - Cookie::queue('session_c', serialize($products)); - - return redirect()->back(); - } - } - } - } - - /*handle the after login event for the customers - when their are pruoducts in the session or cookie - of the logged in user.*/ public function add($id) { - $products = array(); - - $customerLoggedIn = auth()->guard('customer')->check(); - - //customer is authenticated - if ($customerLoggedIn) { - //assuming that there is data in cookie and customer's cart also. - - $data['customer_id'] = auth()->guard('customer')->user()->id; - - $data['channel_id'] = core()->getCurrentChannel()->id; - - $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']); - - //if there are products already in cart of that customer. - $customerCartId = $customerCart->id ?? $customerCart['id']; - - $customerCartProducts = $this->cart->withProducts($customerCartId); - - if (isset($customerCartProducts)) { - - foreach ($customerCartProducts as $previousCartProduct) { - - if($previousCartProduct->id == $id) { - dd('product already exists in cart'); - - session()->flash('error', 'Product already exists in cart'); - - return redirect()->back(); - } - } - //add the product in the cart - - $product['product_id'] = $id; - - $product['quantity'] = 1; - - $product['cart_id'] = $customerCartId; - - $this->cartProduct->create($product); - - return redirect()->back(); - } + if(auth()->guard('customer')->check()) { + Cart::add($id); + } else { + Cart::guestUnitAdd($id); } - - // //case when cookie has products and customer also have data in cart tables - // if(isset($customerCart) && isset($cartCookie)) { - // //for unsetting the cookie for the cart uncomment after all done - // // Cookie::queue(Cookie::forget('session_c')); - - // //check if there is any repetition in the products - // $customerCartId = $customerCart->id ?? $customerCart['id']; - - // //to check if the customer is also having some products saved in the pivot - // //for the products. - // $customerCartProducts = $this->cart->withProducts($customerCartId); - - // //if there are products already in cart of that customer - // if(isset($customerCartProducts)) { - - // foreach($customerCartProducts as $previousCartProduct) { - - // dump($customerCartProducts); - - // foreach($cookieProducts as $key => $cookieProduct) { - - // if($previousCartProduct->id == $cookieProduct) { - - // unset($cookieProducts[$key]); - // } - // } - // } - // } - - // /*if the above block executes it will remove duplicates - // else product in cookies will be stored in the database.*/ - - // foreach($cookieProducts as $key => $cookieProduct) { - - // $product['product_id'] = $cookieProduct; - - // $product['quantity'] = 1; - - // $product['cart_id'] = $customerCartId; - - // $this->cartProduct->create($product); - // } - - // dump('Products in the cart synced.'); - - // return redirect()->back(); - - // } else if(isset($customerCart) && !isset($cartCookie)) { - // //case when there is no data in guest's cart - - // $customerCartId = $customerCart->id ?? $customerCart['id']; - - // $customerCartProducts = $this->cart->withProducts($customerCartId); - - // foreach($customerCartProducts as $previousCartProduct) { - - // if($previousCartProduct->id == $id) { - - // dd('product already in the cart::AUTH'); - - // return redirect()->back(); - // } - // } - // $product['product_id'] = $id; - - // $product['quantity'] = 1; - - // $product['cart_id'] = $customerCartId; - - // $this->cartProduct->create($product); - - // dump('new item added in the cart'); - - // return redirect()->back(); - - // } else if(!isset($customerCart) && isset($cartCookie)) { - - // $products = unserialize(Cookie::get('session_c')); - - // if ($cart = $this->cart->create($data)) { - - // foreach($products as $product) { - - // $product['product_id'] = $id; - - // $product['quantity'] = 1; - - // $product['cart_id'] = $cart; - - // $this->cartProduct->create($product); - // } - // return redirect()->back(); - - // } else { - // session()->flash('error', 'Cannot Add Your Items To Cart'); - - // return redirect()->back(); - // } - // } - // } } - /** - * use detach to remove the - * current product from cart tables - * - * @return Mixed - */ public function remove($id) { - dd("Removing Item from Cart"); - } - - /** - * Function to handle merge - * and sync the cookies products - * with the existing data of cart - * in the cart tables; - */ - public function handleMerge() { - // dd(unserialize(Cookie::get('session_c'))); - if(Cookie::has('session_c')) { - $productInCookies = unserialize(Cookie::get('session_c')); - - $data['customer_id'] = auth()->guard('customer')->user()->id; - - $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']); - - $customerCartId = $customerCart->id ?? $customerCart['id']; - - $customerCartProducts = $this->cart->withProducts($customerCartId); - - if(isset($customerCartProducts)) { - - foreach($customerCartProducts as $previousCartProduct) { - - dump($customerCartProducts); - - foreach($productInCookies as $key => $productInCookie) { - - if($previousCartProduct->id == $productInCookie) { - - unset($cookieProducts[$key]); - } - } - } - } - - /*if the above block executes it will remove duplicates - else product in cookies will be stored in the database.*/ - - foreach($cookieProducts as $key => $cookieProduct) { - - $product['product_id'] = $cookieProduct; - - $product['quantity'] = 1; - - $product['cart_id'] = $customerCartId; - - $this->cartProduct->create($product); - } - - //forget that cookie here. - - dump('Products in the cart synced.'); - - return redirect()->back(); + if(auth()->guard('customer')->check()) { + Cart::remove($id); + } else { + Cart::guestUnitRemove($id); } } } \ No newline at end of file diff --git a/packages/Webkul/Cart/src/Providers/CartServiceProvider.php b/packages/Webkul/Cart/src/Providers/CartServiceProvider.php index 20c8fb1a9..5efe208dd 100644 --- a/packages/Webkul/Cart/src/Providers/CartServiceProvider.php +++ b/packages/Webkul/Cart/src/Providers/CartServiceProvider.php @@ -3,12 +3,16 @@ namespace Webkul\Cart\Providers; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Facades\Validator; use Illuminate\Routing\Router; -use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer; +use Illuminate\Foundation\AliasLoader; use Webkul\User\Http\Middleware\RedirectIfNotAdmin; +use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer; +use Webkul\Cart\Facades\Cart; class CartServiceProvider extends ServiceProvider { + public function boot(Router $router) { $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); @@ -27,7 +31,24 @@ class CartServiceProvider extends ServiceProvider */ public function register() { - // $this->app->bind('datagrid', 'Webkul\Ui\DataGrid\DataGrid'); - $this->app->bind('Cart', 'Webkul\Cart\Cart'); + $this->registerFacades(); + } + + /** + * Register Bouncer as a singleton. + * + * @return void + */ + protected function registerFacades() + { + $loader = AliasLoader::getInstance(); + + $loader->alias('cart', Cart::class); + + $this->app->singleton('cart', function () { + return new cart(); + }); + + $this->app->bind('cart', 'Webkul\Cart\Cart'); } } diff --git a/packages/Webkul/Cart/src/Repositories/CartRepository.php b/packages/Webkul/Cart/src/Repositories/CartRepository.php index 5554c3bdd..d75299717 100644 --- a/packages/Webkul/Cart/src/Repositories/CartRepository.php +++ b/packages/Webkul/Cart/src/Repositories/CartRepository.php @@ -56,4 +56,34 @@ class CartRepository extends Repository return $this->model->find($id)->with_products; } + + /** + * Method to attach + * associations + * + * @return mixed + */ + // public function onlyAttach($id, $taxRates) { + + // foreach($taxRates as $key => $value) { + + // $this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]); + // } + // } + + + /** + * Method to detach + * and attach the + * associations + * + * @return mixed + */ + // public function syncAndDetach($id, $taxRates) { + // $this->model->findOrFail($id)->tax_rates()->detach(); + + // foreach($taxRates as $key => $value) { + // $this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]); + // } + // } } \ No newline at end of file diff --git a/packages/Webkul/Core/src/Providers/CoreServiceProvider.php b/packages/Webkul/Core/src/Providers/CoreServiceProvider.php index e5ab890d2..c1b7ad57a 100644 --- a/packages/Webkul/Core/src/Providers/CoreServiceProvider.php +++ b/packages/Webkul/Core/src/Providers/CoreServiceProvider.php @@ -10,7 +10,7 @@ use Webkul\Core\Http\Middleware\Locale; use Webkul\User\Http\Middleware\RedirectIfNotAdmin; use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer; use Webkul\Core\Core; -use Webkul\Core\Facades\CoreFacade; +use Webkul\Core\Facades\Core as CoreFacade; class CoreServiceProvider extends ServiceProvider { diff --git a/packages/Webkul/Customer/composer.json b/packages/Webkul/Customer/composer.json index e64b60909..f8d4e3ceb 100644 --- a/packages/Webkul/Customer/composer.json +++ b/packages/Webkul/Customer/composer.json @@ -4,7 +4,7 @@ "license": "MIT", "authors": [ { - "name": "prashant-webkul", + "name": "Prashant Singh", "email": "prashant.singh852@webkul.com" } ], diff --git a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php index e74475b78..d3017ed64 100644 --- a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php @@ -4,11 +4,13 @@ namespace Webkul\Customer\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Event; + use Webkul\Customer\Models\Customer; use Webkul\Customer\Http\Listeners\CustomerEventsHandler; -use Illuminate\Support\Facades\Event; -use Cookie; +use Cookie; +use Cart; /** * Session controller for the user customer * @@ -60,11 +62,10 @@ class SessionController extends Controller } //Event passed to prepare cart after login - if(Cookie::has('session_c')) { - Event::fire('customer.after.login', $request->input('email')); - } else { - return redirect()->intended(route($this->_config['redirect'])); - } + + Event::fire('customer.after.login', $request->input('email')); + + return redirect()->intended(route($this->_config['redirect'])); } public function destroy($id) diff --git a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php index cd90709f1..d4b4e26b1 100644 --- a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php +++ b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php @@ -27,12 +27,7 @@ class CustomerEventsHandler { * check emptiness and then * do the appropriate actions. */ - Cart::getCart(1); - // return redirect()->route('cart.merge'); - // if(Cookie::has('session_c')) { - - // } - + Cart::handleMerge(); } /** diff --git a/packages/Webkul/Shop/composer.json b/packages/Webkul/Shop/composer.json index 87d40e3be..65367dc28 100644 --- a/packages/Webkul/Shop/composer.json +++ b/packages/Webkul/Shop/composer.json @@ -1,10 +1,11 @@ { "name": "webkul/laravel-shop", "license": "MIT", + "description" : "Shop package for store front and customers", "authors": [ { - "name": "Prashant", - "email": "prashant@webkul.com" + "name": "Prashant Singh", + "email": "prashant.singh852@webkul.com" } ], "require": {}, diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php index bc525dd9d..df232d060 100644 --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Http/routes.php @@ -16,13 +16,13 @@ Route::group(['middleware' => ['web']], function () { // //Routes for product cart - Route::post('products/guest/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@guestUnitAdd')->name('cart.guest.add'); + Route::post('products/guest/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add'); - Route::post('product/guest/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@guestUnitRemove')->name('cart.guest.remove'); + Route::post('product/guest/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove'); - Route::post('product/customer/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.customer.add'); + // Route::post('product/customer/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.customer.add'); - Route::post('product/customer/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.customer.remove'); + // Route::post('product/customer/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.customer.remove'); Route::get('product/customer/cart/merge', 'Webkul\Cart\Http\Controllers\CartController@handleMerge')->name('cart.merge'); diff --git a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss index 68afef5af..81ee07b89 100644 --- a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss +++ b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss @@ -127,7 +127,6 @@ body { .header-top { margin-bottom: 16px; display: flex; - max-width: 80%; width: 100%; margin-left: auto; margin-right: auto; diff --git a/packages/Webkul/Shop/src/Resources/views/home/index.blade.php b/packages/Webkul/Shop/src/Resources/views/home/index.blade.php index 1b87d248e..0a895c627 100644 --- a/packages/Webkul/Shop/src/Resources/views/home/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/home/index.blade.php @@ -8,6 +8,6 @@ @include('shop::home.featured-products') @include('shop::home.new-products') - + @include('shop::home.news-updates') @endsection diff --git a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php index e9d22bd4a..ba51d2941 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php @@ -8,8 +8,8 @@
- -
+ {{ dd(session()->getId()) }} + @csrf() diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/gallery.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/gallery.blade.php index 0a8465c1d..7004fbdaf 100644 --- a/packages/Webkul/Shop/src/Resources/views/products/view/gallery.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/gallery.blade.php @@ -21,11 +21,13 @@ + {{--
--}} + {{-- {{ dd(unserialize(Cookie::get('session_c'))) }} --}}
diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php index fb97d7ea2..238172b70 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php @@ -21,7 +21,6 @@