Bug fixes and cart operations optimization
This commit is contained in:
parent
9df49c07d3
commit
a631a07674
|
|
@ -4,6 +4,7 @@
|
|||
/public/css
|
||||
/public/js
|
||||
/public/vendor
|
||||
/public/themes/*
|
||||
/storage/*.key
|
||||
/vendor
|
||||
/.idea
|
||||
|
|
|
|||
|
|
@ -94,27 +94,24 @@ class Cart {
|
|||
{
|
||||
$product = $this->product->findOneByField('id', $productId);
|
||||
|
||||
unset($data['_token']);
|
||||
// dd($product);
|
||||
|
||||
//Check if the product is saleable
|
||||
//Check if the product's information is proper or not.
|
||||
if(!isset($data['product']) || !isset($data['quantity'])) {
|
||||
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_fields'));
|
||||
|
||||
return redirect()->back();
|
||||
return false;
|
||||
} else {
|
||||
if($product->type == 'configurable' && !isset($data['super_attribute'])) {
|
||||
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_options'));
|
||||
|
||||
return redirect()->back();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$child = $childData = null;
|
||||
if($product->type == 'configurable') {
|
||||
//Check if the product is salable
|
||||
$child = $this->product->findOneByField('id', $data['selected_configurable_option']);
|
||||
|
||||
//child row data
|
||||
$childData = [
|
||||
'product_id' => $data['selected_configurable_option'],
|
||||
'sku' => $child->sku,
|
||||
|
|
@ -123,8 +120,8 @@ class Cart {
|
|||
];
|
||||
}
|
||||
|
||||
|
||||
$price = ($product->type == 'configurable' ? $child->price : $product->price);
|
||||
|
||||
$parentData = [
|
||||
'sku' => $product->sku,
|
||||
'product_id' => $productId,
|
||||
|
|
@ -153,14 +150,20 @@ class Cart {
|
|||
*/
|
||||
public function add($id, $data)
|
||||
{
|
||||
|
||||
$itemData = $this->prepareItemData($id, $data);
|
||||
|
||||
if($itemData == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($cart = $this->getCart()) {
|
||||
$product = $this->product->find($id);
|
||||
|
||||
$cartItems = $cart->items;
|
||||
|
||||
if($cartItems->count()) {
|
||||
//check the isset conditions as collection empty object will mislead the condition and errorhandling case.
|
||||
if(isset($cartItems) && $cartItems->count()) {
|
||||
foreach($cartItems as $cartItem) {
|
||||
if($product->type == "simple") {
|
||||
|
||||
|
|
@ -173,7 +176,7 @@ class Cart {
|
|||
if($canBe == false) {
|
||||
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
||||
|
||||
return redirect()->back();
|
||||
return false;
|
||||
}
|
||||
|
||||
$cartItem->update([
|
||||
|
|
@ -186,7 +189,7 @@ class Cart {
|
|||
|
||||
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
|
||||
|
||||
return redirect()->back();
|
||||
return true;
|
||||
}
|
||||
} else if($product->type == "configurable") {
|
||||
if($cartItem->type == "configurable") {
|
||||
|
|
@ -205,7 +208,7 @@ class Cart {
|
|||
if($canBe == false) {
|
||||
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
||||
|
||||
return redirect()->back();
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent->update([
|
||||
|
|
@ -218,7 +221,7 @@ class Cart {
|
|||
|
||||
session()->flash('success', trans('shop::app.checkout.cart.quantity.success'));
|
||||
|
||||
return redirect()->back();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -257,12 +260,17 @@ class Cart {
|
|||
* @param integer $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return Response
|
||||
* @return Booleans
|
||||
*/
|
||||
public function createNewCart($id, $data)
|
||||
{
|
||||
$itemData = $this->prepareItemData($id, $data);
|
||||
|
||||
//if the item data is not valid to be processed it will be returning false
|
||||
if($itemData == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cartData['channel_id'] = core()->getCurrentChannel()->id;
|
||||
|
||||
//auth user details else they will be set when the customer is guest
|
||||
|
|
@ -276,9 +284,16 @@ class Cart {
|
|||
$cartData['is_guest'] = 1;
|
||||
}
|
||||
|
||||
//set the currency column with the respective currency
|
||||
$cartData['global_currency_code'] = core()->getBaseCurrencyCode();
|
||||
$cartData['base_currency_code'] = core()->getBaseCurrencyCode();
|
||||
$cartData['channel_currency_code'] = core()->getBaseCurrencyCode();
|
||||
$cartData['cart_currency_code'] = core()->getBaseCurrencyCode();
|
||||
//set the cart items and quantity
|
||||
$cartData['items_count'] = 1;
|
||||
$cartData['items_qty'] = $data['quantity'];
|
||||
|
||||
//create the cart instance in the database
|
||||
if($cart = $this->cart->create($cartData)) {
|
||||
$itemData['parent']['cart_id'] = $cart->id;
|
||||
$product = $this->product->find($id);
|
||||
|
|
@ -332,14 +347,19 @@ class Cart {
|
|||
|
||||
$guestCart = session()->get('cart');
|
||||
|
||||
//when the logged in customer is not having any of the cart instance previously and are active.
|
||||
if(!isset($cart)) {
|
||||
$guestCart->update(['customer_id' => auth()->guard('customer')->user()->id, 'is_guest' => 0]);
|
||||
$guestCart->update([
|
||||
'customer_id' => auth()->guard('customer')->user()->id,
|
||||
'is_guest' => 0,
|
||||
'customer_first_name' => auth()->guard('customer')->user()->first_name,
|
||||
'customer_last_name' => auth()->guard('customer')->user()->last_name,
|
||||
'customer_email' => auth()->guard('customer')->user()->email
|
||||
]);
|
||||
|
||||
session()->forget('cart');
|
||||
|
||||
session()->put('cart', $guestCart);
|
||||
|
||||
return redirect()->back();
|
||||
return true;
|
||||
}
|
||||
|
||||
$cartItems = $cart->items;
|
||||
|
|
@ -360,9 +380,8 @@ class Cart {
|
|||
$canBe = $this->canAddOrUpdate($cartItem->id, $prevQty + $newQty);
|
||||
|
||||
if($canBe == false) {
|
||||
session()->flash('warning', 'The requested quantity is not available, please try back later.');
|
||||
|
||||
return redirect()->back();
|
||||
$this->cartItem->delete($guestCartItem->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
$cartItem->update([
|
||||
|
|
@ -388,9 +407,8 @@ class Cart {
|
|||
$canBe = $this->canAddOrUpdate($cartItem->child->id, $prevQty + $newQty);
|
||||
|
||||
if($canBe == false) {
|
||||
session()->flash('warning', 'The requested quantity is not available, please try back later.');
|
||||
|
||||
return redirect()->back();
|
||||
$this->cartItem->delete($guestCartItem->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
$cartItem->update([
|
||||
|
|
@ -404,9 +422,9 @@ class Cart {
|
|||
$guestCartItems->forget($key);
|
||||
|
||||
//child will be deleted first
|
||||
$this->cartItem->delete($guestCartItemChild->id);
|
||||
// $this->cartItem->delete($guestCartItemChild->id);
|
||||
|
||||
//then parent will get deleted
|
||||
//then parent will also delete the child if any
|
||||
$this->cartItem->delete($guestCartItem->id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class RegistrationController extends Controller
|
|||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
|
||||
// dd(request()->input());
|
||||
$request->validate([
|
||||
|
||||
'first_name' => 'string|required',
|
||||
|
|
@ -65,8 +65,6 @@ class RegistrationController extends Controller
|
|||
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
// $registrationData = $request->except('_token');
|
||||
|
||||
if ($this->customer->create($data)) {
|
||||
|
||||
session()->flash('success', 'Account created successfully.');
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class CartController extends Controller
|
|||
|
||||
public function add($id) {
|
||||
$data = request()->input();
|
||||
|
||||
// dd($data);
|
||||
Cart::add($id, $data);
|
||||
|
||||
return redirect()->back();
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ section.slider-block {
|
|||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
// cursor: pointer;
|
||||
|
||||
ul.account-dropdown-container {
|
||||
float: right;
|
||||
|
|
@ -289,6 +289,32 @@ section.slider-block {
|
|||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-right: 14px;
|
||||
|
||||
.dropdown-list {
|
||||
width: 300px;
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
padding: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
ul.account-dropdown-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
li > a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn {
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +360,7 @@ section.slider-block {
|
|||
}
|
||||
|
||||
.dropdown-cart > .dropdown-header i{
|
||||
cursor: pointer;
|
||||
// cursor: pointer;
|
||||
float: right;
|
||||
height: 22px;
|
||||
width: 22px;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ return [
|
|||
'home' => [
|
||||
'page-title' => 'Bagisto - Home',
|
||||
'featured-products' => 'Featured Products',
|
||||
'new-products' => 'New Products'
|
||||
'new-products' => 'New Products',
|
||||
|
||||
'product-card' => [
|
||||
'add-to-cart' => 'ADD TO CART'
|
||||
]
|
||||
],
|
||||
|
||||
'customer' => [
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
<div class="signup-confirm" :class="[errors.has('agreement') ? 'has-error' : '']">
|
||||
<span class="checkbox">
|
||||
<input type="checkbox" id="checkbox2" name="agreement" v-validate="'required|confirmed'">
|
||||
<input type="checkbox" id="checkbox2" name="agreement" v-validate="'required'">
|
||||
<label class="checkbox-view" for="checkbox2"></label>
|
||||
<span>{{ __('shop::app.customer.signup-form.agree') }}
|
||||
<a href="">{{ __('shop::app.customer.signup-form.terms') }}</a> & <a href="">{{ __('shop::app.customer.signup-form.conditions') }}</a> {{ __('shop::app.customer.signup-form.using') }}.
|
||||
|
|
|
|||
|
|
@ -28,14 +28,15 @@
|
|||
<i class="icon arrow-down-icon active"></i>
|
||||
</div>
|
||||
</div>
|
||||
@guest
|
||||
@guest('customer')
|
||||
<div class="dropdown-list bottom-right" style="display: none;">
|
||||
<div class="dropdown-container">
|
||||
<label>Account</label>
|
||||
<label>Account</label><br/>
|
||||
<span style="font-size: 12px;">Manage Cart, Orders & Wishlist.</span>
|
||||
<ul class="account-dropdown-list">
|
||||
<li><a href="{{ route('customer.session.index') }}">Sign In</a></li>
|
||||
<li><a class="btn btn-primary btn-sm" href="{{ route('customer.session.index') }}">Sign In</a></li>
|
||||
|
||||
<li><a href="{{ route('customer.register.index') }}">Sign Up</a></li>
|
||||
<li><a class="btn btn-primary btn-sm" href="{{ route('customer.register.index') }}">Sign Up</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
@ -43,7 +44,7 @@
|
|||
</div>
|
||||
@endguest
|
||||
@auth('customer')
|
||||
<div class="dropdown-list bottom-right" style="display: none;">
|
||||
<div class="dropdown-list bottom-right" style="display: none; max-width: 230px;">
|
||||
<div class="dropdown-container">
|
||||
<label>Account</label>
|
||||
<ul>
|
||||
|
|
@ -150,7 +151,7 @@
|
|||
<div class="dropdown-footer">
|
||||
<a href="{{ route('shop.checkout.cart.index') }}">View Shopping Cart</a>
|
||||
|
||||
<button class="btn btn-primary btn-lg">CHECKOUT</button>
|
||||
<button class="btn btn-primary btn-lg"><a style="color: white;" href="{{ route('shop.checkout.onepage.index') }}">CHECKOUT</a></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
<div class="product-name">
|
||||
|
||||
{{ $product->id }}
|
||||
|
||||
<a href="" title="{{ $product->name }}">
|
||||
<span>{{ $product->name }}</span>
|
||||
<a href="{{ url()->to('/').'/products/'.$product->url_key }}" title="{{ $product->name }}">
|
||||
<span>
|
||||
{{ $product->name }}
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -852,7 +852,6 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container {
|
||||
|
|
@ -871,6 +870,41 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
margin-right: 14px;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container li.account-dropdown .dropdown-list {
|
||||
width: 300px;
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container li.account-dropdown .dropdown-container {
|
||||
padding: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container li.account-dropdown ul.account-dropdown-list {
|
||||
display: -webkit-box;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
-webkit-box-orient: horizontal;
|
||||
-webkit-box-direction: normal;
|
||||
-ms-flex-direction: row;
|
||||
flex-direction: row;
|
||||
-webkit-box-pack: justify;
|
||||
-ms-flex-pack: justify;
|
||||
justify-content: space-between;
|
||||
-webkit-box-align: center;
|
||||
-ms-flex-align: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container li.account-dropdown ul.account-dropdown-list li > a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.account-dropdown-container li.account-dropdown ul.account-dropdown-list .btn {
|
||||
min-width: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header .header-top div.right-content ul.cart-dropdown-container {
|
||||
float: right;
|
||||
margin-left: 10px;
|
||||
|
|
@ -926,7 +960,6 @@ section.slider-block div.slider-content div.slider-control .light-right-icon {
|
|||
}
|
||||
|
||||
.header .header-top div.right-content ul.cart-dropdown-container li.cart-dropdown .dropdown-list .dropdown-container .dropdown-cart > .dropdown-header i {
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
height: 22px;
|
||||
width: 22px;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue