From 3feaae97df89d5ccb2f705fc2f9cab1249e3eb27 Mon Sep 17 00:00:00 2001 From: Romu Date: Mon, 3 Apr 2017 05:45:56 -0700 Subject: [PATCH] gestion du 0 + message d'erreur --- override/controllers/front/CartController.php | 5 ++- themes/toutpratique/css/global.css | 10 ++++- .../js/modules/blockcart/ajax-cart.js | 41 ++++++++++--------- .../modules/blockcart/blockcart_footer.tpl | 4 +- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/override/controllers/front/CartController.php b/override/controllers/front/CartController.php index 40e8de0d..9b58f77e 100644 --- a/override/controllers/front/CartController.php +++ b/override/controllers/front/CartController.php @@ -21,7 +21,7 @@ class CartController extends CartControllerCore $qty_to_check = $this->qty; $cart_products = $this->context->cart->getProducts(); - if (is_array($cart_products)) + if (is_array($cart_products) && !Tools::getIsset('fromLightbox')) foreach ($cart_products as $cart_product) { if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) && @@ -54,8 +54,9 @@ class CartController extends CartControllerCore elseif (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty($this->id_product_attribute, $qty_to_check)) $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); } - elseif (!$product->checkQty($qty_to_check)) + elseif (!$product->checkQty($qty_to_check)) { $this->errors[] = Tools::displayError('There isn\'t enough product in stock.', !Tools::getValue('ajax')); + } // If no errors, process product addition if (!$this->errors && $mode == 'add') diff --git a/themes/toutpratique/css/global.css b/themes/toutpratique/css/global.css index edda71c9..1eb64846 100644 --- a/themes/toutpratique/css/global.css +++ b/themes/toutpratique/css/global.css @@ -4616,12 +4616,20 @@ main#categorycms { margin-bottom: 30px } background: #fff; border-left: 1px solid #f0f0f0; border-right: 1px solid #f0f0f0; - float: left; + float: left; height: 30px; padding-top: 5px; width: 40px; text-align: center; } + .layer_cart_product .message { + color: #6ac5bb; + display: block; + float: left; + font-size: 12px; + padding: 8px 0 0 10px; + } + .layer_cart_product .message.error { color: #e4535d } #layer_cart .layer_cart_product .product-infos .prices, #layer_cart_pack .layer_cart_product .product-infos .prices { diff --git a/themes/toutpratique/js/modules/blockcart/ajax-cart.js b/themes/toutpratique/js/modules/blockcart/ajax-cart.js index d85984b3..ecb30264 100644 --- a/themes/toutpratique/js/modules/blockcart/ajax-cart.js +++ b/themes/toutpratique/js/modules/blockcart/ajax-cart.js @@ -1,6 +1,5 @@ $(document).ready(function(){ - ajaxCart.overrideButtonsInThePage(); $(document).on('click', '.block_cart_collapse', function(e){ @@ -72,6 +71,20 @@ $(document).ready(function(){ }); $('#columns #layer_cart, #columns .layer_cart_overlay').detach().prependTo('#columns'); + + $('.update-qty .qty-up').on('click', function() { + qty = parseInt($('.layer_cart_product .nb_quantity').html()) + 1; + idProduct = $(".layer_cart_product .product-id").val(); + + ajaxCart.updateQty(qty, idProduct, null); + }); + + $('.update-qty .qty-down').on('click', function() { + qty = parseInt($('.product-infos .nb_quantity').html()) - 1; + idProduct = idProduct = $(".layer_cart_product .product-id").val(); + + ajaxCart.updateQty(qty, idProduct, null); + }); }); @@ -270,22 +283,6 @@ var ajaxCart = { }); }, - lightboxQty: function() { - $('.update-qty .qty-up').on('click', function() { - qty = parseInt($('.layer_cart_product .nb_quantity').html()) + 1; - idProduct = $(".layer_cart_product .product-id").val(); - - ajaxCart.updateQty(qty, idProduct, null); - }); - - $('.update-qty .qty-down').on('click', function() { - qty = parseInt($('.product-infos .nb_quantity').html()) - 1; - idProduct = idProduct = $(".layer_cart_product .product-id").val(); - - ajaxCart.updateQty(qty, idProduct, null); - }); - }, - updateQty: function(quantity, idProduct, idCombination) { $.ajax({ type: 'POST', @@ -294,11 +291,17 @@ var ajaxCart = { async: true, cache: false, dataType : "json", - data: 'controller=cart&add=1&fromLightbox=true&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), + data: 'controller=cart&add=1&fromLightbox=true&ajax=true&qty=' + quantity + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''), success: function(jsonData,textStatus,jqXHR) { if (!jsonData.hasError) { ajaxCart.updateCart(jsonData); $('.layer_cart_product .nb_quantity').html(quantity); + + $('.message.error').hide(); + $('.message.success').html('Quantité mise à jour avec succés').show(); + } else { + $('.message.success').hide(); + $('.message.error').html(jsonData.errors[0]).show(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) @@ -819,8 +822,6 @@ var ajaxCart = { $('#layer_cart').addClass('open'); $('#layer_cart .panel-overlay').addClass('open'); $('.layer_cart_overlay').fadeIn(); - - ajaxCart.lightboxQty(); } } else { window.location.reload(); diff --git a/themes/toutpratique/modules/blockcart/blockcart_footer.tpl b/themes/toutpratique/modules/blockcart/blockcart_footer.tpl index 8b06ce67..c1a86f71 100644 --- a/themes/toutpratique/modules/blockcart/blockcart_footer.tpl +++ b/themes/toutpratique/modules/blockcart/blockcart_footer.tpl @@ -14,10 +14,12 @@

{l s='Quantité dans votre panier' mod='blockcart'} - + - + + +