visibletrue Posted June 23, 2012 Share Posted June 23, 2012 Need display additional_shipping_cost different with shipping cost carriers I have made a modify in blockcart module but Ajax update is not work when I click "Add to cart" button. It just work when I refresh the page Code is blockcart.php public function smartyAssigns(&$smarty, &$params) { global $errors, $cookie; // Set currency if (!(int)($params['cart']->id_currency)) $currency = new Currency((int)$params['cookie']->id_currency); else $currency = new Currency((int)$params['cart']->id_currency); if (!Validate::isLoadedObject($currency)) $currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT'))); if ($params['cart']->id_customer) { $customer = new Customer((int)$params['cart']->id_customer); $taxCalculationMethod = Group::getPriceDisplayMethod((int)$customer->id_default_group); } else $taxCalculationMethod = Group::getDefaultPriceDisplayMethod(); $useTax = !($taxCalculationMethod == PS_TAX_EXC); $products = $params['cart']->getProducts(true); $nbTotalProducts = 0; foreach ($products AS $product) $nbTotalProducts += (int)$product['cart_quantity']; $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING)); $totalToPay = $params['cart']->getOrderTotal($useTax); $totalGbs += $product['additional_shipping_cost'] * $product['cart_quantity']; if ($useTax AND Configuration::get('PS_TAX_DISPLAY') == 1) { $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false); $smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency)); } $smarty->assign(array( 'products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $params['cart']->getDiscounts(false, Tools::isSubmit('id_product')), 'nb_total_products' => (int)($nbTotalProducts), 'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING) - $totalGbs, $currency), '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), 'id_carrier' => (int)($params['cart']->id_carrier), 'weightUnit' => Configuration::get('PS_WEIGHT_UNIT'), [b]'gbs_cost' => Tools::displayPrice($totalGbs, $currency),[/b] 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int)(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); } blockcart-json.tpl "gbsCost": "{$gbs_cost|html_entity_decode:2:'UTF-8'}", ajax-cart.js //update general cart informations everywhere in the page updateCartEverywhere : function(jsonData) { $('.ajax_cart_total').text(jsonData.productTotal); $('.ajax_cart_shipping_cost').text(jsonData.shippingCost); $('.ajax_block_cart_weight').text(jsonData.totalWeight); [b]$('.ajax_block_gbs_cost').text(jsonData.gbsCost); [/b] $('.ajax_cart_tax_cost').text(jsonData.taxCost); $('.cart_block_wrapping_cost').text(jsonData.wrappingCost); .................................................. blockcart.tpl <span>{l s='Other shipping:' mod='blockcart'}</span> <span id="cart_block_gbs_cost" class="price ajax_block_gbs_cost">[b]{$gbs_cost}[/b]</span> Please help, how to make it refreshed without refresh my page, when I click "Add to cart" button Thank you Link to comment Share on other sites More sharing options...
kfoo Posted June 23, 2012 Share Posted June 23, 2012 (edited) I have the same problem with discounts in the blockcart. I suspect $products (in your case), is updated in one of the php files in the /controller directory, hence the need for a page refresh. I too, would be happy to hear any thoughts on how to do this without a refresh. Edited June 23, 2012 by kfoo (see edit history) Link to comment Share on other sites More sharing options...
visibletrue Posted June 24, 2012 Author Share Posted June 24, 2012 Hello, waiting for reply Link to comment Share on other sites More sharing options...
razaro Posted June 24, 2012 Share Posted June 24, 2012 Hi Think that this part of code is causing problems $nbTotalProducts = 0; foreach ($products AS $product) $nbTotalProducts += (int)$product['cart_quantity']; $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING)); $totalToPay = $params['cart']->getOrderTotal($useTax); $totalGbs += $product['additional_shipping_cost'] * $product['cart_quantity']; Try this $nbTotalProducts = 0; $totalGbs = 0; foreach ($products AS $product){ $nbTotalProducts += (int)$product['cart_quantity']; $totalGbs += $product['additional_shipping_cost'] * $product['cart_quantity']; } $wrappingCost = (float)($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING)); $totalToPay = $params['cart']->getOrderTotal($useTax); Not sure if will help. Do you get some JavaScript errors, and do you have maybe live example ? Link to comment Share on other sites More sharing options...
visibletrue Posted June 24, 2012 Author Share Posted June 24, 2012 Not sure if will help. Do you get some JavaScript errors, and do you have maybe live example ? Hi, I have try but still not working. I think problem in Javascript and no error while checking use Firebug. I just install in localhost server :sad: Link to comment Share on other sites More sharing options...
razaro Posted June 24, 2012 Share Posted June 24, 2012 Tried on localhost myself using default theme , changed code works. Few obvious questions - you have added additional_shipping_cost for each product in back office? And code you posted have some bold tags that forum added, they are not in your code ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now