commit
59593c3d5e
|
|
@ -12,11 +12,11 @@ class EventServiceProvider extends ServiceProvider
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
'App\Events\Event' => [
|
||||
'App\Listeners\EventListener',
|
||||
],
|
||||
];
|
||||
// protected $listen = [
|
||||
// 'App\Events\Event' => [
|
||||
// 'App\Listeners\EventListener',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
"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",
|
||||
|
|
@ -52,6 +53,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\\Attribute\\": "packages/Webkul/Attribute/src",
|
||||
"Webkul\\Shop\\": "packages/Webkul/Shop/src",
|
||||
"Webkul\\Core\\": "packages/Webkul/Core/src",
|
||||
|
|
@ -59,7 +61,6 @@
|
|||
"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\\Shipping\\": "packages/Webkul/Shipping/src"
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -243,6 +243,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,
|
||||
'Core' => Webkul\Core\Facades\Core::class
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
@section('page_title')
|
||||
|
||||
@endsection
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
/node_modules
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
{
|
||||
"name": "webkul/laravel-cart",
|
||||
"description": "Cart Package for customer.",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "prashant-webkul",
|
||||
"name": "Prashant Singh",
|
||||
"email": "prashant.singh852@webkul.com"
|
||||
}
|
||||
],
|
||||
|
|
@ -17,9 +16,8 @@
|
|||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Webkul\\Cart\\Providers\\CartServiceProvider"
|
||||
],
|
||||
"aliases": {}
|
||||
"Webkul\\Cart\\CartServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,361 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
//Cart repositories
|
||||
use Webkul\Cart\Repositories\CartRepository;
|
||||
use Webkul\Cart\Repositories\CartProductRepository;
|
||||
|
||||
//Customer repositories
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
use Cookie;
|
||||
|
||||
/**
|
||||
* Cart facade for all
|
||||
* the methods to be
|
||||
* implemented for Cart.
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class Cart {
|
||||
|
||||
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 guestUnitAdd($id) {
|
||||
|
||||
$products = array();
|
||||
|
||||
$minutes = 10;
|
||||
|
||||
if(Cookie::get('current_session_id')) {
|
||||
|
||||
$cart_session_id = Cookie::get('cart_session_id');
|
||||
|
||||
$cart = $this->cart->getOneByField('session_id'. $cart_session_id);
|
||||
|
||||
$cartId = $cart->id ?? $cart['id'] ;
|
||||
|
||||
$products = $this->getProducts($id);
|
||||
|
||||
foreach($products as $key => $value) {
|
||||
if($value == $id) {
|
||||
dd('product already in the cart');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
if($this->cartProduct->create($id)) {
|
||||
session()->flash('Success', 'Product Added To Cart');
|
||||
return redirect()->back();
|
||||
}
|
||||
return redirect()->back();
|
||||
|
||||
} else {
|
||||
Cookie::queue('cart_session_id', session()->id(), $minutes);
|
||||
|
||||
$data['session_id'] = Cookie::get('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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
|
||||
$cart_session_id = Cookie::get('cart_session_id');
|
||||
|
||||
$cart = $this->cart->findOneByField('session_id');
|
||||
|
||||
$cartId = $cart->id ?? $cart['id'];
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
|
|||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCartItemsTable extends Migration
|
||||
class CreateCartProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
|
|
@ -13,7 +13,7 @@ class CreateCartItemsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cart_items', function (Blueprint $table) {
|
||||
Schema::create('cart_products', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('product_id')->unsigned();
|
||||
$table->foreign('product_id')->references('id')->on('products');
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Cart extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'cart';
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,16 @@ namespace Webkul\Cart\Http\Controllers;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
//Cart repositories
|
||||
use Webkul\Cart\Repositories\CartRepository;
|
||||
use Webkul\Cart\Repositories\CartItemsRepository;
|
||||
use Session;
|
||||
use Webkul\Cart\Repositories\CartProductRepository;
|
||||
|
||||
//Customer repositories
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
use Cart;
|
||||
use Cookie;
|
||||
|
||||
/**
|
||||
* Cart controller for the customer
|
||||
|
|
@ -29,17 +36,44 @@ class CartController extends Controller
|
|||
|
||||
protected $cart;
|
||||
|
||||
protected $cartProduct;
|
||||
|
||||
public function __construct(CartRepository $cart)
|
||||
{
|
||||
$this->middleware(['customer', 'guest']);
|
||||
protected $customer;
|
||||
|
||||
$this->_config = request('_config');
|
||||
public function __construct(CartRepository $cart, CartProductRepository $cartProduct, CustomerRepository $customer) {
|
||||
|
||||
$this->middleware('customer')->except(['add', 'remove']);
|
||||
|
||||
$this->customer = $customer;
|
||||
|
||||
$this->cart = $cart;
|
||||
|
||||
$this->cartProduct = $cartProduct;
|
||||
}
|
||||
|
||||
public function add() {
|
||||
return "Adding Items to Cart";
|
||||
/**
|
||||
* Function for guests
|
||||
* user to add the product
|
||||
* in the cart.
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
|
||||
public function add($id) {
|
||||
|
||||
if(auth()->guard('customer')->check()) {
|
||||
Cart::add($id);
|
||||
} else {
|
||||
Cart::guestUnitAdd($id);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($id) {
|
||||
|
||||
if(auth()->guard('customer')->check()) {
|
||||
Cart::remove($id);
|
||||
} else {
|
||||
Cart::guestUnitRemove($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?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;
|
||||
}
|
||||
|
|
@ -2,11 +2,19 @@
|
|||
|
||||
namespace Webkul\Cart\Models;
|
||||
|
||||
class Cart
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Webkul\Product\Models\Product;
|
||||
|
||||
class Cart extends Model
|
||||
{
|
||||
protected $table = 'cart';
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CartItems
|
||||
class CartProduct extends Model
|
||||
{
|
||||
protected $table = 'cart_items';
|
||||
protected $table = 'cart_products';
|
||||
|
||||
protected $fillable = ['product_id','quantity','cart_id','tax_category_id','coupon_code'];
|
||||
}
|
||||
|
|
@ -3,17 +3,25 @@
|
|||
namespace Webkul\Cart\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
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;
|
||||
|
||||
class CartServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
||||
|
||||
$router->aliasMiddleware('admin', RedirectIfNotAdmin::class);
|
||||
|
||||
// $router->aliasMiddleware('customer', RedirectIfNotCustomer::class);
|
||||
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
|
||||
$this->register(EventServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -23,6 +31,24 @@ class CartServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
// $this->app->bind('datagrid', 'Webkul\Ui\DataGrid\DataGrid');
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use Webkul\Core\Eloquent\Repository;
|
|||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class CartItemsRepository extends Repository
|
||||
class CartProductRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
|
|
@ -21,7 +21,7 @@ class CartItemsRepository extends Repository
|
|||
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\Cart\Models\CartItems';
|
||||
return 'Webkul\Cart\Models\CartProduct';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,4 +51,39 @@ class CartRepository extends Repository
|
|||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public function getProducts($id) {
|
||||
|
||||
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]);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
@ -140,9 +140,8 @@ class Core
|
|||
|
||||
$channel = $this->getCurrentChannel();
|
||||
|
||||
$currencyCode = $channel->base_currency;
|
||||
|
||||
// $currencyCode = $channel->base_currency->code;
|
||||
$currencyCode = $channel->base_currency;
|
||||
|
||||
return currency($price, $currencyCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ use Illuminate\Routing\Router;
|
|||
use Illuminate\Foundation\AliasLoader;
|
||||
use Webkul\Core\Http\Middleware\Locale;
|
||||
use Webkul\Core\Core;
|
||||
use Webkul\Core\Facades\CoreFacade;
|
||||
use Webkul\Core\Facades\Core as CoreFacade;
|
||||
|
||||
class CoreServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
|
|
@ -20,9 +21,15 @@ class CoreServiceProvider extends ServiceProvider
|
|||
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
||||
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'core');
|
||||
$router->aliasMiddleware('locale', Locale::class);
|
||||
|
||||
$router->aliasMiddleware('admin', RedirectIfNotAdmin::class);
|
||||
|
||||
$router->aliasMiddleware('customer', RedirectIfNotCustomer::class);
|
||||
|
||||
// $this->publishes([
|
||||
// __DIR__ . '/../../publishable/lang' => public_path('vendor/webkul/core/lang'),
|
||||
// ], 'public');
|
||||
|
||||
Validator::extend('slug', 'Webkul\Core\Contracts\Validations\Slug@passes');
|
||||
Validator::extend('code', 'Webkul\Core\Contracts\Validations\Code@passes');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "prashant-webkul",
|
||||
"name": "Prashant Singh",
|
||||
"email": "prashant.singh852@webkul.com"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Auth;
|
|||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,9 +4,13 @@ namespace Webkul\Customer\Http\Controllers;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Webkul\Customer\Models\Customer;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
use Webkul\Customer\Models\Customer;
|
||||
use Webkul\Customer\Http\Listeners\CustomerEventsHandler;
|
||||
|
||||
use Cookie;
|
||||
use Cart;
|
||||
/**
|
||||
* Session controller for the user customer
|
||||
*
|
||||
|
|
@ -29,6 +33,10 @@ class SessionController extends Controller
|
|||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$subscriber = new CustomerEventsHandler;
|
||||
|
||||
Event::subscribe($subscriber);
|
||||
|
||||
}
|
||||
|
||||
public function show()
|
||||
|
|
@ -53,6 +61,10 @@ class SessionController extends Controller
|
|||
return back();
|
||||
}
|
||||
|
||||
//Event passed to prepare cart after login
|
||||
|
||||
Event::fire('customer.after.login', $request->input('email'));
|
||||
|
||||
return redirect()->intended(route($this->_config['redirect']));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Customer\Http\Listeners;
|
||||
use Cookie;
|
||||
use Cart;
|
||||
|
||||
class CustomerEventsHandler {
|
||||
|
||||
/**
|
||||
* Handle Customer login events.
|
||||
*/
|
||||
public function onCustomerLogin($event)
|
||||
{
|
||||
/**
|
||||
* handle the user login
|
||||
* event to manage the
|
||||
* after login, if
|
||||
* the user has added any
|
||||
* products as guest then
|
||||
* the cart items from session
|
||||
* will be transferred from
|
||||
* cookie to the cart table
|
||||
* in the database.
|
||||
*
|
||||
* Check whether cookie is
|
||||
* present or not and then
|
||||
* check emptiness and then
|
||||
* do the appropriate actions.
|
||||
*/
|
||||
Cart::handleMerge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the listeners for the subscriber.
|
||||
*
|
||||
* @param Illuminate\Events\Dispatcher $events
|
||||
* @return void */
|
||||
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin');
|
||||
}
|
||||
}
|
||||
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace Webkul\Customer\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Webkul\Customer\Menu;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
|
|
@ -27,6 +28,7 @@ class EventServiceProvider extends ServiceProvider
|
|||
|
||||
public function createCustomerAccountSideMenu()
|
||||
{
|
||||
|
||||
Event::listen('customer.menu.create', function () {
|
||||
return Menu::create(function ($menu) {
|
||||
Event::fire('customer.menu.build', $menu);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ class Product extends Model
|
|||
|
||||
protected $with = ['attribute_family', 'inventories'];
|
||||
|
||||
// protected $table = 'products';
|
||||
|
||||
/**
|
||||
* Get the product attribute family that owns the product.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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": {},
|
||||
|
|
|
|||
|
|
@ -21,6 +21,20 @@ Route::group(['middleware' => ['web']], function () {
|
|||
'view' => 'shop::products.view'
|
||||
])->name('shop.products.index');
|
||||
|
||||
// //Routes for product cart
|
||||
|
||||
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@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');
|
||||
|
||||
//Routes for product cart ends
|
||||
|
||||
|
||||
// Product Review routes
|
||||
Route::get('/reviews/{slug}/{id}', 'Webkul\Shop\Http\Controllers\ReviewController@show')->defaults('_config', [
|
||||
|
|
@ -59,7 +73,6 @@ Route::group(['middleware' => ['web']], function () {
|
|||
'redirect' => 'customer.account.index'
|
||||
])->name('customer.session.create');
|
||||
|
||||
|
||||
// Registration Routes
|
||||
Route::get('register', 'Webkul\Customer\Http\Controllers\RegistrationController@show')->defaults('_config', [
|
||||
'view' => 'shop::customers.signup.index' //hint path
|
||||
|
|
@ -128,7 +141,7 @@ Route::group(['middleware' => ['web']], function () {
|
|||
])->name('customer.address.edit');
|
||||
|
||||
Route::post('address/edit', 'Webkul\Customer\Http\Controllers\AddressController@edit')->defaults('_config', [
|
||||
'view' => 'shop::customers.account.address.address'
|
||||
'redirect' => 'customer.address.index'
|
||||
])->name('customer.address.edit');
|
||||
|
||||
/* Routes for Addresses ends here */
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ComposerServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
//using the class based composers...
|
||||
View::composer('shop::layouts.header.index', 'Webkul\Shop\Http\ViewComposers\Categories\CategoryComposer');
|
||||
View::composer(['shop::layouts.header.index', 'shop::layouts.footer'], 'Webkul\Shop\Http\ViewComposers\Categories\CategoryComposer');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -767,6 +767,7 @@ section.slider-block {
|
|||
margin-right: 10%;
|
||||
|
||||
.content-container {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
|
@ -777,7 +778,7 @@ section.slider-block {
|
|||
|
||||
.product-grid {
|
||||
display: grid;
|
||||
grid-gap: 15px;
|
||||
grid-gap: 30px;
|
||||
|
||||
&.max-2-col {
|
||||
grid-template-columns: repeat(2, minmax(250px, 1fr));
|
||||
|
|
@ -1285,12 +1286,11 @@ section.slider-block {
|
|||
|
||||
//edit form
|
||||
.edit-form-content {
|
||||
padding: 0px 25px;
|
||||
margin-left: 5.5%;
|
||||
margin-top: 1%;
|
||||
width: 100%;
|
||||
|
||||
.title {
|
||||
.edit-text {
|
||||
margin-bottom: 2%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
|
|
@ -1300,36 +1300,13 @@ section.slider-block {
|
|||
.edit-form {
|
||||
display: flex;
|
||||
background: $background-color;
|
||||
border: 1px solid $border-color;
|
||||
flex-direction: column;
|
||||
min-height: 345px;
|
||||
// padding: 25px;
|
||||
padding: 25px;
|
||||
}
|
||||
}
|
||||
//edit form ends
|
||||
|
||||
//address form
|
||||
.address-form-content {
|
||||
padding: 0px 25px;
|
||||
margin-left: 5.5%;
|
||||
margin-top: 1%;
|
||||
width: 100%;
|
||||
|
||||
.title {
|
||||
margin-bottom: 2%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.address-form {
|
||||
display: flex;
|
||||
background: $background-color;
|
||||
flex-direction: column;
|
||||
min-height: 345px;
|
||||
// padding: 25px;
|
||||
}
|
||||
}
|
||||
//address form ends
|
||||
}
|
||||
//account ends here
|
||||
//customers page css ends here
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@
|
|||
@include('shop::home.featured-products')
|
||||
|
||||
@include('shop::home.new-products')
|
||||
|
||||
|
||||
@include('shop::home.news-updates')
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<section class="featured-products">
|
||||
<div class="featured-heading">
|
||||
{{ $session_id = session()->getId() }}<br/>
|
||||
New Products<br/>
|
||||
<span class="featured-seperator" style="color:lightgrey;">_____</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@
|
|||
<div class="list-container">
|
||||
<span class="list-heading">Categories</span>
|
||||
<ul class="list-group">
|
||||
<li>MEN</li>
|
||||
<li>Women</li>
|
||||
<li>Kids</li>
|
||||
<li>Accessories</li>
|
||||
<li>Home & Living</li>
|
||||
@foreach($categories as $key => $category)
|
||||
<li>{{ $category['name'] }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
<div class="list-container">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<div class="header">
|
||||
<div class="header" id="header">
|
||||
|
||||
<div class="header-top">
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@
|
|||
|
||||
<div id="app">
|
||||
|
||||
@include('shop::layouts.header.index')
|
||||
|
||||
@yield('slider')
|
||||
|
||||
<div class="main-container-wrapper">
|
||||
|
||||
@include('shop::layouts.header.index')
|
||||
|
||||
@yield('slider')
|
||||
|
||||
<div class="content-container">
|
||||
|
||||
@yield('content-wrapper')
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
window.flashMessages = [];
|
||||
|
||||
|
||||
@if($success = session('success'))
|
||||
window.flashMessages = [{'type': 'alert-success', 'message': "{{ $success }}" }];
|
||||
@elseif($warning = session('warning'))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
@extends('shop::layouts.master')
|
||||
|
||||
@section('content-wrapper')
|
||||
|
||||
|
||||
@include ('shop::products.list.layered-navigation')
|
||||
|
||||
<div class="main" style="display: inline-block">
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
@if ($toolbarHelper->getCurrentMode() == 'grid')
|
||||
<div class="product-grid max-3-col">
|
||||
|
||||
|
||||
@foreach ($products as $product)
|
||||
|
||||
@include ('shop::products.list.card', ['product' => $product])
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
</div>
|
||||
@else
|
||||
<div class="product-list">
|
||||
|
||||
|
||||
@foreach ($products as $product)
|
||||
|
||||
@include ('shop::products.list.card', ['product' => $product])
|
||||
|
|
@ -35,13 +35,13 @@
|
|||
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
<div class="bottom-toolbar">
|
||||
|
||||
{{ $products->appends(request()->input())->links() }}
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@stop
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
@inject ('reviewHelper', 'Webkul\Product\Product\Review')
|
||||
|
||||
@if ($total = $reviewHelper->getTotalReviews($product))
|
||||
|
||||
<div class="product-ratings">
|
||||
|
||||
<span class="stars">
|
||||
@for ($i = 1; $i <= round($reviewHelper->getAverageRating($product)); $i++)
|
||||
|
||||
<span class="icon star-icon"></span>
|
||||
|
||||
|
||||
@endfor
|
||||
</span>
|
||||
|
||||
<div class="total-reviews">
|
||||
{{ __('shop::app.products.total-reviews', ['total' => $total]) }}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
@endif
|
||||
|
|
@ -7,11 +7,9 @@
|
|||
<span class="breadcrumb">Home</span> > <span class="breadcrumb">Men</span> > <span class="breadcrumb">Slit Open Jeans</span>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="layouter">
|
||||
|
||||
<form action="">
|
||||
|
||||
{{-- {{ dd(session()->getId()) }} --}}
|
||||
<form method="POST" action="{{ route('cart.add', $product->id) }}">
|
||||
@csrf()
|
||||
|
||||
<input type="hidden" name="product">
|
||||
|
|
@ -55,7 +53,7 @@
|
|||
@include ('shop::products.view.reviews')
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
|
@ -63,4 +61,5 @@
|
|||
@include ('shop::products.view.up-sells')
|
||||
|
||||
</section>
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
</tr>
|
||||
|
||||
@endforeach
|
||||
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</accordian>
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
@include ('shop::products.add-to')
|
||||
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
|
||||
<script type="text/x-template" id="product-gallery-template">
|
||||
|
|
@ -94,7 +93,7 @@
|
|||
this.thumbs = [moveThumb[0], ...this.thumbs];
|
||||
} else {
|
||||
const moveThumb = this.thumbs.splice(0, 1);
|
||||
|
||||
|
||||
this.thumbs = [...this.thumbs, moveThumb[0]];
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -953,7 +953,7 @@ class ProductGrid
|
|||
|
||||
$this->allAttributes = $this->getAttributes();
|
||||
$this->getDbQueryResults();
|
||||
dd($this->results);
|
||||
// dd($this->results);
|
||||
return view('ui::datagrid.index', [
|
||||
'css' => $this->css,
|
||||
'results' => $this->results,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
<form onsubmit="return confirm('Are You Sure?');"
|
||||
@if(strtoupper($massoperation[ 'method'])=="GET" || strtoupper($massoperation['method'])=="POST" )
|
||||
method="{{ strtoupper($massoperation['method']) }}"
|
||||
|
||||
@else
|
||||
method="POST"
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -811,6 +811,7 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
}
|
||||
|
||||
.main-container-wrapper .content-container {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
|
@ -821,7 +822,7 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
|
||||
.main-container-wrapper .product-grid {
|
||||
display: grid;
|
||||
grid-gap: 15px;
|
||||
grid-gap: 30px;
|
||||
}
|
||||
|
||||
.main-container-wrapper .product-grid.max-2-col {
|
||||
|
|
@ -1353,13 +1354,12 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
}
|
||||
|
||||
.account-content .edit-form-content {
|
||||
padding: 0px 25px;
|
||||
margin-left: 5.5%;
|
||||
margin-top: 1%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.account-content .edit-form-content .title {
|
||||
.account-content .edit-form-content .edit-text {
|
||||
margin-bottom: 2%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
|
|
@ -1371,37 +1371,13 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
background: #ffffff;
|
||||
border: 1px solid #c7c7c7;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
min-height: 345px;
|
||||
}
|
||||
|
||||
.account-content .address-form-content {
|
||||
padding: 0px 25px;
|
||||
margin-left: 5.5%;
|
||||
margin-top: 1%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.account-content .address-form-content .title {
|
||||
margin-bottom: 2%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.account-content .address-form-content .address-form {
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
background: #ffffff;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: column;
|
||||
flex-direction: column;
|
||||
min-height: 345px;
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
section.product-detail {
|
||||
|
|
|
|||
Loading…
Reference in New Issue