Scroll
Drupal Commerce: programmatic output of the "Add to Cart" button
Forums
The question is, I need to programmatically display the "Add to cart" button in the Views template. I'm doing it based on the example http://drupal.org/node/1232470#comment-4801356 and the documentation http://api.drupalcommerce.org/api/Drupal%20Commerce/sites!all!modules!commerce!modules!cart!commerce_cart.module/function/commerce_cart_add_to_cart_form/DC
like this:
<?php // build the line items for shopping cart $line_item = commerce_line_item_new($view['product']->type, $order_id = 0); $line_item->data['context']['product_ids'] = array($view['product']->product_id); $line_item->quantity = 1; // need to create config for quantity $qty = 1; $form_id = commerce_cart_add_to_cart_form_id(array($view['product']->product_id), $qty); $addtocart_form = drupal_get_form($form_id, $line_item); // we alter the submit form to use our special theme function // need to move this to configuration $addtocart_form['submit']['#theme'][] = 'vtcommerce_button_small'; $variables['cart'] = render($addtocart_form); ?> So the button displays correctly, but the widget for adding the quantity of products does not appear, even though $line_item->quantity = 1; and $qty = 1;. The question is: why?