I display my products through the category menu, so that when you click it, it shows the list of all the items in that category, ie: http://website/product-category/pasta

I want to have an "add to cart" button below the image and descriptions of every single items.

How can i do that?

thank you.

3 Answers 3


Here's the code I that built the add to cart button using a specific product_id:


$form_id = commerce_cart_add_to_cart_form_id(array($product->product_id));
$line_item = commerce_product_line_item_new($product);
$line_item->data['context']['product_ids'] = array($product->product_id);

$form = drupal_get_form($form_id, $line_item);
// render your $form somewhere


If you have created a page like below using view then add "Add to cart form" field available on views.


But if you are opening taxonomy default detail page where all item related to that category are showing then just go to your "Product Display" content type and click on manage display. Here you can find default and teaser view mode. Edit teaser view mode and drag your "Product Display content type" field to enabled area. Set label of the Product display to hidden and format should be "Add to cart form".


thank you.

I did find a solution on IRC drupal chat.

My issue was that i didn't had any relationship on the page, that's why i couldn't find the field.

So i did create a relationship: Indexed Node: Product and then i was able to add the field Product) Commerce Product: Add to Cart form.

thanks to everyone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.