/** * {@inheritdoc} */ public function view(OrderInterface $order, $view_mode) { $build = array('#type' => 'table', '#attributes' => array('class' => array('order-pane-table')), '#header' => array('qty' => array('data' => $this->t('Quantity'), 'class' => array('qty')), 'product' => array('data' => $this->t('Product'), 'class' => array('product')), 'model' => array('data' => $this->t('SKU'), 'class' => array('sku', RESPONSIVE_PRIORITY_LOW)), 'cost' => array('data' => $this->t('Cost'), 'class' => array('cost', RESPONSIVE_PRIORITY_LOW)), 'price' => array('data' => $this->t('Price'), 'class' => array('price')), 'total' => array('data' => $this->t('Total'), 'class' => array('price'))), '#empty' => $this->t('This order contains no products.')); $account = \Drupal::currentUser(); if (!$account->hasPermission('administer products')) { unset($build['#header']['cost']); } // @todo Replace with Views. foreach ($order->products as $id => $product) { $build[$id]['qty'] = array('#theme' => 'uc_qty', '#qty' => $product->qty->value, '#cell_attributes' => array('class' => array('qty'))); if ($product->nid->entity && $product->nid->entity->access('view')) { $title = Link::createFromRoute($product->title->value, 'entity.node.canonical', ['node' => $product->nid->target_id])->toString(); } else { $title = $product->title->value; } $build[$id]['product'] = array('#markup' => $title . uc_product_get_description($product), '#cell_attributes' => array('class' => array('product'))); $build[$id]['model'] = array('#markup' => $product->model->value, '#cell_attributes' => array('class' => array('sku'))); if ($account->hasPermission('administer products')) { $build[$id]['cost'] = array('#theme' => 'uc_price', '#price' => $product->cost->value, '#cell_attributes' => array('class' => array('cost'))); } $build[$id]['price'] = array('#theme' => 'uc_price', '#price' => $product->price->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('price'))); $build[$id]['total'] = array('#theme' => 'uc_price', '#price' => $product->price->value * $product->qty->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('total'))); // $build[$id][$field]['#wrapper_attributes']['class'] = $build['#header'][$field]['class']; } return $build; }
/** * {@inheritdoc} */ public function buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) { parent::buildContent($entities, $displays, $view_mode, $langcode); foreach ($entities as $product) { $product->content['qty'] = array('#theme' => 'uc_qty', '#qty' => $product->qty->value, '#cell_attributes' => array('class' => array('qty'))); $node = node_load($product->nid->target_id); $title = $node->access('view') ? \Drupal::l($product->title->value, new Url('entity.node.canonical', array('node' => $product->nid->target_id))) : $product->title->value; $product->content['product'] = array('#markup' => $title . uc_product_get_description($product), '#cell_attributes' => array('class' => array('product'))); $product->content['model'] = array('#markup' => $product->model->value, '#cell_attributes' => array('class' => array('sku'))); $account = \Drupal::currentUser(); if ($account->hasPermission('administer products')) { $product->content['cost'] = array('#theme' => 'uc_price', '#price' => $product->cost->value, '#cell_attributes' => array('class' => array('cost'))); } $product->content['price'] = array('#theme' => 'uc_price', '#price' => $product->price->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('price'))); $product->content['total'] = array('#theme' => 'uc_price', '#price' => $product->price->value * $product->qty->value, '#suffixes' => array(), '#cell_attributes' => array('class' => array('total'))); } }
/** * Controls the display of an item in the cart. * * Product type modules allow the creation of nodes that can be added to the * cart. The cart determines how they are displayed through this hook. This is * especially important for product kits, because it may be displayed as a * single unit in the cart even though it is represented as several items. * * This hook is only called for the module that owns the cart item in * question, as set in $item->module. * * @param $item * The item in the cart to display. * * @return * A form array containing the following elements: * - "nid" * - #type: value * - #value: The node id of the $item. * - "module" * - #type: value * - #value: The module implementing this hook and the node represented by * $item. * - "remove" * - #type: submit * - #value: t('Remove'); when clicked, will remove $item from the cart. * - "description" * - #type: markup * - #value: Themed markup (usually an unordered list) displaying extra * information. * - "title" * - #type: markup * - #value: The displayed title of the $item. * - "#total" * - "type": float * - "value": Numeric price of $item. Notice the '#' signifying that this is * not a form element but just a value stored in the form array. * - "data" * - #type: hidden * - #value: The serialized $item->data. * - "qty" * - #type: textfield * - #value: The quantity of $item in the cart. When "Update cart" is * clicked, the customer's input is saved to the cart. */ function hook_cart_display($item) { $node = node_load($item->nid); $element = array(); $element['nid'] = array('#type' => 'value', '#value' => $node->nid); $element['module'] = array('#type' => 'value', '#value' => 'uc_product'); $element['remove'] = array('#type' => 'checkbox'); $element['title'] = array('#value' => node_access('view', $node) ? l($item->title, 'node/' . $node->nid) : check_plain($item->title)); $context = array('revision' => 'altered', 'type' => 'cart_item', 'subject' => array('cart_item' => $item, 'node' => $node)); $price_info = array('price' => $item->price, 'qty' => $item->qty); $element['#total'] = uc_price($price_info, $context); $element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data)); $element['qty'] = array('#type' => 'textfield', '#default_value' => $item->qty, '#size' => 5, '#maxlength' => 6); if ($description = uc_product_get_description($item)) { $element['description'] = array('#value' => $description); } return $element; }
/** * Controls the display of an item in the cart. * * Product type modules allow the creation of nodes that can be added to the * cart. The cart determines how they are displayed through this hook. This is * especially important for product kits, because it may be displayed as a * single unit in the cart even though it is represented as several items. * * This hook is only called for the module that owns the cart item in * question, as set in $item->module. * * @param $item * The item in the cart to display. * * @return * A form array containing the following elements: * - "nid" * - #type: value * - #value: The node id of the $item. * - "module" * - #type: value * - #value: The module implementing this hook and the node represented by * $item. * - "remove" * - #type: submit * - #value: t('Remove'); when clicked, will remove $item from the cart. * - "description" * - #type: markup * - #value: Themed markup (usually an unordered list) displaying extra * information. * - "title" * - #type: markup * - #value: The displayed title of the $item. * - "#total" * - type: float * - value: Numeric price of $item. Notice the '#' signifying that this is * not a form element but just a value stored in the form array. * - "data" * - #type: hidden * - #value: The serialized $item->data. * - "qty" * - #type: textfield * - #value: The quantity of $item in the cart. When "Update cart" is * clicked, the customer's input is saved to the cart. */ function hook_uc_cart_display($item) { $node = node_load($item->nid); $element = array(); $element['nid'] = array('#type' => 'value', '#value' => $node->id()); $element['module'] = array('#type' => 'value', '#value' => 'uc_product'); $element['remove'] = array('#type' => 'checkbox'); $element['title'] = array('#markup' => $node->access('view') ? \Drupal\Core\Link::createFromRoute($item->title, 'entity.node.canonical', ['node' => $item->nid])->toString() : $item->title); $element['#total'] = $item->price * $item->qty; $element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data)); $element['qty'] = array('#type' => 'textfield', '#default_value' => $item->qty, '#size' => 5, '#maxlength' => 6); if ($description = uc_product_get_description($item)) { $element['description'] = array('#markup' => $description); } return $element; }
/** * Controls the display of an item in the cart. * * Product type modules allow the creation of nodes that can be added to the * cart. The cart determines how they are displayed through this hook. This is * especially important for product kits, because it may be displayed as a * single unit in the cart even though it is represented as several items. * * This hook is only called for the module that owns the cart item in * question, as set in $item->module. * * @param $item * The item in the cart to display. * * @return * A form array containing the following elements: * - "nid" * - #type: value * - #value: The node id of the $item. * - "module" * - #type: value * - #value: The module implementing this hook and the node represented by * $item. * - "remove" * - #type: submit * - #value: t('Remove'); when clicked, will remove $item from the cart. * - "description" * - #type: markup * - #value: Themed markup (usually an unordered list) displaying extra * information. * - "title" * - #type: markup * - #value: The displayed title of the $item. * - "#total" * - type: float * - value: Numeric price of $item. Notice the '#' signifying that this is * not a form element but just a value stored in the form array. * - "data" * - #type: hidden * - #value: The serialized $item->data. * - "qty" * - #type: textfield * - #value: The quantity of $item in the cart. When "Update cart" is * clicked, the customer's input is saved to the cart. */ function hook_uc_cart_display($item) { $node = node_load($item->nid); $element = array(); $element['nid'] = array('#type' => 'value', '#value' => $node->nid); $element['module'] = array('#type' => 'value', '#value' => 'uc_product'); $element['remove'] = array('#type' => 'checkbox'); $element['title'] = array('#markup' => node_access('view', $node) ? l($item->title, 'node/' . $node->nid) : check_plain($item->title)); $element['#total'] = $item->price * $item->qty; $element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data)); $element['qty'] = array('#type' => 'textfield', '#default_value' => $item->qty, '#size' => 5, '#maxlength' => 6); if ($description = uc_product_get_description($item)) { $element['description'] = array('#markup' => $description); } return $element; }
function tendu_cart_review_table($show_subtotal = TRUE) { $subtotal = 0; // Set up table header. $header = array(array('data' => t('Your Items'), 'class' => 'image'), array('data' => t(''), 'class' => 'desc'), array('data' => t('Item Price'), 'class' => 'itemprice'), array('data' => t('Quantity'), 'class' => 'qty'), array('data' => t('Price'), 'class' => 'price')); $context = array(); // Set up table rows. $contents = uc_cart_get_contents(); foreach ($contents as $item) { $price_info = array('price' => $item->price, 'qty' => $item->qty); $context['revision'] = 'altered'; $context['type'] = 'cart_item'; $context['subject'] = array('cart' => $contents, 'cart_item' => $item, 'node' => node_load($item->nid)); $total = uc_price($price_info, $context); $subtotal += $total; $prodnode = $context['subject']['node']; $description = l($prodnode->title, 'node/' . $prodnode->nid) . uc_product_get_description($item); // Remove node from context to prevent the price from being altered. $context['revision'] = 'themed-original'; $context['type'] = 'amount'; // dsm($item); unset($context['subject']); // dsm($prodnode); $prodimg = l('<img src="' . imagecache_create_url('cart', $prodnode->field_image_cache[0]['filepath']) . '"/>', 'node/' . $prodnode->nid, array('html' => true)); $rows[] = array(array('data' => $prodimg, 'class' => 'image'), array('data' => $description, 'class' => 'desc'), array('data' => t('@qty', array('@qty' => $item->price)), 'class' => 'itemprice'), array('data' => t('@qty×', array('@qty' => $item->qty)), 'class' => 'qty'), array('data' => uc_price($total, $context), 'class' => 'price')); unset($prodimg); } // Add the subtotal as the final row. if ($show_subtotal) { $context = array('revision' => 'themed-original', 'type' => 'amount'); $rows[] = array('data' => array(array('data' => '<span id="backtocart-link">' . l('Back to cart', 'cart/') . '</span> ', 'colspan' => 2, 'class' => 'backtocart-wrapper'), array('data' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ' . uc_price($subtotal, $context), 'colspan' => 3, 'class' => 'subtotal')), 'class' => 'lastrow'); } $output = '<div class="tableheader">' . t('Currently In Your Shopping Cart') . '</div>'; return $output . theme('table', $header, $rows, array('class' => 'cart-review')); }