/** * Default constructor for the Commerce Line Item object. Do not call this * class directly. Create a separate class for each line item type and use * its constructor. * * You can also pass a second argument, and it will be interpreted as * order_id. It is used for creating a new line item. * * @param int $line_item_id * Product id if an existing product is to be loaded. */ public function __construct($line_item_id = NULL) { $args = func_get_args(); array_shift($args); $order_id = array_shift($args); if (is_null($order_id)) { $order_id = 0; } if (!is_null($line_item_id) && is_numeric($line_item_id)) { $line_item = commerce_line_item_load($line_item_id); if (!$line_item) { $this->setErrors("Line item with id {$line_item_id} does not exist."); $this->setInitialized(FALSE); return; } } else { $class = new \ReflectionClass(get_called_class()); $type = Utils::makeSnakeCase($class->getShortName()); $line_item = commerce_line_item_new($type, $order_id); } parent::__construct($line_item); }
<div class="views-field-title"><?php print $fields['title']->content; ?> </div> <?php $nid = strip_tags($fields['nid']->content); $node = node_load($nid); $product = commerce_product_load($node->field_product[LANGUAGE_NONE][0]['product_id']); ?> <div class="views-field-field-sell-price"><?php print commerce_currency_format($product->commerce_price[LANGUAGE_NONE][0]['amount'], 'VND'); ?> </div> <div class="views-field-field-old-price"><?php print $fields['field_old_price']->content; ?> </div> <?php $line_item = commerce_line_item_new($product->type, $order_id = 0); $line_item->data['context']['product_ids'] = array($product->product_id); $line_item->quantity = 1; $qty = 1; $form_id = commerce_cart_add_to_cart_form_id(array($product->product_id), $qty); $addtocart_form = drupal_get_form($form_id, $line_item); ?> <div class="views-field-view-node "><?php print render($addtocart_form); ?> </div>