Merge branch 'ticket/r12779-lightbox-qty' into develop

This commit is contained in:
Romu 2017-04-03 05:46:35 -07:00
commit 2cca3ea857
4 changed files with 36 additions and 24 deletions

View File

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

View File

@ -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 {

View File

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

View File

@ -14,10 +14,12 @@
<p class="product-name"></p>
<p class="product-attributes">
{l s='Quantité dans votre panier' mod='blockcart'}
<span style="padding-left: 20px" class="update-qty clearfix">
<span class="update-qty clearfix">
<span class="qty-down">-</span>
<span class="nb_quantity"></span>
<span class="qty-up">+</span>
<span class="message success"></span>
<span class="message error"></span>
</span>
</p>
<div class="prices">