Fixed bugs and made way for exisiting features of cart to be implemented in new future

This commit is contained in:
prashant-webkul 2018-09-25 14:07:34 +05:30
parent aeaf81f08b
commit 26de50bc46
11 changed files with 75 additions and 126 deletions

View File

@ -65,17 +65,17 @@
<span class="control-error" v-if="errors.has('locales[]')">@{{ errors.first('locales[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('default_locale') ? 'has-error' : '']">
<div class="control-group" :class="[errors.has('default_locale_id') ? 'has-error' : '']">
<label for="default_locale" class="required">{{ __('admin::app.settings.channels.default-locale') }}</label>
<?php $selectedOption = old('default_locale') ?: $channel->default_locale_id ?>
<select v-validate="'required'" class="control" id="default_locale" name="default_locale">
<select v-validate="'required'" class="control" id="default_locale" name="default_locale_id">
@foreach(core()->getAllLocales() as $locale)
<option value="{{ $locale->id }}" {{ $selectedOption == $locale->id ? 'selected' : '' }}>
{{ $locale->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('default_locale')">@{{ errors.first('default_locale') }}</span>
<span class="control-error" v-if="errors.has('default_locale_id')">@{{ errors.first('default_locale_id') }}</span>
</div>
<div class="control-group" :class="[errors.has('currencies[]') ? 'has-error' : '']">
@ -91,17 +91,17 @@
<span class="control-error" v-if="errors.has('currencies[]')">@{{ errors.first('currencies[]') }}</span>
</div>
<div class="control-group" :class="[errors.has('base_currency') ? 'has-error' : '']">
<div class="control-group" :class="[errors.has('base_currency_id') ? 'has-error' : '']">
<label for="base_currency" class="required">{{ __('admin::app.settings.channels.base-currency') }}</label>
<?php $selectedOption = old('base_currency') ?: $channel->base_currency_id ?>
<select v-validate="'required'" class="control" id="base_currency" name="base_currency">
<select v-validate="'required'" class="control" id="base_currency" name="base_currency_id">
@foreach(core()->getAllCurrencies() as $currency)
<option value="{{ $currency->id }}" {{ $selectedOption == $currency->id ? 'selected' : '' }}>
{{ $currency->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('base_currency')">@{{ errors.first('base_currency') }}</span>
<span class="control-error" v-if="errors.has('base_currency_id')">@{{ errors.first('base_currency_id') }}</span>
</div>
</div>

View File

@ -102,9 +102,6 @@ class Cart {
*/
public function add($id, $data) {
// session()->forget('cart');
// return redirect()->back();
if(session()->has('cart')) {
$cart = session()->get('cart');

View File

@ -20,6 +20,11 @@ class CreateCartTable extends Migration
$table->string('session_id')->nullable();
$table->integer('channel_id')->unsigned();
$table->foreign('channel_id')->references('id')->on('channels');
$table->string('sku')->nullable();
$table->string('type')->nullable();
$table->string('name')->nullable();
$table->integer('parent_id')->nullable();
$table->foreign('parent_id')->references('id')->on('cart');
$table->string('coupon_code')->nullable();
$table->boolean('is_gift')->nullable();
$table->integer('items_count')->nullable();

View File

@ -4,19 +4,15 @@ namespace Webkul\Cart\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Cart\Repositories\CartRepository;
use Webkul\Cart\Repositories\CartItemRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Product\ProductImage;
use Webkul\Product\Product\View as ProductView;
use Webkul\Attribute\Repositories\AttributeOptionRepository;
use Cart;
use Cookie;
/**
* Cart controller for the customer
@ -31,9 +27,17 @@ class CartController extends Controller
{
/**
* Display a listing of the resource.
* Protected Variables that
* holds instances of the
* repository classes.
*
* @return \Illuminate\Http\Response
* @param Array $_config
* @param $cart
* @param $cartItem
* @param $customer
* @param $product
* @param $productImage
* @param $productView
*/
protected $_config;
@ -47,7 +51,26 @@ class CartController extends Controller
protected $productView;
public function __construct(CartRepository $cart, CartItemRepository $cartItem, CustomerRepository $customer, ProductRepository $product, ProductImage $productImage, ProductView $productView) {
/**
* Initializing various
* required repositories
* and classes.
*
* @param Mixed $cart
* @param Mixed $cartItem
* @param Mixed $customer
* @param Mixed $product
* @param Mixed $productImage
* @param Mixed $productView
*/
public function __construct(
CartRepository $cart,
CartItemRepository $cartItem,
CustomerRepository $customer,
ProductRepository $product,
ProductImage $productImage,
ProductView $productView)
{
$this->middleware('customer')->except(['add', 'remove', 'test']);
@ -75,20 +98,34 @@ class CartController extends Controller
*/
public function add($id) {
session()->forget('cart');
return redirect()->back();
$data = request()->input();
if(!isset($data['is_configurable']) || !isset($data['product']) ||!isset($data['quantity'])) {
session()->flash('error', 'Cannot Product Due to User\'s miscreancy in system\'s integrity');
session()->flash('error', 'Cart System Integrity Violation');
return redirect()->back();
} else {
//handle the accidental case
//when some one deleted
//form fields from the DOM
if($data['is_configurable']) {
if(!isset($data['super_attributes'])) {
session()->flash('error', 'Cart System Integrity Violation');
return redirect()->back();
}
}
}
if($data['is_configurable'] == "false") {
$data['price'] = $this->product->findOneByField('id', $data['product'])->price;
} else {
$id = $data['selected_configurable_option'];
if(isset($data['is_configurable']) && $data['is_configurable']) {
$data['price'] = $this->product->findOneByField('id', $data['selected_configurable_option'])->price;
} else {
$data['price'] = $this->product->findOneByField('id', $data['product'])->price;
}
Cart::add($id, $data);

View File

@ -48,8 +48,6 @@ class CartComposer
$cart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id);
if(isset($cart)) {
$cart = $this->cart->findOneByField('id', 144);
$cartItems = $this->cart->items($cart['id']);
$products = array();
@ -74,8 +72,6 @@ class CartComposer
$cart = session()->get('cart');
if(isset($cart)) {
$cart = $this->cart->findOneByField('id', 144);
$cartItems = $this->cart->items($cart['id']);
$products = array();

View File

@ -42,7 +42,6 @@ class CartRepository extends Repository
* @param string $attribute
* @return Mixed
*/
public function update(array $data, $id, $attribute = "id")
{
$cart = $this->find($id);
@ -52,60 +51,6 @@ 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 attach($cart_id, $product_id, $quantity, $price) {
return $this->model->findOrFail($cart_id)->with_products()->attach($cart_id, ['product_id' => $product_id, 'cart_id' => $cart_id, 'quantity' => $quantity, 'price' => $price]);
}
/**
* Create Cart Item
* Through Cart.
*
* @return Collection
*/
public function createItem($cartId, $data) {
$cart = $this->model->findOrFail($cartId);
return $cart->items()->create($data);
}
/**
* This will update the
* quantity of product
* for the customer,
* in case of merge.
*
* @return Mixed
*/
public function updateRelatedForMerge($cart_id, $product_id, $column, $value) {
$cart_product = $this->model->findOrFail($cart_id);
return $cart_product->with_products()->updateExistingPivot($product_id, array($column => $value));
}
/**
* Update the quantity of
* previously added item
* in the cart.
*
* @return Mixed
*/
// public function updateRelatedInItems($cartId, $cartItemId, $column, $value) {
// return $this->updateItem($cartId)->syncWithoutDetaching($cartItemId, [$column => $value]);
// }
/**
* Method to detach
* associations.
@ -121,6 +66,14 @@ class CartRepository extends Repository
return $this->model->destroy($cart_id);
}
/**
* Used to get items
* for cart explicitly,
* use cart instance
* instead.
*
* @return Mixed
*/
public function items($cartId) {
return $this->model->find($cartId)->items;
}

View File

@ -140,7 +140,7 @@ class Core
$channel = $this->getCurrentChannel();
$currencyCode = $channel->base_currency;
$currencyCode = $channel->base_currency->code;
return currency($price, $currencyCode);
}

View File

@ -80,7 +80,6 @@ class ChannelController extends Controller
'base_currency' => 'required'
]);
$this->channel->create(request()->all());
session()->flash('success', 'Channel created successfully.');
@ -114,9 +113,9 @@ class ChannelController extends Controller
'code' => ['required', 'unique:channels,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
'name' => 'required',
'locales' => 'required|array|min:1',
'default_locale' => 'required',
'default_locale_id' => 'required',
'currencies' => 'required|array|min:1',
'base_currency' => 'required'
'base_currency_id' => 'required'
]);
$this->channel->update(request()->all(), $id);

View File

@ -5,11 +5,8 @@ namespace Webkul\Customer\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
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

View File

@ -35,9 +35,9 @@ Route::group(['middleware' => ['web']], function () {
// //Routes for product cart
Route::post('products/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add');
Route::post('checkout/cart/add/{id}', 'Webkul\Cart\Http\Controllers\CartController@add')->name('cart.add');
Route::post('product/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove');
Route::post('checkout/cart/remove/{id}', 'Webkul\Cart\Http\Controllers\CartController@remove')->name('cart.remove');
//Routes for product cart ends

View File

@ -6,45 +6,10 @@
</div>
<div class="cart-content">
{{-- {{ dd($products) }} --}}
<div class="left-side">
{{-- <div class="item">
<img class="item-image" src="{{ bagisto_asset('images/jeans_big.jpg') }}" />
<div class="item-details">
<div class="item-title">
Rainbow Creation Embroided
</div>
<div class="price">
<span class="main-price">
$24.00
</span>
<span class="real-price">
$25.00
</span>
<span class="discount">
10% Off
</span>
</div>
<div class="summary">
Color : Gray, Size : S, Sleeve type : Puffed Sleeves, Occasion : Birthday, Marriage Anniversary
</div>
<div class="misc">
<div class="qty-text">Quantity</div>
<div class="box">1</div>
<span class="remove">Remove</span>
<span class="towishlist">Move to Wishlist</span>
</div>
</div>
</div> --}}
@foreach($products as $product)
<div class="item">
<div style="margin-right: 15px;">