Merge branch 'prashant' of https://github.com/bagisto/bagisto into rahul

This commit is contained in:
rahul shukla 2018-09-24 16:12:10 +05:30
commit 3c9153be87
8 changed files with 114 additions and 95 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,21 +21,20 @@ use Cookie;
* @author Prashant Singh <prashant.singh852@webkul.com>
* @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();
}
}
}

View File

@ -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() {
}
}

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

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

View File

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

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

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

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>