diff --git a/packages/Webkul/Cart/src/Cart.php b/packages/Webkul/Cart/src/Cart.php index a91dc12b6..094ca5330 100644 --- a/packages/Webkul/Cart/src/Cart.php +++ b/packages/Webkul/Cart/src/Cart.php @@ -4,14 +4,11 @@ namespace Webkul\Cart; use Carbon\Carbon; -//Cart repositories use Webkul\Cart\Repositories\CartRepository; use Webkul\Cart\Repositories\CartItemRepository; -//Customer repositories use Webkul\Customer\Repositories\CustomerRepository; -//Product Repository use Webkul\Product\Repositories\ProductRepository; use Cookie; @@ -24,21 +21,20 @@ use Cookie; * @author Prashant Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ - class Cart { - protected $cart; + protected $cart; //cart repository instance - protected $cartItem; + protected $cartItem; //cart_item repository instance - protected $customer; + protected $customer; //customer repository instance - //Cookie expiry limit in minutes - protected $minutes; + protected $product; //product repository instance - protected $product; - - public function __construct(CartRepository $cart, CartItemRepository $cartItem, CustomerRepository $customer, $minutes = 150, ProductRepository $product) { + public function __construct(CartRepository $cart, + CartItemRepository $cartItem, + CustomerRepository $customer, + ProductRepository $product) { $this->customer = $customer; @@ -46,34 +42,33 @@ class Cart { $this->cartItem = $cartItem; - $this->minutes = $minutes; - $this->product = $product; } /** - * Create New Cart - * Cart, Cookie & - * Session. + * Create new cart + * instance with the + * current item added. * - * @return mixed - */ - + * @param @id + * @param $data + * + * @return Mixed + */ public function createNewCart($id, $data) { - $cartData['channel_id'] = core()->getCurrentChannel()->id; if(auth()->guard('customer')->check()) { - $data['customer_id'] = auth()->guard('customer')->user()->id; + $cartData['customer_id'] = auth()->guard('customer')->user()->id; - $cartData['customer_full_name'] = auth()->guard('customer')->first_name .' '. auth()->guard('customer')->last_name; + $cartData['customer_full_name'] = auth()->guard('customer')->user()->first_name .' '. auth()->guard('customer')->user()->last_name; } if($cart = $this->cart->create($cartData)) { - + $data['cart_id'] = $cart->id; $data['product_id'] = $id; - if($result = $cart->items()->create($data)) { + if($result = $this->cartItem->create($data)) { session()->put('cart', $cart); session()->flash('success', 'Item Added To Cart Successfully'); @@ -86,21 +81,24 @@ class Cart { 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. - */ - + /** + * Add Items in a + * cart with some + * cart and item + * details. + * + * @param @id + * @param $data + * + * @return Mixed + */ public function add($id, $data) { - if(session()->has('cart')) { $cart = session()->get('cart'); - $cartItems = $cart->items; + $cartItems = $cart->items()->get(); if(isset($cartItems)) { - foreach($cartItems as $cartItem) { if($cartItem->product_id == $id) { $prevQty = $cartItem->quantity; @@ -146,12 +144,13 @@ class Cart { } /** - * Function to handle merge - * and sync the cookies products - * with the existing data of cart - * in the cart tables; - */ - + * This function handles + * when guest has some of + * cart products and then + * logs in. + * + * @return Redirect + */ public function mergeCart() { if(session()->has('cart')) { $cart = session()->get('cart'); @@ -168,7 +167,7 @@ class Cart { foreach($cartItems as $key => $cartItem) { - if($cartItem->product_id == $customerCartItem->id) { + if($cartItem->product_id == $customerCartItem->product_id) { $customerItemQuantity = $customerCartItem->quantity; @@ -176,9 +175,9 @@ class Cart { $customerCartItem->update(['cart_id' => $customerCart->id, 'quantity' => $cartItemQuantity + $customerItemQuantity]); - $cartItem->destroy(); + $this->cartItem->delete($cartItem->id); - unset($cartItems[$key]); + $cartItems->forget($key); } } } @@ -202,19 +201,4 @@ class Cart { return redirect()->back(); } } - - /** - * Destroys the session - * maintained for cart - * on customer logout. - * - * @return Mixed - */ - public function destroyCart() { - if(session()->has('cart')) { - session()->forget('cart'); - - return redirect()->back(); - } - } } \ 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 cc77f47c9..5b77c35d4 100644 --- a/packages/Webkul/Cart/src/Http/Controllers/CartController.php +++ b/packages/Webkul/Cart/src/Http/Controllers/CartController.php @@ -100,14 +100,15 @@ class CartController extends Controller } /** - * This is a test for - * relationship existence - * from cart item to product + * This method will return + * the quantities from + * inventory sources whose + * status are not false. * * @return Array */ - public function test() { - $cart = $this->cart->findOneByField('id', 110); + public function canAddOrUpdate() { + $cart = $this->cart->findOneByField('id', 144); $items = $cart->items; @@ -120,15 +121,36 @@ class CartController extends Controller foreach($items as $item) { $inventories = $item->product->inventories; - foreach($inventories as $inventory) { - $totalQty = $totalQty + $inventory->qty; + $inventory_sources = $item->product->inventory_sources; + + $totalQty = 0; + foreach($inventory_sources as $inventory_source) { + + if($inventory_source->status!=0) { + foreach($inventories as $inventory) { + $totalQty = $totalQty + $inventory->qty; + } + + array_push($allProdQty1, $totalQty); + + $allProdQty[$item->product->id] = $totalQty; + } + } - - array_push($allProdQty1, $totalQty); - - $allProdQty[$item->product->id] = $totalQty; } - dd($allProdQty, $allProdQty1); + dd($allProdQty); + + foreach ($items as $item) { + $inventories = $item->product->inventory_sources->where('status', '=', '1'); + + foreach($inventories as $inventory) { + dump($inventory->status); + } + } + } + + public function test() { + } } \ 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 index 210e95017..372f40d14 100644 --- a/packages/Webkul/Cart/src/Http/ViewComposers/CartComposer.php +++ b/packages/Webkul/Cart/src/Http/ViewComposers/CartComposer.php @@ -9,8 +9,6 @@ use Webkul\Cart\Repositories\CartRepository; use Webkul\Cart\Repositories\CartItemRepository; - -use Cookie; use Cart; /** * cart List Composer on Navigation Menu @@ -57,11 +55,11 @@ class CartComposer $view->with('cart', $cart_products); } } else { - if(Cookie::has('cart_session_id')) { - $cart = $this->cart->findOneByField('session_id', Cookie::get('cart_session_id')); + if(session()->has('cart')) { + $cart = session()->get('cart'); if(isset($cart)) { - $cart_items = $this->cart->items($cart['id']); + $cartItems = $this->cart->items($cart['id']); $cart_products = array(); diff --git a/packages/Webkul/Cart/src/Models/Cart.php b/packages/Webkul/Cart/src/Models/Cart.php index eb1d92950..734897522 100644 --- a/packages/Webkul/Cart/src/Models/Cart.php +++ b/packages/Webkul/Cart/src/Models/Cart.php @@ -15,11 +15,6 @@ class Cart extends Model protected $hidden = ['coupon_code']; - public function with_products() { - - return $this->belongsToMany(Product::class, 'cart_items')->withPivot('id', 'product_id','quantity', 'cart_id'); - } - public function items() { return $this->hasMany('Webkul\Cart\Models\CartItem'); } diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index 0b5d36e49..4457259e3 100644 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -140,8 +140,7 @@ class Core $channel = $this->getCurrentChannel(); - $currencyCode = $channel->base_currency->code; - // $currencyCode = $channel->base_currency; + $currencyCode = $channel->base_currency; return currency($price, $currencyCode); } diff --git a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php index 67ea8ba65..656bb73fc 100644 --- a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php @@ -31,7 +31,10 @@ class RegistrationController extends Controller } /** - * For showing the registration form + * Opens up the + * user's sign up + * form. + * * @return view */ public function show() @@ -40,9 +43,11 @@ class RegistrationController extends Controller } /** - * For collecting the registration - * data from the registraion form - * @return view + * Method to store + * user's sign up + * form data to DB + * + * @return Mixed */ public function create(Request $request) { @@ -52,13 +57,17 @@ class RegistrationController extends Controller 'first_name' => 'string|required', 'last_name' => 'string|required', 'email' => 'email|required', - 'password' => 'confirmed|min:6|required' - + 'password' => 'confirmed|min:6|required', + 'agreement' => 'confirmed' ]); - $registrationData = $request->except('_token'); + $data = request()->input(); - if ($this->customer->create($registrationData)) { + $data['password'] = bcrypt($data['password']); + + // $registrationData = $request->except('_token'); + + if ($this->customer->create($data)) { session()->flash('success', 'Account created successfully.'); diff --git a/packages/Webkul/Product/src/Models/ProductInventory.php b/packages/Webkul/Product/src/Models/ProductInventory.php index 582bdfc24..cb503f8c9 100644 --- a/packages/Webkul/Product/src/Models/ProductInventory.php +++ b/packages/Webkul/Product/src/Models/ProductInventory.php @@ -9,4 +9,16 @@ class ProductInventory extends Model public $timestamps = false; protected $fillable = ['qty', 'product_id', 'inventory_source_id']; + + /** + * Use by cart for + * checking the + * inventory source + * status + * + * @return Collection + */ + // public function checkInventoryStatus() { + // return $this->leftjoin('inventory_sources', 'inventory_sources.id', 'inventory_source_id')->select('status')->where('status', '=','1'); + // } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php index ecc0e4564..21c916675 100644 --- a/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php @@ -18,31 +18,31 @@
- + @{{ errors.first('first_name') }}
- + @{{ errors.first('last_name') }}
- + @{{ errors.first('email') }}
- + @{{ errors.first('password') }}
- + @{{ errors.first('confirm_password') }}