Merge branch 'ticket-12574-RemoveProductFromBlockcart'

This commit is contained in:
Marion Muszynski 2017-03-29 10:22:01 +02:00
commit bc8a76bb3d
6 changed files with 85 additions and 23 deletions

View File

@ -62,11 +62,11 @@ var ajaxCart = {
var customizationId = 0;
var productId = 0;
var productAttributeId = 0;
if ($($(this).parent().parent()).attr('name') == 'customization')
if ($($(this).parent().parent().parent()).attr('name') == 'customization')
// Reverse two levels: a >> div >> li
var customizableProductDiv = $($(this).parent().parent()).find("div[id^=deleteCustomizableProduct_]");
var customizableProductDiv = $($(this).parent().parent().parent()).find("div[id^=deleteCustomizableProduct_]");
else
var customizableProductDiv = $($(this).parent()).find("div[id^=deleteCustomizableProduct_]");
var customizableProductDiv = $($(this).parent().parent()).find("div[id^=deleteCustomizableProduct_]");
if (customizableProductDiv && $(customizableProductDiv).length)
{
$(customizableProductDiv).each(function(){
@ -86,7 +86,7 @@ var ajaxCart = {
if (!customizationId)
{
//retrieve idProduct and idCombination from the displayed product in the block cart
var firstCut = $(this).parent().parent().attr('id').replace('cart_block_product_', '');
var firstCut = $(this).parent().parent().parent().attr('id').replace('cart_block_product_', '');
firstCut = firstCut.replace('deleteCustomizableProduct_', '');
ids = firstCut.split('_');
productId = parseInt(ids[0]);
@ -388,18 +388,21 @@ var ajaxCart = {
// Update product quantity
updateProductQuantity : function (product, quantity) {
$('dt#cart_block_product_' + product.id + (product.idCombination ? '_' + product.idCombination : '') + ' .quantity').fadeTo('fast', 0, function() {
$(this).text(quantity);
$(this).fadeTo('fast', 1, function(){
$(this).fadeTo('fast', 0, function(){
$(this).fadeTo('fast', 1, function(){
$(this).fadeTo('fast', 0, function(){
$(this).fadeTo('fast', 1);
var old_quantity = parseInt($('dt#cart_block_product_' + product.id + (product.idCombination ? '_' + product.idCombination : '') + ' .quantity').text());
if(old_quantity != quantity) {
$('dt#cart_block_product_' + product.id + (product.idCombination ? '_' + product.idCombination : '') + ' .quantity').fadeTo('fast', 0, function() {
$(this).text(quantity);
$(this).fadeTo('fast', 1, function(){
$(this).fadeTo('fast', 0, function(){
$(this).fadeTo('fast', 1, function(){
$(this).fadeTo('fast', 0, function(){
$(this).fadeTo('fast', 1);
});
});
});
});
});
});
}
},
@ -426,8 +429,12 @@ var ajaxCart = {
var content = '<dt class="hidden" id="cart_block_product_' + domIdProduct + '">';
content += '<a class="img_cart" href="' + this.link + '" title="' + this.name + '"><img src="' + this.id_image + '" alt="' + this.name +'"></a>';
content += '<a class="cart_block_product_name" href="' + this.link + '" title="' + this.name + '">' + name + '</a>';
content += '<p class="label_quantity">Quantité : <span class="quantity">' + this.quantity + '</span></p>';
content += '<p class="label_quantity">Quantité : ';
content += '<span class="quantity">' + this.quantity + '</span>';
content += ' <a rel="nofollow" class="cart_quantity_down" id="cart_quantity_down_'+productId+'_'+(this.hasAttributes ? parseInt(this.idCombination) : 0)+'" onclick="updateQuantity('+productId+','+(this.hasAttributes ? parseInt(this.idCombination) : 0)+',\'down\');"><img src="'+baseDir+'themes/site/img/moins.png" alt="-" width="13" height="13" /></a>';
content += ' <a rel="nofollow" class="cart_quantity_up" id="cart_quantity_up_'+productId+'_'+(this.hasAttributes ? parseInt(this.idCombination) : 0)+'" onclick="updateQuantity('+productId+','+(this.hasAttributes ? parseInt(this.idCombination) : 0)+',\'up\');"><img src="'+baseDir+'themes/site/img/plus.png" alt="-" width="13" height="13" /></a>';
content += '<span class="remove_link"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseDir + 'cart.php?delete&amp;id_product=' + productId + '&amp;token=' + static_token + (this.hasAttributes ? '&amp;ipa=' + parseInt(this.idCombination) : '') + '"> </a></span>';
content += '</p>';
content += '<p><span class="label_price">Prix unitaire : <span class="green price">' + this.unit_price + '</span></p>';
content += '</dt>';
// if (this.hasAttributes)
@ -715,6 +722,21 @@ function removeAllCart() {
});
}
function updateQuantity(id_product,id_product_attribute,op) {
$.ajax({
type: 'POST',
url: baseDir + 'cart.php',
async: true,
cache: false,
dataType : "json",
data: 'add=1&op='+op+'&id_product='+id_product+'&ipa='+id_product_attribute+'&qty=1&token=' + static_token + '&ajax=true',
success: function(jsonData) {
ajaxCart.updateCart(jsonData);
},
error: function() {alert('ERROR: unable to remove your cart');}
});
}
//when document is loaded...
$(document).ready(function(){

View File

@ -3350,7 +3350,7 @@ table.std tbody td.cart_quantity div, .rte table tbody td.cart_quantity div {
}
table.std tbody td.cart_quantity div#cart_quantity_button, .rte table tbody td.cart_quantity div#cart_quantity_button {
margin-right: 10px;
padding-top: 4px;
padding-top: 2px;
}
table.std tbody td.cart_quantity input.cart_quantity_input, .rte table tbody td.cart_quantity input.cart_quantity_input {
float: right;
@ -7156,3 +7156,28 @@ table#carrierTable tbody td {
border-bottom: 15px solid transparent;
border-right: 15px solid #fff;
}
#cart_block_list .products dt{
position: relative;
}
#cart_block_list .remove_link{
display: inline-block;
position: absolute;
height: 13px;
width: 13px;
/*top:10px;*/
right:0px;
cursor: pointer;
background: url("../img/icon/delete.gif") no-repeat center center #fff;
}
#cart_block_list .remove_link a{
display: block;
width: 100%;
height: 100%;
}
#cart_block_list .cart_quantity_dow,
#cart_block_list .cart_quantity_dup{
text-decoration: none;
}

BIN
themes/site/img/moins.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
themes/site/img/plus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -75,17 +75,32 @@ $(document).ready(function() {
<div id="cart_block_list" class="{if isset($colapseExpandStatus) && $colapseExpandStatus eq 'expanded' || !$ajax_allowed || !isset($colapseExpandStatus)}expanded{else}collapsed{/if}">
{if $products}
<dl class="products">
{foreach from=$products item='product' name='myLoop'}
{foreach from=$products item='product' name='myLoop'}
{assign var='productId' value=$product.id_product}
{assign var='productAttributeId' value=$product.id_product_attribute}
<dt id="cart_block_product_{$product.id_product}{if $product.id_product_attribute}_{$product.id_product_attribute}{/if}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">
<dt id="cart_block_product_{$product.id_product}{if $product.id_product_attribute}_{$product.id_product_attribute}{/if}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">
<a class="img_cart" href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category)}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'mini_carre')}" alt="" align="left" title="{$product.name|escape:htmlall:'UTF-8'|truncate:20}" /></a>
<a class="cart_block_product_name" href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category)}" title="{$product.name|escape:html:'UTF-8'}">
{$product.name|truncate:40:'...'|escape:html:'UTF-8'}</a>
<p class="label_quantity">{l s='Quantité :' mod='blockcartex'} <span class="quantity">{$product.cart_quantity}</span></p>
<span class="remove_link">{if !isset($customizedDatas.$productId.$productAttributeId)}<a rel="nofollow" class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart.php')}?delete&amp;id_product={$product.id_product}&amp;ipa={$product.id_product_attribute}&amp;token={$static_token}" title="{l s='remove this product from my cart' mod='blockcartex'}">&nbsp;</a>{/if}</span>
<p class="label_quantity">{l s='Quantité :' mod='blockcartex'} <span class="quantity">{$product.cart_quantity}</span>
{if isset($page_name) && $page_name != 'order'}
{if $product.minimal_quantity < ($customization.quantity - $quantityDisplayed) OR $product.minimal_quantity <= 1}
<a rel="nofollow" class="cart_quantity_down" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}" onclick="updateQuantity({$product.id_product|intval},{$product.id_product_attribute|intval},'down');" title="{l s='Subtract' mod='blockcartex'}">
<img src="{$img_dir}moins.png" alt="{l s='Subtract'}" width="13" height="13" />
</a>
{else}
<a class="cart_quantity_down" style="opacity: 0.3;" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}" href="#" title="{l s='Subtract' mod='blockcartex'}">
<img src="{$img_dir}moins.png" alt="{l s='Subtract'}" width="13" height="13" />
</a>
{/if}
<a rel="nofollow" class="cart_quantity_up" id="cart_quantity_up_{$product.id_product}_{$product.id_product_attribute}" onclick="updateQuantity({$product.id_product|intval},{$product.id_product_attribute|intval},'up');" title="{l s='Add' mod='blockcartex'}"><img src="{$img_dir}plus.png" alt="{l s='Add'}" width="13" height="13" /></a>
<span class="remove_link">{if !isset($customizedDatas.$productId.$productAttributeId)}<a rel="nofollow" class="ajax_cart_block_remove_link" href="{$link->getPageLink('cart.php')}?delete&amp;id_product={$product.id_product}&amp;ipa={$product.id_product_attribute}&amp;token={$static_token}" title="{l s='remove this product from my cart' mod='blockcartex'}">&nbsp;</a>{/if}</span>
{/if}
</p>
<p><span class="label_price">{l s='Prix unitaire :' mod='blockcartex'}</span> <span class="green price">{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice p="`$product.total`"}{else}{displayWtPrice p="`$product.price_wt`"}{/if}</span>
</p>
</dt>
@ -94,7 +109,7 @@ $(document).ready(function() {
<a href="{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category)}" title="{l s='Product detail'}">{$product.attributes_small}</a>
{/if}
<!-- Customizable datas
<!-- Customizable datas
{if isset($customizedDatas.$productId.$productAttributeId)}
{if !isset($product.attributes_small)}<dd id="cart_block_combination_of_{$product.id_product}{if $product.id_product_attribute}_{$product.id_product_attribute}{/if}" class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if}">{/if}
<ul class="cart_block_customizations" id="customization_{$productId}_{$productAttributeId}">

View File

@ -52,14 +52,14 @@
<a rel="nofollow" class="cart_quantity_delete" id="{$product.id_product}_{$product.id_product_attribute}" href="{$link->getPageLink('cart.php', true)}?delete&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;token={$token_cart}" title="{l s='Delete'}"><img src="{$img_dir}icon/delete.gif" alt="{l s='Delete'}" class="icon" width="13" height="13" /></a>
</div>
<div id="cart_quantity_button">
<a rel="nofollow" class="cart_quantity_up" id="cart_quantity_up_{$product.id_product}_{$product.id_product_attribute}" href="{$link->getPageLink('cart.php', true)}?add&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;token={$token_cart}" title="{l s='Add'}"><img src="{$img_dir}icon/quantity_up.gif" alt="{l s='Add'}" width="14" height="9" /></a><br />
<a rel="nofollow" class="cart_quantity_up" id="cart_quantity_up_{$product.id_product}_{$product.id_product_attribute}" href="{$link->getPageLink('cart.php', true)}?add&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;token={$token_cart}" title="{l s='Add'}"><img src="{$img_dir}plus.png" alt="{l s='Add'}" width="14" height="14" /></a><br />
{if $product.minimal_quantity < ($product.cart_quantity-$quantityDisplayed) OR $product.minimal_quantity <= 1}
<a rel="nofollow" class="cart_quantity_down" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}" href="{$link->getPageLink('cart.php', true)}?add&amp;id_product={$product.id_product|intval}&amp;ipa={$product.id_product_attribute|intval}&amp;op=down&amp;token={$token_cart}" title="{l s='Subtract'}">
<img src="{$img_dir}icon/quantity_down.gif" alt="{l s='Subtract'}" width="14" height="9" />
<img src="{$img_dir}moins.png" alt="{l s='Subtract'}" width="14" height="14" />
</a>
{else}
<a class="cart_quantity_down" style="opacity: 0.3;" href="#" id="cart_quantity_down_{$product.id_product}_{$product.id_product_attribute}" title="{l s='You must purchase a minimum of '}{$product.minimal_quantity}{l s=' of this product.'}">
<img src="{$img_dir}icon/quantity_down.gif" width="14" height="9" alt="{l s='Subtract'}" />
<img src="{$img_dir}moins.png" width="14" height="14" alt="{l s='Subtract'}" />
</a>
{/if}
</div>