* @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class BlockCart extends Module { public function __construct() { $this->name = 'blockcart'; $this->tab = 'front_office_features'; $this->version = '1.2'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Cart block'); $this->description = $this->l('Adds a block containing the customer\'s shopping cart.'); } public function assignContentVars($params) { global $errors; // Set currency if ((int)$params['cart']->id_currency && (int)$params['cart']->id_currency != $this->context->currency->id) $currency = new Currency((int)$params['cart']->id_currency); else $currency = $this->context->currency; $taxCalculationMethod = Group::getPriceDisplayMethod((int)Group::getCurrent()->id); $useTax = !($taxCalculationMethod == PS_TAX_EXC); $products = $params['cart']->getProducts(true); $nbTotalProducts = 0; foreach ($products as $product) $nbTotalProducts += (int)$product['cart_quantity']; $cart_rules = $params['cart']->getCartRules(); $base_shipping = $params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING); $shipping_cost = Tools::displayPrice($base_shipping, $currency); $shipping_cost_float = Tools::convertPrice($base_shipping, $currency); $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING)); $totalToPay = $params['cart']->getOrderTotal($useTax); if ($useTax && Configuration::get('PS_TAX_DISPLAY') == 1) { $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); $this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); } // The cart content is altered for display foreach ($cart_rules as &$cart_rule) { if ($cart_rule['free_shipping']) { $shipping_cost = Tools::displayPrice(0, $currency); $shipping_cost_float = 0; $cart_rule['value_real'] -= Tools::convertPrice($params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING), $currency); $cart_rule['value_tax_exc'] = Tools::convertPrice($params['cart']->getOrderTotal(false, Cart::ONLY_SHIPPING), $currency); } if ($cart_rule['gift_product']) { foreach ($products as &$product) if ($product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) { $product['is_gift'] = 1; $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_); } } } $this->smarty->assign(array( 'products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $cart_rules, 'nb_total_products' => (int)($nbTotalProducts), 'shipping_cost' => $shipping_cost, 'shipping_cost_float' => $shipping_cost_float, 'show_wrapping' => $wrappingCost > 0 ? true : false, 'show_tax' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')), 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency), 'total' => Tools::displayPrice($totalToPay, $currency), 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false, 'static_token' => Tools::getToken(false) )); if (count($errors)) $this->smarty->assign('errors', $errors); if (isset($this->context->cookie->ajax_blockcart_display)) $this->smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); } public function getContent() { $output = '