Jump to content

Get id_combination for each product in product-list.tpl


Recommended Posts

Hi guys. I was hoping to get some help with something I'm trying to do. I have a wishlist module I purchased for customers to create wishlists and add products to it and such. I would like my customers to be able to add products to their list directly from the category pages displayed using product-list.tpl. However, the module identifies the products by the id_combination id which is not defined for individual products in product-list.tpl . So I was wondering is anyone knew or could come up with a way to create the correct id_combination for each product listed by product-list.tpl.

 

Thanks in advance for your assistance in this matter.

Link to comment
Share on other sites

HI Bodyles,

Yes it is possible to generate the correct id_combination (or the selected ones) at category pages. I am not exactly sure if it is possible without overloading the Category class or not, but Do the following steps.

 

1) Override the Category class and create your own getProducts function. Call the parent::getProducts with all the appropriate parameters in the overloaded getProducts. This will return you the list of the products.

 

2) Now create a for loop and get combinations for all the products one by one and add them to the product list. You have to generate a sub array in the products array for each product like

 

$products['attributes'] = [attributes array or data you got as explained above]

 

3) Now you have combinations in the products list and in product-list.tpl, you can check and display all combinations. If you dont want to display combinations, then you can create a hidden field and give it an id /name like combination_{product_id} . Keep its value the value of the combination for that product. The {product_id} in the id/name of the hidden field will help you to get combination id for a specific product (for product for which the add to wish list button is clicked).

 

4) Now the add to wishlist button has on click event like

 

onclick="WishlistCart('wishlist_block_list', 'add', '{$id_product|intval}', $('#idCombination').val(), document.getElementById('quantity_wanted').value); return false;"

 

{$id_product|intval} = You can get it already in the product-list.tpl

$('#idCombination').val() = As explained above

document.getElementById('quantity_wanted').value = Keep qty one by default, or what ever value you want.

 

And thats it.

 

I am also working on displaying the the add to wishlist button on category pages, and I did, the image flows to the wishlist modle, but it is not adding it to the wishlist. I dont know why, but if you got it worked, then please let me know.

 

I hope my details will help. Let me know if you have any other questions.

 

Thank you

Link to comment
Share on other sites

Hi Bodyles,

The way i explained above is working fine. My wishlist was not working at category pages because of cookies, which when i cleared out, it worked fine. So use the above methode.

Also about your sayings

" However, the module identifies the products by the id_combination id which is not defined for individual products in product-list.tpl "

 

It is not true. The wishlist module takes the combination id, if there is one, then it takes, else it will not take and will use 0 instead.

 

Thank you

Link to comment
Share on other sites

×
×
  • Create New...