Skip to content

Instantly share code, notes, and snippets.

@mordonez
Created March 22, 2012 14:24
Show Gist options
  • Save mordonez/2158606 to your computer and use it in GitHub Desktop.
Save mordonez/2158606 to your computer and use it in GitHub Desktop.
commerce: quantity block
/**
* Implements hook_block_info().
*
* This hook declares what blocks are provided by the module.
*/
function stock_block_info() {
$blocks['cart_quantity'] = array(
'info' => t('Cart Quantiy'),
'status' => TRUE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*
* This hook generates the contents of the blocks themselves.
*/
function stock_block_view($delta = '') {
switch ($delta) {
case 'cart_quantity':
global $user;
$order = commerce_cart_order_load($user->uid);
if (empty($order) || empty($order->commerce_line_items)) {
$block['subject'] = '';
$block['content'] = '';
}
else {
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items = $wrapper->commerce_line_items;
$total = commerce_line_items_total($line_items);
$currency = commerce_currency_load($total['currency_code']);
$quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
$block['subject'] = t("uppercase this please");
$block['content'] = array(
'subject' => '',
'content' => array(
'#markup' => '<p>' . $quantity . '</p>',
),
);
}
}
return $block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment