Cart Inventories now pulling up item count using inventory sources status

This commit is contained in:
prashant-webkul 2018-09-22 14:01:18 +05:30
parent e37bfabda7
commit c8f67009b1
5 changed files with 62 additions and 65 deletions

View File

@ -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,12 +21,11 @@ use Cookie;
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class Cart {
protected $cart; //item repository instance
protected $cart; //cart repository instance
protected $cartItem; //cart item repository instance
protected $cartItem; //cart_item repository instance
protected $customer; //customer repository instance
@ -50,17 +46,20 @@ class Cart {
}
/**
* 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')->user()->first_name .' '. auth()->guard('customer')->user()->last_name;
}
@ -82,18 +81,18 @@ 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) {
// session()->forget('cart');
// return redirect()->back();
if(session()->has('cart')) {
$cart = session()->get('cart');
@ -145,11 +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');
@ -200,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();
}
}
}

View File

@ -100,13 +100,14 @@ 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() {
public function canAddOrUpdate() {
$cart = $this->cart->findOneByField('id', 144);
$items = $cart->items;
@ -147,6 +148,9 @@ class CartController extends Controller
dump($inventory->status);
}
}
}
public function test() {
}
}

View File

@ -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();

View File

@ -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.');

View File

@ -18,31 +18,31 @@
<div class="control-group" :class="[errors.has('first_name') ? 'has-error' : '']">
<label for="first_name">{{ __('shop::app.customer.signup-form.firstname') }}</label>
<input type="text" class="control" name="first_name" v-validate="'required'" value="{{ old('first_name') }}">
<input type="text" class="control" name="first_name" v-validate="'required'" value="{{ old('first_name') }}" required>
<span class="control-error" v-if="errors.has('first_name')">@{{ errors.first('first_name') }}</span>
</div>
<div class="control-group" :class="[errors.has('last_name') ? 'has-error' : '']">
<label for="last_name">{{ __('shop::app.customer.signup-form.lastname') }}</label>
<input type="text" class="control" name="last_name" v-validate="'required'" value="{{ old('last_name') }}">
<input type="text" class="control" name="last_name" v-validate="'required'" value="{{ old('last_name') }}" required>
<span class="control-error" v-if="errors.has('last_name')">@{{ errors.first('last_name') }}</span>
</div>
<div class="control-group" :class="[errors.has('email') ? 'has-error' : '']">
<label for="email">{{ __('shop::app.customer.signup-form.email') }}</label>
<input type="email" class="control" name="email" v-validate="'required|email'" value="{{ old('email') }}">
<input type="email" class="control" name="email" v-validate="'required|email'" value="{{ old('email') }}" required>
<span class="control-error" v-if="errors.has('email')">@{{ errors.first('email') }}</span>
</div>
<div class="control-group" :class="[errors.has('password') ? 'has-error' : '']">
<label for="password">{{ __('shop::app.customer.signup-form.password') }}</label>
<input type="password" class="control" name="password" v-validate="'required|min:6'" ref="password" value="{{ old('password') }}">
<input type="password" class="control" name="password" v-validate="'required|min:6'" ref="password" value="{{ old('password') }}" required>
<span class="control-error" v-if="errors.has('password')">@{{ errors.first('password') }}</span>
</div>
<div class="control-group" :class="[errors.has('confirm_password') ? 'has-error' : '']">
<label for="confirm_password">{{ __('shop::app.customer.signup-form.confirm_pass') }}</label>
<input type="password" class="control" name="password_confirmation" v-validate="'required|min:6|confirmed:password'">
<input type="password" class="control" name="password_confirmation" v-validate="'required|min:6|confirmed:password'" required>
<span class="control-error" v-if="errors.has('confirm_password')">@{{ errors.first('confirm_password') }}</span>
</div>