1
votes

Is possible to add Wishlist products with quantity and other attributes to Cart in prestashop?

I used the below code in managewishlist.tpl to add the product to cart and remove it from wishlist.

<a class="button btn-default ajax_add_to_cart_button btn btn-default" 
href="{$link->getPageLink('cart',false, NULL, "add=1&amp;id_product={$product.id_product|intval}&amp;qty={$product.quantity}", false)|escape:'html':'UTF-8'}" 
rel="nofollow" title="{l s='Add to cart'}" 
data-id-product="{$product.id_product|intval}" 
onclick="WishlistProductManage('wlp_bought', 'delete', '{$id_wishlist}', '{$product.id_product}', '{$product.id_product_attribute}', $('#quantity_{$product.id_product}_{$product.id_product_attribute}').val(), $('#priority_{$product.id_product}_{$product.id_product_attribute}').val());">
        <span>{l s='Add to cart'}</span>
</a>

please let me know how to pass the quantity value so that i can get result.

for example if i have one product in wishlist and its quantity is 3.

so when i click on add to cart it should add 3 quantity of the same product.

Also let me know how can i pass color and size attribute that is available in wishlist.

1

1 Answers

2
votes

Code for button (in themes/your_template/modules/blockwishlist/views/templates/front/managewishlist.tpl:

<a class="exclusive button ajax_add_to_cart_button add-to-cart-in-wl" href="{$link->getPageLink('cart', true, NULL, "qty={$product.quantity|intval}&amp;id_product={$product.id_product|intval}&amp;add")|escape:'html':'UTF-8'}" data-id-attribute="{$product.id_product_attribute}" data-id-product="{$product.id_product|intval}" data-minimal_quantity="{$product.quantity|intval}" title="{l s='Add to cart' mod='blockwishlist'}"><span>{l s='Add to cart' mod='blockwishlist'}</span></a>

And you need to change the code in the file themes/your_template/js/modules/blockcart/ajax-cart.js that handles the event "click" on an element ".ajax_add_to_cart_button":

$(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function(e){
e.preventDefault();
var idProduct =  parseInt($(this).data('id-product'));
var idProductAttribute =  parseInt($(this).data('id-product-attribute'));
var minimalQuantity =  parseInt($(this).data('minimal_quantity'));
if ($(this).is('.add-to-cart-in-wl')) {
    quan = $(this).closest('.product_infos').find('.wishlist_product_detail input.form-control').val();
    if (quan != minimalQuantity)
        minimalQuantity = quan;
}
if (!minimalQuantity)
    minimalQuantity = 1;
if ($(this).prop('disabled') != 'disabled')
    ajaxCart.add(idProduct, idProductAttribute, false, this, minimalQuantity);
});