diff --git a/classes/Cart.php b/classes/Cart.php
index b65b691f1..1afc74b67 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -1140,8 +1140,8 @@ class CartCore extends ObjectModel
'SELECT `quantity`
FROM `'._DB_PREFIX_.'cart_product`
WHERE `id_product` = '.(int)$id_product.'
- AND `id_product_attribute` = '.(int)$id_product_attribute
- );
+ AND `id_cart` = '.(int)$this->id.'
+ AND `id_product_attribute` = '.(int)$id_product_attribute);
$customization_quantity = (int)Db::getInstance()->getValue('
SELECT `quantity`
@@ -1151,12 +1151,12 @@ class CartCore extends ObjectModel
AND `id_product_attribute` = '.(int)$id_product_attribute.'
'.((int)$id_address_delivery ? 'AND `id_address_delivery` = '.(int)$id_address_delivery : ''));
- if (!$this->_deleteCustomization((int)$id_customization, (int)$id_product, (int)$id_product_attribute, $id_address_delivery))
+ if (!$this->_deleteCustomization((int)$id_customization, (int)$id_product, (int)$id_product_attribute, (int)$id_address_delivery))
return false;
// refresh cache of self::_products
$this->_products = $this->getProducts(true);
- return ($this->deleteProduct((int)$id_product, $id_product_attribute, $id_address_delivery) && $customization_quantity == $product_total_quantity);
+ return ($customization_quantity == $product_total_quantity && $this->deleteProduct((int)$id_product, (int)$id_product_attribute, null, (int)$id_address_delivery));
}
/* Get customization quantity */
@@ -1165,8 +1165,7 @@ class CartCore extends ObjectModel
FROM `'._DB_PREFIX_.'customization`
WHERE `id_cart` = '.(int)$this->id.'
AND `id_product` = '.(int)$id_product.'
- AND `id_product_attribute` = '.(int)$id_product_attribute
- );
+ AND `id_product_attribute` = '.(int)$id_product_attribute);
if ($result === false)
return false;
@@ -1180,7 +1179,7 @@ class CartCore extends ObjectModel
AND `id_product` = '.(int)$id_product.
($id_product_attribute != null ? ' AND `id_product_attribute` = '.(int)$id_product_attribute : '')
);
-
+
/* Product deletion */
$result = Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'cart_product`
diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php
index 53e379b6d..9d8b593ad 100644
--- a/controllers/front/OrderOpcController.php
+++ b/controllers/front/OrderOpcController.php
@@ -576,16 +576,17 @@ class OrderOpcControllerCore extends ParentOrderController
protected function getFormatedSummaryDetail()
{
$result = array('summary' => $this->context->cart->getSummaryDetails(),
- 'customizedDatas' => Product::getAllCustomizedDatas($this->context->cart->id, null, true)
- );
+ 'customizedDatas' => Product::getAllCustomizedDatas($this->context->cart->id, null, true));
+
foreach ($result['summary']['products'] as $key => &$product)
{
$product['quantity_without_customization'] = $product['quantity'];
if ($result['customizedDatas'])
{
- foreach ($result['customizedDatas'][(int)$product['id_product']][(int)$product['id_product_attribute']] as $addresses)
- foreach ($addresses as $customization)
- $product['quantity_without_customization'] -= (int)$customization['quantity'];
+ if (isset($result['customizedDatas'][(int)$product['id_product']][(int)$product['id_product_attribute']]))
+ foreach ($result['customizedDatas'][(int)$product['id_product']][(int)$product['id_product_attribute']] as $addresses)
+ foreach ($addresses as $customization)
+ $product['quantity_without_customization'] -= (int)$customization['quantity'];
}
}
diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js
index 307bc301c..2eb44e093 100644
--- a/modules/blockcart/ajax-cart.js
+++ b/modules/blockcart/ajax-cart.js
@@ -427,6 +427,7 @@ var ajaxCart = {
if (this.id != undefined)
{
//create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty)
+
if ($('#cart_block dl.products').length == 0)
{
$('#cart_block_no_products').before('
');
@@ -434,9 +435,8 @@ var ajaxCart = {
}
//if product is not in the displayed cart, add a new product's line
var domIdProduct = this.id + '_' + (this.idCombination ? this.idCombination : '0') + '_' + (this.idAddressDelivery ? this.idAddressDelivery : '0');
-
var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0');
- if ($('#cart_block_product_'+ domIdProduct ).length == 0)
+ if ($('#cart_block_product_'+ domIdProduct).length == 0)
{
var productId = parseInt(this.id);
var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0);
@@ -463,10 +463,9 @@ var ajaxCart = {
//else update the product's line
else
{
- var jsonProduct = this;
- if($.trim($('#cart_block_product_' + domIdProduct + ' .quantity').text()) != jsonProduct.quantity || $.trim($('dt#cart_block_product_' + domIdProduct + ' .price').text()) != jsonProduct.priceByLine)
+ var jsonProduct = this;
+ if($.trim($('#cart_block_product_' + domIdProduct + ' .quantity').html()) != jsonProduct.quantity || $.trim($('#cart_block_product_' + domIdProduct + ' .price').html()) != jsonProduct.priceByLine)
{
-
// Usual product
if (!this.is_gift)
$('#cart_block_product_' + domIdProduct + ' .price').text(jsonProduct.priceByLine);
diff --git a/themes/default/js/cart-summary.js b/themes/default/js/cart-summary.js
index 0fead83ce..6531ffd47 100644
--- a/themes/default/js/cart-summary.js
+++ b/themes/default/js/cart-summary.js
@@ -208,22 +208,31 @@ function changeAddressDelivery(obj)
function updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, line)
{
- if (typeof(line) == 'undefined')
- line = $('#product_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery);
+ if (typeof(line) == 'undefined' || line.length == 0)
+ line = $('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery + ', #product_' + id_product + '_' + id_product_attribute + '_nocustom_' + old_id_address_delivery);
+
+ $('.product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).each(function(){
+ $(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery + ' address_' + old_id_address_delivery).addClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery + ' address_' + id_address_delivery);
+ $(this).find('input[name^=quantity_]').each(function(){
+ if (typeof($(this).attr('name')) != 'undefined')
+ $(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery));
+ });
+ $(this).find('a').each(function(){
+ if (typeof($(this).attr('href')) != 'undefined')
+ $(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery));
+ });
+ });
- line.attr('id', 'product_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery);
- line.find('.cart_quantity_input')
- .attr('name', 'quantity_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery);
- line.find('input[name=quantity_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery + '_hidden]')
- .attr('name', 'quantity_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery + '_hidden');
- line.find('#cart_quantity_down_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery)
- .attr('id', 'cart_quantity_down_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery);
- line.find('#cart_quantity_up_' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery)
- .attr('id', 'cart_quantity_up_' + id_product+'_' + id_product_attribute + '_0_' + id_address_delivery);
- line.find('#' + id_product+'_' + id_product_attribute + '_0_' + old_id_address_delivery)
- .attr('id', id_product+'_' + id_product_attribute + '_0_' + id_address_delivery);
- line.find('#select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + old_id_address_delivery)
- .attr('id', 'select_address_delivery_' + id_product+'_' + id_product_attribute + '_' + id_address_delivery);
+ line.attr('id', line.attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('address_' + old_id_address_delivery).addClass('address_' + id_address_delivery).find('span[id^=cart_quantity_custom_], input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){
+ if (typeof($(this).attr('name')) != 'undefined')
+ $(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery));
+ if (typeof($(this).attr('id')) != 'undefined')
+ $(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery));
+ if (typeof($(this).attr('href')) != 'undefined')
+ $(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery));
+ });
+
+ line.find('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).attr('id', 'select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery);
}
function updateQty(val, cart, el)
@@ -236,6 +245,7 @@ function updateQty(val, cart, el)
prefix = '#fancybox-content ';
var id = $(el).attr('name');
+
var exp = new RegExp("^[0-9]+$");
if (exp.test(val) == true)
@@ -267,7 +277,7 @@ function deleteProductFromSummary(id)
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
- if (typeof(ids[2]) !== 'undefined')
+ if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
@@ -326,22 +336,36 @@ function deleteProductFromSummary(id)
if (!customizationId)
refreshOddRow();
});
-
var exist = false;
for (i=0;i 1))
+ exist = true;
+ }
// if all customization removed => delete product line
- if (!exist && customizationId && parseInt($('#cart_quantity_custom_' + productId + (productAttributeId > 0 ? '_' + productAttributeId : '') + '_0_' + id_address_delivery).html()) == 1)
+ if (!exist && customizationId)
$('#product_' + productId + '_' + productAttributeId + '_0_' + id_address_delivery).fadeOut('slow', function() {
$(this).remove();
+ var line = $('#product_' + productId + '_' + productAttributeId + '_nocustom_' + id_address_delivery);
+ if (line.length > 0)
+ {
+ line.find('input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){
+ if (typeof($(this).attr('name')) != 'undefined')
+ $(this).attr('name', $(this).attr('name').replace(/nocustom/, '0'));
+ if (typeof($(this).attr('id')) != 'undefined')
+ $(this).attr('id', $(this).attr('id').replace(/nocustom/, '0'));
+ });
+ line.find('span[id^=total_product_price_]').each(function(){
+ $(this).attr('id', $(this).attr('id').replace(/_nocustom/, ''));
+ });
+ line.attr('id', line.attr('id').replace(/nocustom/, '0'));
+ }
refreshOddRow();
});
}
-
updateCartSummary(jsonData.summary);
updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
@@ -393,10 +417,11 @@ function upQuantity(id, qty)
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
- if (typeof(ids[2]) !== 'undefined')
+ if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
+
$.ajax({
type: 'POST',
headers: { "cache-control": "no-cache" },
@@ -409,12 +434,12 @@ function upQuantity(id, qty)
+'&add=true'
+'&getproductprice=true'
+'&summary=true'
- +'&id_product='+productId
- +'&ipa='+productAttributeId
- +'&id_address_delivery='+id_address_delivery
- + ( (customizationId !== 0) ? '&id_customization='+customizationId : '')
- +'&qty='+qty
- +'&token='+static_token
+ +'&id_product=' + productId
+ +'&ipa=' + productAttributeId
+ +'&id_address_delivery=' + id_address_delivery
+ + ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
+ +'&qty=' + qty
+ +'&token=' + static_token
+'&allow_refresh=1',
success: function(jsonData)
{
@@ -433,7 +458,8 @@ function upQuantity(id, qty)
if (jsonData.refresh)
location.reload();
updateCartSummary(jsonData.summary);
- updateCustomizedDatas(jsonData.customizedDatas);
+ if (customizationId !== 0)
+ updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
if (typeof(getCarrierListAndUpdate) !== 'undefined')
@@ -471,7 +497,7 @@ function downQuantity(id, qty)
productId = parseInt(ids[0]);
if (typeof(ids[1]) !== 'undefined')
productAttributeId = parseInt(ids[1]);
- if (typeof(ids[2]) !== 'undefined')
+ if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
customizationId = parseInt(ids[2]);
if (typeof(ids[3]) !== 'undefined')
id_address_delivery = parseInt(ids[3]);
@@ -515,7 +541,8 @@ function downQuantity(id, qty)
if (jsonData.refresh)
location.reload();
updateCartSummary(jsonData.summary);
- updateCustomizedDatas(jsonData.customizedDatas);
+ if (customizationId !== 0)
+ updateCustomizedDatas(jsonData.customizedDatas);
updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);
@@ -543,37 +570,28 @@ function downQuantity(id, qty)
function updateCartSummary(json)
{
- // Update products prices + discount
var i;
var nbrProducts = 0;
+ var product_list = new Array();
if (typeof json == 'undefined')
return;
$('div.error').fadeOut();
- $('.cart_quantity_input').val(0);
-
- product_list = {};
for (i=0;i product_list[i].price)
initial_price_text = '' + initial_price + '
';
- }
- key_for_blockcart = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_address_delivery;
-
- $('#cart_block_product_'+ key_for_blockcart + ' span.quantity').html(product_list[i].quantity);
+ var key_for_blockcart = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_address_delivery;
+ var key_for_blockcart_nocustom = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + ((product_list[i].quantity_without_customization != product_list[i].quantity)? 'nocustom' : '0') + '_' + product_list[i].id_address_delivery;
if (priceDisplayMethod !== 0)
{
- $('#cart_block_product_' + key_for_blockcart + ' span.price').html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
- $('#product_price_' + key_for_blockcart).html(initial_price_text+current_price);
- $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
+ $('#product_price_' + key_for_blockcart).html(initial_price_text + current_price);
+ if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
+ $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_customization, currencyFormat, currencySign, currencyBlank));
+ else
+ $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
+ if (product_list[i].quantity_without_customization != product_list[i].quantity)
+ $('#total_product_price_' + key_for_blockcart_nocustom).html(formatCurrency(product_list[i].total, currencyFormat, currencySign, currencyBlank));
}
else
- {
- $('#cart_block_product_' + key_for_blockcart + ' span.price').html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
- $('#product_price_' + key_for_blockcart).html(initial_price_text+current_price);
- $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
- }
-
- nbrProducts += parseInt(product_list[i].quantity);
- $('input[name=quantity_' + product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_0_' + product_list[i].id_address_delivery + ']').val(product_list[i].quantity_without_customization);
- $('input[name=quantity_' + product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_0_' + product_list[i].id_address_delivery + '_hidden]').val(product_list[i].quantity_without_customization);
-
- if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined')
- {
- $('#cart_quantity_custom_' + key_for_blockcart)
- .html(product_list[i].customizationQuantityTotal);
- $('input[name=quantity_' + product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_customization + '_' + product_list[i].id_address_delivery + ']').val(product_list[i].customizationQuantityTotal);
+ {
+ $('#product_price_' + key_for_blockcart).html(initial_price_text + current_price);
+ if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
+ $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_customization_wt, currencyFormat, currencySign, currencyBlank));
+ else
+ $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
+ if (product_list[i].quantity_without_customization != product_list[i].quantity)
+ $('#total_product_price_' + key_for_blockcart_nocustom).html(formatCurrency(product_list[i].total_wt, currencyFormat, currencySign, currencyBlank));
}
+ $('input[name=quantity_' + key_for_blockcart_nocustom + ']').val(product_list[i].quantity_without_customization);
+ $('input[name=quantity_' + key_for_blockcart_nocustom + '_hidden]').val(product_list[i].quantity_without_customization);
+ if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0)
+ $('#cart_quantity_custom_' + key_for_blockcart).html(product_list[i].customizationQuantityTotal);
+ nbrProducts += parseInt(product_list[i].quantity);
}
// Update discounts
@@ -644,20 +661,15 @@ function updateCartSummary(json)
var toDelete = true;
for (i=0;i
+
|
@@ -33,7 +33,7 @@
{if $product.reference}{$product.reference|escape:'htmlall':'UTF-8'}{else}--{/if} |
-
+
{if !empty($product.gift)}
{l s='Gift!'}
{else}
@@ -62,25 +62,25 @@
{/if}
{if !isset($customizedDatas.$productId.$productAttributeId) OR $quantityDisplayed > 0}
-
-
+
+
{/if}
{/if}
|
-
+
{if !empty($product.gift)}
{l s='Gift!'}
{else}
@@ -96,7 +96,7 @@
|
{if (!isset($customizedDatas.$productId.$productAttributeId) OR $quantityDisplayed) > 0 && empty($product.gift)}
{/if}
|
diff --git a/themes/default/shopping-cart.tpl b/themes/default/shopping-cart.tpl
index 36a01329a..8b486c2de 100644
--- a/themes/default/shopping-cart.tpl
+++ b/themes/default/shopping-cart.tpl
@@ -230,7 +230,7 @@
{* Then the customized datas ones*}
{if isset($customizedDatas.$productId.$productAttributeId)}
{foreach $customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] as $id_customization=>$customization}
-
+
|
{foreach $customization.datas as $type => $custom_data}
|