diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 706c00313..64e2c2f45 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -3,7 +3,6 @@
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
-use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
@@ -14,7 +13,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
- Schema::defaultStringLength(191);
}
/**
diff --git a/config/database.php b/config/database.php
index cab5d068f..e486bd20d 100644
--- a/config/database.php
+++ b/config/database.php
@@ -51,7 +51,7 @@ return [
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
- 'engine' => null,
+ 'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
],
'pgsql' => [
diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php
index 0d9342e41..a580a8789 100644
--- a/packages/Webkul/Cart/src/Cart.php
+++ b/packages/Webkul/Cart/src/Cart.php
@@ -32,57 +32,186 @@ class Cart {
protected $customer;
- public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer) {
+ //Cookie expiry limit in minutes
+ protected $minutes = 150;
+
+ public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer ,$minutes = 150) {
$this->customer = $customer;
$this->cart = $cart;
$this->cartProduct = $cartProduct;
+
+ $this->minutes = $minutes;
}
public function guestUnitAdd($id) {
+ //empty array for storing the products
$products = array();
- $minutes = 10;
-
- if(Cookie::get('current_session_id')) {
+ if(Cookie::has('cart_session_id')) {
+ //getting the cart session id from cookie
$cart_session_id = Cookie::get('cart_session_id');
- $cart = $this->cart->getOneByField('session_id'. $cart_session_id);
+ //finding current cart instance in the database table.
+ $current_cart = $this->cart->findOneByField('session_id', $cart_session_id);
- $cartId = $cart->id ?? $cart['id'] ;
+ //check there is any cart or not
+ if(isset($current_cart)) {
+ $current_cart_id = $current_cart['id'] ?? $current_cart->id;
- $products = $this->getProducts($id);
-
- foreach($products as $key => $value) {
- if($value == $id) {
- dd('product already in the cart');
-
- return redirect()->back();
- }
+ $current_cart_session_id = $current_cart['session_id'] ?? $current_cart->session_id;
+ } else {
+ //if someone deleted then take the flow to the normal
+ $this->repairCart($cart_session_id, $id);
}
- if($this->cartProduct->create($id)) {
- session()->flash('Success', 'Product Added To Cart');
+ //matching the session id present in the cookie and database are same or not.
+ if((session()->get('cart_session_id') == Cookie::get('cart_session_id')) && ($current_cart_session_id == session()->get('cart_session_id'))) {
+ $current_cart_products = array();
+
+ $current_cart_products = $this->cart->getProducts($current_cart_id);
+
+ //checking new product coming in the cart is new or previously added item.
+ foreach($current_cart_products as $key => $value) {
+
+ $product_id = $value['id'] ?? $value->id;
+
+ if($product_id == $id) {
+ //create status code to communicate with session flash
+ session()->flash('error', 'Item Already In Cart');
+
+ //remove this its temporary
+ dump('Item Already In Cart');
+
+ return redirect()->back();
+ }
+ }
+
+ //cart data being attached to the instace.
+ $cart_data = $this->cart->attach($current_cart_id, $id, 1);
+
+ //getting the products after being attached to cart instance
+ $cart_products = $this->cart->getProducts($current_cart_id);
+
+ //storing the information in session.
+ session()->put('cart_data', [$current_cart, $cart_products]);
+
+ session()->flash('Success', 'Item Added To Cart Successfully');
+
+ dump($cart_products);
+
+ //return the control to the controller
+ return redirect()->back();
+
+ } else {
+ //repair the cart, will remake the session
+ //and add the product in the new cart instance.
+ $this->repairCart($cart_session_id, $id);
+ }
+ } else {
+ //function call
+ $this->createNewCart($id);
+ }
+ }
+
+ /*helpers*/
+
+ /**
+ * Create New Cart
+ * Cart, Cookie &
+ * Session.
+ *
+ * @return mixed
+ */
+
+ public function createNewCart($id) {
+
+ $fresh_cart_session_id = session()->getId();
+
+ $data['session_id'] = $fresh_cart_session_id;
+
+ $data['channel_id'] = core()->getCurrentChannel()->id;
+
+ if($cart = $this->cart->create($data)) {
+
+ $this->makeCartSession($fresh_cart_session_id);
+
+ $new_cart_id = $cart->id ?? $cart['id'];
+
+ $cart_product['product_id'] = $id;
+
+ $cart_product['quantity'] = 1;
+
+ $cart_product['cart_id'] = $new_cart_id;
+
+ if($cart_product = $this->cart->attach($new_cart_id, $cart_product['product_id'], $cart_product['quantity'])) {
+
+ session()->put('cart_data', [$cart, $cart_product]);
+
+ session()->flash('success', 'Item Added To Cart Successfully');
+
return redirect()->back();
}
- return redirect()->back();
+ }
+ session()->flash('error', 'Some Error Occured');
- } else {
- Cookie::queue('cart_session_id', session()->id(), $minutes);
+ return redirect()->back();
+ }
- $data['session_id'] = Cookie::get('cart_session_id');
+ /**
+ * This makes session
+ * cart.
+ */
+ public function makeCartSession($cart_session_id) {
+
+ $fresh_cart_session_id = $cart_session_id;
+
+ Cookie::queue('cart_session_id', $fresh_cart_session_id, $this->minutes);
+
+ session()->put('cart_session_id', $fresh_cart_session_id);
+ }
+
+
+ /**
+ * Reset Session and
+ * Cookie values
+ * and sync database
+ * if present.
+ *
+ * @return mixed
+ */
+ public function repairCart($cart_session_id ="null", $product_id = 0) {
+
+ if($cart_session_id == session()->get('cart_session_id')) {
+ $data['session_id'] = $cart_session_id;
$data['channel_id'] = core()->getCurrentChannel()->id;
- if($this->cart->create($data)) {
- if($this->cartProduct->create($product)) {
- session()->flash('Success', 'Product Added To Cart');
- }
- }
+ $cart = $this->cart->create($data);
+
+ $cart_id = $cart['id'] ?? $cart->id;
+
+ $this->cart->attach($cart_id, $product_id, 1);
+
+ session()->flash('success', 'Item Added To Cart Successfully');
+
+ return redirect()->back();
+
+ } else {
+
+ Cookie::queue(Cookie::forget('cart_session_id'));
+
+ session()->forget('cart_session_id');
+
+ session()->regenerate();
+
+ session()->flash('error', 'Please Try Adding Product Again.');
+
+ return redirect()->back();
}
}
@@ -96,8 +225,8 @@ class Cart {
public function guestUnitRemove($id) {
//remove the products here
- if(Cookie::has('session_c')) {
- $products = unserialize(Cookie::get('session_c'));
+ if(Cookie::has('session_cart_id')) {
+ $products = unserialize(Cookie::get('session_cart_id'));
foreach($products as $key => $value) {
if($value == $id) {
@@ -105,7 +234,7 @@ class Cart {
array_push($products, $id);
- Cookie::queue('session_c', serialize($products));
+ Cookie::queue('session_cart_id', serialize($products));
return redirect()->back();
}
@@ -123,149 +252,81 @@ class Cart {
$products = array();
- // $customerLoggedIn = auth()->guard('customer')->check();
-
- // //customer is authenticated
- // if ($customerLoggedIn) {
- //assuming that there is data in cookie and customer's cart also.
+ if(!auth()->guard('customer')->check()) {
+ throw new \Exception('This function is protected for auth customers only.');
+ }
$data['customer_id'] = auth()->guard('customer')->user()->id;
$data['channel_id'] = core()->getCurrentChannel()->id;
- $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']);
+ $customer_cart = $this->cart->findOneByField('customer_id', $data['customer_id']);
//if there are products already in cart of that customer.
- $customerCartId = $customerCart->id ?? $customerCart['id'];
+ $customer_cart_id = $customer_cart->id ?? $customer_cart['id'];
- $customerCartProducts = $this->cart->getProducts($customerCartId);
+ /**
+ * Check if their any
+ * instance of current
+ * customer in the cart
+ * table.
+ */
+ if(isset($customer_cart)) {
+ $customer_cart_products = $this->cart->getProducts($customer_cart_id);
- if (isset($customerCartProducts)) {
+ if (isset($customer_cart_products)) {
- foreach ($customerCartProducts as $previousCartProduct) {
+ foreach ($customer_cart_products as $customer_cart_product) {
+ if($customer_cart_product->id == $id) {
+ dump('Item already exists in cart');
- if($previousCartProduct->id == $id) {
- dd('product already exists in cart');
+ session()->flash('error', 'Item already exists in cart');
- session()->flash('error', 'Product already exists in cart');
+ return redirect()->back();
- return redirect()->back();
+ //maybe increase the quantity in here
+ }
}
+ //add the product in the cart
+
+ $this->cart->attach($customer_cart_id, $id, 1);
+
+ session()->flash('success', 'Item Added To Cart Successfully');
+
+ return redirect()->back();
+ } else {
+ $this->cart->destroy($customer_cart_id);
+
+ session()->flash('error', 'Try Adding The Item Again');
+
+ dd('cart instance without any product found, delete it and create a new one for the current product id');
+
+ return redirect()->back();
}
- //add the product in the cart
+ } else {
+ /**
+ * this will work
+ * for logged in users
+ * and they do not have
+ * any cart instance
+ * found in the database.
+ */
- $product['product_id'] = $id;
+ if($new_cart = $this->cart->create($data)) {
+ $new_cart_id = $new_cart->id ?? $new_cart['id'];
- $product['quantity'] = 1;
+ $this->cart->attach($new_cart_id, $id, 1);
- $product['cart_id'] = $customerCartId;
+ session()->flash('success', 'Item Added To Cart Successfully');
- $this->cartProduct->create($product);
+ return redirect()->back();
- return redirect()->back();
+ } else {
+ session()->flash('error', 'Cannot Add Item in Cart');
+
+ 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();
- // }
- // }
- // }
}
/**
@@ -284,78 +345,84 @@ class Cart {
* and sync the cookies products
* with the existing data of cart
* in the cart tables;
- */
- public function handleMerge() {
+ */
- // $productsInCookie = unserialize(Cookie::get('session_c'));
+ public function mergeCart() {
+ //considering cookie as a source of truth.
+ if(Cookie::has('cart_session_id')) {
+ /*
+ Check for previous cart of customer and
+ pull products from that cart instance
+ and then check for unique products
+ and delete the record with session id
+ and increase the quantity of the products
+ that are added again before deleting the
+ guest cart record.
+ */
- $cart_session_id = Cookie::get('cart_session_id');
+ //To hold the customer ID which is currently logged in
+ $customer_id = auth()->guard('customer')->user()->id;
- $cart = $this->cart->findOneByField('session_id');
+ //having the session id saved in the cart.
+ $cart_session_id = Cookie::get('cart_session_id');
- $cartId = $cart->id ?? $cart['id'];
+ //pull the record from cart table for above session id.
+ $guest_cart = $this->cart->findOneByField('session_id', $cart_session_id);
- $data['customer_id'] = auth()->guard('customer')->user()->id;
+ if(!isset($guest_cart)) {
+ dd('Some One Deleted Cart or it wasn\'t there from the start');
- $data['channel_id'] = core()->getCurrentChannel()->id;
+ return redirect()->back();
+ }
- $customerCart = $this->cart->findOneByField('customer_id', $data['customer_id']);
+ $guest_cart_products = $this->cart->getProducts($guest_cart->id);
- if(isset($customerCart)) {
+ //check if the current logged in customer is also
+ //having any previously saved cart instances.
+ $customer_cart = $this->cart->findOneByField('customer_id', $customer_id);
- $customerCartId = $customerCart->id ?? $customerCart['id'];
+ if(isset($customer_cart)) {
+ $customer_cart_products = $this->cart->getProducts($customer_cart->id);
- $customerCartProducts = $this->cart->getProducts($customerCartId);
+ foreach($guest_cart_products as $key => $guest_cart_product) {
- if(isset($customerCartProducts)) {
+ foreach($customer_cart_products as $customer_cart_product) {
- foreach($customerCartProducts as $previousCartProduct) {
+ if($guest_cart_product->id == $customer_cart_product->id) {
- foreach($productsInCookie as $key => $productInCookie) {
+ $quantity = $guest_cart_product->toArray()['pivot']['quantity'] + 1;
- if($previousCartProduct->id == $productInCookie) {
+ $pivot = $guest_cart_product->toArray()['pivot'];
- unset($productsInCookie[$key]);
+ $saveQuantity = $this->cart->updateRelatedForMerge($pivot, 'quantity', $quantity);
+
+ unset($guest_cart_products[$key]);
}
}
}
- }
- /*if the above block executes it will remove duplicates
- else product in cookies will be stored in the database.*/
+ //insert the new products here.
+ foreach ($guest_cart_products as $key => $guest_cart_product) {
+ $product = $guest_cart_product->toArray();
- 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);
+ $this->cart->updateRelatedForMerge($product['pivot'], 'cart_id', $customer_cart->id);
}
- }
- //forget the Cookie
- Cookie::queue(Cookie::forget('session_c'));
- return redirect()->back();
+ //detach with guest cart records
+ $this->cart->detachAndDeleteParent($guest_cart->id);
+
+ Cookie::queue(Cookie::forget('cart_session_id'));
+
+ return redirect()->back();
+ } else {
+ //this will just update the customer id column in the cart table
+ $this->cart->update(['customer_id' => $customer_id], $guest_cart->id);
+
+ Cookie::queue(Cookie::forget('cart_session_id'));
+
+ return redirect()->back();
+ }
}
+ return redirect()->back();
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Cart/src/Http/Controllers/CartController.php b/packages/Webkul/Cart/src/Http/Controllers/CartController.php
index cbb144943..101d28b9a 100644
--- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php
+++ b/packages/Webkul/Cart/src/Http/Controllers/CartController.php
@@ -42,7 +42,7 @@ class CartController extends Controller
public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer) {
- $this->middleware('customer')->except(['add', 'remove']);
+ $this->middleware('customer')->except(['add', 'remove', 'test']);
$this->customer = $customer;
@@ -66,6 +66,8 @@ class CartController extends Controller
} else {
Cart::guestUnitAdd($id);
}
+
+ return redirect()->back();
}
public function remove($id) {
@@ -75,5 +77,24 @@ class CartController extends Controller
} else {
Cart::guestUnitRemove($id);
}
+
+ return redirect()->back();
}
+
+ // public function test() {
+ // $cookie = Cookie::get('cart_session_id');
+
+ // $cart = $this->cart->findOneByField('session_id', $cookie);
+
+ // $cart_products = $this->cart->getProducts($cart->id);
+
+ // foreach($cart_products as $cart_product) {
+ // $quantity = $cart_product->toArray()['pivot']['quantity'] + 1;
+
+ // $pivot = $cart_product->toArray()['pivot'];
+
+ // $saveQuantity = $this->cart->saveRelated($pivot, 'quantity', $quantity+1);
+ // }
+ // dd('done');
+ // }
}
\ No newline at end of file
diff --git a/packages/Webkul/Cart/src/Http/ViewComposers/CartComposer.php b/packages/Webkul/Cart/src/Http/ViewComposers/CartComposer.php
new file mode 100644
index 000000000..a216c1d5c
--- /dev/null
+++ b/packages/Webkul/Cart/src/Http/ViewComposers/CartComposer.php
@@ -0,0 +1,59 @@
+
+ * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
+ */
+
+class CartComposer
+{
+
+ /**
+ * The cart implementation
+ * for shop bundle's navigation
+ * menu
+ */
+ protected $cart;
+
+ /**
+ * Bind data to the view.
+ *
+ * @param View $view
+ * @return void
+ */
+ public function __construct(CartRepository $cart) {
+ $this->cart = $cart;
+ }
+
+ public function compose(View $view) {
+ if(auth()->guard('customer')->check()) {
+ $cart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id);
+
+ $cart_products = $this->cart->getProducts($cart['id']);
+
+ // dd($cart_products);
+
+ $view->with('cart', $cart_products);
+
+ } else {
+ if(Cookie::has('cart_session_id')) {
+ $cart = $this->cart->findOneByField('session_id', Cookie::get('cart_session_id'));
+
+ $cart_products = $this->cart->getProducts($cart['id']);
+
+ $view->with('cart', $cart_products);
+ }
+ }
+ }
+}
diff --git a/packages/Webkul/Cart/src/Models/Cart.php b/packages/Webkul/Cart/src/Models/Cart.php
index f03c3a82f..f1591cdb4 100644
--- a/packages/Webkul/Cart/src/Models/Cart.php
+++ b/packages/Webkul/Cart/src/Models/Cart.php
@@ -10,11 +10,12 @@ class Cart extends Model
{
protected $table = 'cart';
- protected $fillable = ['customer_id','session_id','channel_id','coupon_code','is_gift'];
+ protected $fillable = ['customer_id', 'session_id', 'channel_id', 'coupon_code', 'is_gift'];
protected $hidden = ['coupon_code'];
public function with_products() {
- return $this->belongsToMany(Product::class, 'cart_products');
+
+ return $this->belongsToMany(Product::class, 'cart_products')->withPivot('id', 'product_id','quantity', 'cart_id');
}
}
diff --git a/packages/Webkul/Cart/src/Providers/CartServiceProvider.php b/packages/Webkul/Cart/src/Providers/CartServiceProvider.php
index 28755d917..d1ba3b051 100644
--- a/packages/Webkul/Cart/src/Providers/CartServiceProvider.php
+++ b/packages/Webkul/Cart/src/Providers/CartServiceProvider.php
@@ -8,8 +8,8 @@ use Illuminate\Routing\Router;
use Illuminate\Foundation\AliasLoader;
use Webkul\User\Http\Middleware\RedirectIfNotAdmin;
use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer;
-use Webkul\Cart\Cart;
-use Webkul\Cart\Facades\Cart as CartFacade;
+use Webkul\Cart\Facades\Cart;
+use Webkul\Cart\Providers\ComposerServiceProvider;
class CartServiceProvider extends ServiceProvider
{
@@ -18,7 +18,11 @@ class CartServiceProvider extends ServiceProvider
{
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
- $this->register(EventServiceProvider::class);
+ $router->aliasMiddleware('admin', RedirectIfNotAdmin::class);
+
+ $router->aliasMiddleware('customer', RedirectIfNotCustomer::class);
+
+ $this->app->register(ComposerServiceProvider::class);
}
/**
@@ -38,6 +42,9 @@ class CartServiceProvider extends ServiceProvider
*/
protected function registerFacades()
{
+
+ //to make the cart facade and bind the
+ //alias to the class needed to be called.
$loader = AliasLoader::getInstance();
$loader->alias('cart', CartFacade::class);
diff --git a/packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php b/packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php
new file mode 100644
index 000000000..3f62d51c7
--- /dev/null
+++ b/packages/Webkul/Cart/src/Providers/ComposerServiceProvider.php
@@ -0,0 +1,32 @@
+ $value) {
+ return $this->model->findOrFail($cart_id)->with_products()->attach($cart_id, ['product_id' => $product_id, 'cart_id' => $cart_id, 'quantity' => $quantity]);
- // $this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]);
- // }
- // }
+ }
+ /**
+ * This will update the
+ * quantity of product
+ * for the customer,
+ * in case of merge.
+ *
+ * @return Mixed
+ */
+ public function updateRelatedForMerge($pivot, $column, $value) {
+ $cart_product = $this->model->findOrFail($pivot['cart_id']);
+
+ return $cart_product->with_products()->updateExistingPivot($pivot['product_id'], array($column => $value));
+ }
/**
* Method to detach
- * and attach the
- * associations
+ * associations.
*
- * @return mixed
- */
- // public function syncAndDetach($id, $taxRates) {
- // $this->model->findOrFail($id)->tax_rates()->detach();
+ * Use this only with
+ * guest cart only.
+ *
+ * @return Mixed
+ */
+ public function detachAndDeleteParent($cart_id) {
+ $cart = $this->model->find($cart_id);
- // foreach($taxRates as $key => $value) {
- // $this->model->findOrFail($id)->tax_rates()->attach($id, ['tax_category_id' => $id, 'tax_rate_id' => $value]);
- // }
- // }
+ //apply strict check for verifying guest ownership on this record.
+ $cart->with_products()->detach();
+
+ return $this->model->destroy($cart_id);
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php
index d3017ed64..1ad764b39 100644
--- a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php
+++ b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php
@@ -71,6 +71,9 @@ class SessionController extends Controller
public function destroy($id)
{
auth()->guard('customer')->logout();
+
+ Event::fire('customer.after.logout', 1);
+
return redirect()->route($this->_config['redirect']);
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php
index d4b4e26b1..bb6bba8ec 100644
--- a/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php
+++ b/packages/Webkul/Customer/src/Http/Listeners/CustomerEventsHandler.php
@@ -27,7 +27,11 @@ class CustomerEventsHandler {
* check emptiness and then
* do the appropriate actions.
*/
- Cart::handleMerge();
+ Cart::mergeCart();
+ }
+
+ //use this when there is very uttermost need to use it.
+ public function onCustomerLogout($event) {
}
/**
@@ -39,5 +43,7 @@ class CustomerEventsHandler {
public function subscribe($events)
{
$events->listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin');
+
+ $events->listen('customer.after.logout', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogout');
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Http/routes.php
index 906226fe4..7d8361989 100644
--- a/packages/Webkul/Shop/src/Http/routes.php
+++ b/packages/Webkul/Shop/src/Http/routes.php
@@ -23,19 +23,12 @@ Route::group(['middleware' => ['web']], function () {
// //Routes for product cart
- Route::post('products/guest/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add');
+ Route::post('products/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add');
- 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/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');
+ Route::post('product/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove');
//Routes for product cart ends
-
// Product Review routes
Route::get('/reviews/{slug}', 'Webkul\Shop\Http\Controllers\ReviewController@show')->defaults('_config', [
'view' => 'shop::products.reviews.index'
@@ -53,13 +46,6 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.reviews.index'
])->name('admin.reviews.store');
- // Route::post('/reviews/create/{slug}', 'Webkul\Core\Http\Controllers\ReviewController@store')->defaults('_config', [
- // 'redirect' => 'admin.reviews.index'
- // ])->name('admin.reviews.store');
-
-
- // Route::view('/products/{slug}', 'shop::store.product.details.index');
- Route::view('/cart', 'shop::store.product.view.cart.index');
//customer routes starts here
Route::prefix('customer')->group(function () {
@@ -90,12 +76,6 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'customer.session.index'
])->name('customer.session.destroy');
- Route::view('/cart', 'shop::store.product.cart.cart.index')->name('customer.cart');
-
- Route::view('/product', 'shop::store.product.details.home.index')->name('customer.product');
-
- Route::view('/product/review', 'shop::store.product.review.index')->name('customer.product.review');
-
//customer account
Route::prefix('account')->group(function () {
diff --git a/packages/Webkul/Shop/src/Resources/assets/js/app.js b/packages/Webkul/Shop/src/Resources/assets/js/app.js
index 0e18520bc..1507aa2da 100644
--- a/packages/Webkul/Shop/src/Resources/assets/js/app.js
+++ b/packages/Webkul/Shop/src/Resources/assets/js/app.js
@@ -10,6 +10,7 @@ Vue.component("category-nav", require("./components/category-nav.vue"));
Vue.component("category-item", require("./components/category-item.vue"));
Vue.component("image-slider", require("./components/image-slider.vue"));
Vue.component("vue-slider", require("vue-slider-component"));
+Vue.component("cart-dropdown", require("./components/cart-dropdown.vue"));
$(document).ready(function () {
@@ -52,6 +53,7 @@ $(document).ready(function () {
const flashes = this.$refs.flashes;
flashMessages.forEach(function (flash) {
+ console.log(flash);
flashes.addFlash(flash);
}, this);
},
diff --git a/packages/Webkul/Shop/src/Resources/assets/js/components/cart-dropdown.vue b/packages/Webkul/Shop/src/Resources/assets/js/components/cart-dropdown.vue
new file mode 100644
index 000000000..9b27c8634
--- /dev/null
+++ b/packages/Webkul/Shop/src/Resources/assets/js/components/cart-dropdown.vue
@@ -0,0 +1,156 @@
+
+ Cart Subtotal - $80
+
+
+