name = 'blockcart'; $this->tab = 'Blocks'; $this->version = '1.2'; parent::__construct(); $this->displayName = $this->l('Cart block'); $this->description = $this->l('Adds a block containing the customer\'s shopping cart'); } public function smartyAssigns(&$smarty, &$params) { global $errors, $cookie; // Set currency if (!intval($params['cart']->id_currency)) $currency = new Currency(intval($params['cookie']->id_currency)); else $currency = new Currency(intval($params['cart']->id_currency)); if (!Validate::isLoadedObject($currency)) $currency = new Currency(intval(Configuration::get('PS_CURRENCY_DEFAULT'))); if ($params['cart']->id_customer) { $customer = new Customer(intval($params['cart']->id_customer)); $taxCalculationMethod = Group::getPriceDisplayMethod(intval($customer->id_default_group)); } else $taxCalculationMethod = Group::getDefaultPriceDisplayMethod(); $usetax = $taxCalculationMethod == PS_TAX_EXC ? false : true; $products = $params['cart']->getProducts(true); $nbTotalProducts = 0; foreach ($products AS $product) $nbTotalProducts += intval($product['cart_quantity']); $wrappingCost = floatval($params['cart']->getOrderTotal($usetax, 6)); $smarty->assign(array( 'products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas(intval($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $params['cart']->getDiscounts(false, $usetax), 'nb_total_products' => intval($nbTotalProducts), 'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal($usetax, 5), $currency), 'show_wrapping' => $wrappingCost > 0 ? true : false, 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($usetax, 4), $currency), 'total' => Tools::displayPrice($params['cart']->getOrderTotal($usetax), $currency), 'id_carrier' => intval($params['cart']->id_carrier), 'ajax_allowed' => intval(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false )); if (sizeof($errors)) $smarty->assign('errors', $errors); if(isset($cookie->ajax_blockcart_display)) $smarty->assign('colapseExpandStatus', $cookie->ajax_blockcart_display); } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitBlockCart')) { $ajax = Tools::getValue('ajax'); if ($ajax != 0 AND $ajax != 1) $output .= '
'.$this->l('Ajax : Invalid choice.').'
'; else { Configuration::updateValue('PS_BLOCK_CART_AJAX', intval($ajax)); } $output .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } return $output.$this->displayForm(); } public function displayForm() { return '
'.$this->l('Settings').'

'.$this->l('Activate AJAX mode for cart (compatible with the default theme)').'

'; } public function install() { if ( parent::install() == false OR $this->registerHook('rightColumn') == false OR Configuration::updateValue('PS_BLOCK_CART_AJAX', 1) == false ) return false; return true; } public function hookRightColumn($params) { global $smarty, $page_name; $smarty->assign('order_page', $page_name == 'order'); $this->smartyAssigns($smarty, $params); return $this->display(__FILE__, 'blockcart.tpl'); } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookAjaxCall($params) { global $smarty; $this->smartyAssigns($smarty, $params); return $this->display(__FILE__, 'blockcart-json.tpl'); } } ?>