Scroll
Drupal Commerce: 「カートに追加」ボタンのプログラムによる出力
フォーラム
質問があります。Viewsのテンプレートで「Add to cart」ボタンをプログラム的に出力する必要があります。http://drupal.org/node/1232470#comment-4801356の例と、http://api.drupalcommerce.org/api/Drupal%20Commerce/sites!all!modules!commerce!modules!cart!commerce_cart.module/function/commerce_cart_add_to_cart_form/DCのドキュメントを参考にやってみています
次のようにしています:
<?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);
?>
ボタン自体は正常に表示されるのですが、商品の数量を追加するウィジェットが表示されません。
$line_item->quantity = 1; と $qty = 1; を指定しているのですが。
質問:なぜでしょうか?
- コメントを投稿するにはログインしてください