fix on basket
This commit is contained in:
@@ -18,6 +18,7 @@ var jsSite = [
|
|||||||
jsBase,
|
jsBase,
|
||||||
jsBootstrap,
|
jsBootstrap,
|
||||||
'node_modules/currency.js/dist/currency.min.js',
|
'node_modules/currency.js/dist/currency.min.js',
|
||||||
|
'build/js/plugins/smooth_products/js/smoothproducts.min.js',
|
||||||
'build/js/site.js',
|
'build/js/site.js',
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ var cssSite = [
|
|||||||
'node_modules/bootstrap/dist/css/bootstrap.min.css',
|
'node_modules/bootstrap/dist/css/bootstrap.min.css',
|
||||||
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
|
||||||
'node_modules/animate.css/animate.min.css',
|
'node_modules/animate.css/animate.min.css',
|
||||||
|
'build/js/plugins/smooth_products/css/smoothproducts.css',
|
||||||
'build/css/shadow.css',
|
'build/css/shadow.css',
|
||||||
'build/css/site.css',
|
'build/css/site.css',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ class BasketController extends Controller
|
|||||||
{
|
{
|
||||||
$offer_id = $request->input('offer_id');
|
$offer_id = $request->input('offer_id');
|
||||||
$quantity = $request->input('quantity');
|
$quantity = $request->input('quantity');
|
||||||
return Offers::addBasket($offer_id, $quantity);
|
$update = $request->input('update') ?? false;
|
||||||
|
return Offers::addBasket($offer_id, $quantity, $update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,18 @@ use \Cart;
|
|||||||
|
|
||||||
class ShopCart
|
class ShopCart
|
||||||
{
|
{
|
||||||
public static function add($item)
|
public static function add($item, $update = false)
|
||||||
{
|
{
|
||||||
|
if (self::has($item['id'])) {
|
||||||
|
if ($update) {
|
||||||
|
self::remove($id);
|
||||||
$ret = self::get()->add($item);
|
$ret = self::get()->add($item);
|
||||||
|
} else {
|
||||||
|
$ret = self::get()->update($item['id'], ['quantity' => $item['quantity']]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$ret = self::get()->add($item);
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'count' => self::count(),
|
'count' => self::count(),
|
||||||
'quantity' => self::getTotalQuantity(),
|
'quantity' => self::getTotalQuantity(),
|
||||||
|
|||||||
@@ -7,22 +7,21 @@ use App\Repositories\Core\User\ShopCart;
|
|||||||
|
|
||||||
class Offers
|
class Offers
|
||||||
{
|
{
|
||||||
public static function addBasket($offer_id, $quantity = 1)
|
public static function addBasket($offer_id, $quantity = 1, $update = false)
|
||||||
{
|
{
|
||||||
if (ShopCart::has($offer_id)) {
|
if (ShopCart::has($offer_id) && !$quantity) {
|
||||||
$ret = ShopCart::remove($offer_id);
|
$ret = ShopCart::remove($offer_id);
|
||||||
}
|
}
|
||||||
$data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false;
|
$data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false;
|
||||||
return $data ? ShopCart::add($data) : false;
|
return $data ? ShopCart::add($data, $update) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFull($id, $sale_channel_id = false)
|
public static function getFull($id, $sale_channel_id = false)
|
||||||
{
|
{
|
||||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||||
return Offer::with([
|
$offer = Offer::with([
|
||||||
'article.article_nature',
|
'article.article_nature',
|
||||||
'article.product',
|
'article.product',
|
||||||
'article.image',
|
|
||||||
'tariff' => function ($query) use ($sale_channel_id) {
|
'tariff' => function ($query) use ($sale_channel_id) {
|
||||||
$query->bySaleChannel($sale_channel_id);
|
$query->bySaleChannel($sale_channel_id);
|
||||||
},
|
},
|
||||||
@@ -32,6 +31,8 @@ class Offers
|
|||||||
'tariff.price_lists.price_list_values',
|
'tariff.price_lists.price_list_values',
|
||||||
'variation',
|
'variation',
|
||||||
])->find($id);
|
])->find($id);
|
||||||
|
$offer->article->image = Articles::getFullImageByArticle($offer->article);
|
||||||
|
return $offer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPrice($id, $quantity = 1, $sale_channel_id = false)
|
public static function getPrice($id, $quantity = 1, $sale_channel_id = false)
|
||||||
@@ -56,7 +57,7 @@ class Offers
|
|||||||
'quantity' => (int) $item->quantity,
|
'quantity' => (int) $item->quantity,
|
||||||
'price' => $item->price,
|
'price' => $item->price,
|
||||||
'variation' => $offer->variation->name,
|
'variation' => $offer->variation->name,
|
||||||
'image' => Articles::getPreviewSrc($offer->article->image),
|
'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $data ?? false;
|
return $data ?? false;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
@component('components.card', ['class' => 'shadow'])
|
@component('components.card', ['class' => 'shadow bg-light'])
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-6 text-uppercase">
|
<div class="col-6 text-uppercase">
|
||||||
Tarif appliqué
|
Tarif appliqué
|
||||||
@@ -74,8 +74,10 @@
|
|||||||
|
|
||||||
$('.basket-quantity').change(function() {
|
$('.basket-quantity').change(function() {
|
||||||
var offer_id = $(this).data('id');
|
var offer_id = $(this).data('id');
|
||||||
quantity = $('.basket-quantity').value;
|
var quantity = $(this).val();
|
||||||
addBasket(offer_id, quantity, function() {
|
console.log("add basket");
|
||||||
|
console.log(quantity);
|
||||||
|
updateBasket(offer_id, quantity, function() {
|
||||||
calculatePrice($(this).parents('.basket-row'));
|
calculatePrice($(this).parents('.basket-row'));
|
||||||
calculateTotal();
|
calculateTotal();
|
||||||
});
|
});
|
||||||
@@ -83,15 +85,15 @@
|
|||||||
|
|
||||||
$('.basket-delete').click(function() {
|
$('.basket-delete').click(function() {
|
||||||
var offer_id = $(this).data('id');
|
var offer_id = $(this).data('id');
|
||||||
addBasket(offer_id, 0, function() {
|
updateBasket(offer_id, 0, function() {
|
||||||
$('#basket_offer-' + offer_id).remove();
|
$('#basket_offer-' + offer_id).remove();
|
||||||
calculateTotal();
|
calculateTotal();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBasket(offer_id, quantity, callback) {
|
function updateBasket(offer_id, quantity, callback) {
|
||||||
var data = {offer_id: offer_id, quantity: 0};
|
var data = {offer_id: offer_id, quantity: quantity, update: true};
|
||||||
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
|
$.post("{{ route('Shop.Basket.addBasket') }}", data, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user