View source
<?php
module_load_include('inc', 'basic_cart', 'basic_cart.cart');
function basic_cart_price($vars) {
$price = $vars['price'];
$html = '<div class="basic-cart-price"><span class="basic-cart-price-label">' . t('Price') . ': </span><strong>' . $price . '</strong></div>';
return $html;
}
function basic_cart_add_to_cart_button($vars) {
$nid = $vars['nid'];
return '<div class="basic-cart-add-to-cart">
' . l(t('Add to cart'), 'cart/add/' . $nid, array(
'attributes' => array(
'class' => array(
'button basic-cart-add-to-cart-link',
),
),
)) . '
</div>';
}
function basic_cart_add_to_cart_link($nid) {
$link = array(
'#type' => 'link',
'#id' => drupal_html_id('basic-cart-add-to-cart-link-' . $nid),
'#prefix' => '<div class="basic-cart-add-to-cart">',
'#suffix' => '</div>',
'#title' => t('Add to cart'),
'#href' => 'cart/add/' . $nid,
'#attributes' => array(
'class' => array(
'button',
'basic-cart-add-to-cart-link',
),
),
);
return $link;
}
function theme_basic_cart_cart_total_price($variables) {
$price = basic_cart_get_total_price();
$total = basic_cart_price_format($price->total);
$html = '<div class="basic-cart-cart-total-price-contents row">';
$html .= ' <div class="basic-cart-total-price cell">' . t('Total price') . ': <strong>' . $total . '</strong></div>';
$html .= '</div>';
$vat_is_enabled = (int) variable_get('basic_cart_vat_state');
if (!empty($vat_is_enabled) && $vat_is_enabled) {
$vat_value = basic_cart_price_format($price->vat);
$html .= '<div class="basic-cart-cart-total-vat-contents row">';
$html .= ' <div class="basic-cart-total-vat cell">' . t('Total VAT') . ': <strong>' . $vat_value . '</strong></div>';
$html .= '</div>';
}
return $html;
}
function theme_basic_cart_render_cart_element($variables) {
$name = $variables['form']['#name'];
$nid = (int) str_replace(array(
'cartcontents[',
']',
), '', $name);
if (empty($nid)) {
return '';
}
$vars = array(
'path' => base_path() . drupal_get_path('module', 'basic_cart') . '/images/delete2.png',
'alt' => t('Remove from cart'),
'title' => t('Remove from cart'),
'attributes' => array(
'class' => 'basic-cart-delete-image-image',
),
);
$delete_link = l(theme('image', $vars), 'cart/remove/' . $nid, array(
'html' => TRUE,
));
$node = basic_cart_get_cart($nid);
$desc = '';
if (isset($node->basic_cart_node_description)) {
$desc = drupal_strlen($node->basic_cart_node_description) > 50 ? truncate_utf8($node->basic_cart_node_description, 50) : $node->basic_cart_node_description;
}
$unit_price = isset($node->basic_cart_unit_price) ? $node->basic_cart_unit_price : 0;
$unit_price = basic_cart_price_format($unit_price);
$prefix = '<div class="basic-cart-cart-contents row">';
$prefix .= ' <div class="basic-cart-delete-image cell">' . $delete_link . '</div>';
$prefix .= ' <div class="basic-cart-cart-node-title cell">' . l($node->title, 'node/' . $nid) . '<br />';
$prefix .= ' <span class="basic-cart-cart-node-summary">' . $desc . '</span>';
$prefix .= ' </div>';
$prefix .= ' <div class="cell basic-cart-cart-unit-price"><strong>' . $unit_price . '</strong></div>';
$prefix .= ' <div class="cell basic-cart-cart-x">x</div>';
$prefix .= ' <div class="basic-cart-cart-quantity cell">';
$prefix .= ' <div class="cell">';
$suffix = ' </div>';
$suffix .= ' </div>';
$suffix .= '</div>';
$quantity = theme('textfield', $variables['form']);
return $prefix . $quantity . $suffix;
}