0

I'm working on a website made with D7 and the Commerce Module, with a "Products" view (for the Product content type) having this relationship field:

(Products referenced by field_info_prodotto) Commerce Product: Add to Cart form

I want this "Buy Now" button/form to also be inside each products' page (= in the template for the Product content type).

I can create a template for single nodes (see code), but how should I edit the general template (node--product-display.tpl.php)?

# node--181.tpl.php    
<form class="commerce-add-to-cart commerce-cart-add-to-cart-form-24" autocomplete="off"
action="/en/products" method="post" id="commerce-cart-add-to-cart-form-24" accept-charset="UTF-8">
<div><input type="hidden" name="product_id" value="24">
<input type="hidden" name="form_id" value="commerce_cart_add_to_cart_form_24">
<input name='form_token' type='hidden' value='<?php print drupal_get_token('commerce_cart_add_to_cart_form_24'); ?>'>
<div id="edit-line-item-fields--9" class="form-wrapper"></div><input type="hidden" name="quantity"
value="1">
<input type="submit" id="edit-submit--9" name="op" value="Add to cart" class="form-submit">
</div>
</form>

(In the template there is already the code to show a "Buy Now" field - field_tab_5 - but that's just an empty text field and I suppose it's not what I'm after).

4
  • So, do you need only Add to cart form template? May 26, 2019 at 15:45
  • Yes, that's it. I edited the question to make it more understandable.
    – CharlesM
    May 26, 2019 at 17:18
  • Can you please share the .tpl file name where you added your form? May 26, 2019 at 19:52
  • I have added a form for a single node (node--181.tpl.php) and I could do the same for all the other nodes, but I'm looking for the way to edit only node--product-display.tpl.php
    – CharlesM
    May 26, 2019 at 22:30

1 Answer 1

0

Found a solution!

  • Add a field of type "Product reference" to the Product content type ("Inline entity form - Multiple values" as widget)
  • Use "Add to Cart Form" to its display format
  • Field API in node--product-display.tpl.php:

    print render($content['field_info_prodotto']);

Your Answer

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

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