Zippi Posted August 6, 2016 Share Posted August 6, 2016 I tried following example on presta shop documentation, but i can not get it to work. Maybe someone can explain it to me better? or have very simple example module with AJAX i can look at? Link to comment Share on other sites More sharing options...
phinq1910 Posted August 6, 2016 Share Posted August 6, 2016 (edited) I have example following: - create /your-module/ajax.php require_once(dirname(__FILE__).'../../../config/config.inc.php'); require_once(dirname(__FILE__).'../../../init.php'); function fn_calc_prices($product_id, $lang_id = 1, $shop_id = 1) { // Get product object $product = new Product($product_id, TRUE, $lang_id, $shop_id); $price_base = $product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, FALSE); $price = $product->price; $taxes = isset($product->tax_rate) ? $product->tax_rate : 0; $quantity = $product->quantity; $min_order = $product->minimal_quantity; die(Tools::jsonEncode( array( 'price_base' => $price_base, 'price' => $price, 'taxes' => $taxes, 'quantity' => $quantity, 'min_order' => $min_order, ) )); } switch (Tools::getValue('method')) { case 'prices': $product_id = Tools::getValue('id'); $lang_id = Tools::getValue('lang'); $shop_id = Tools::getValue('shop'); fn_calc_prices($product_id, $lang_id, $shop_id); break; default: # code... break; } exit; - Need call ajax in javascript file: jQuery.ajax({ url: baseDir + 'modules/your-module/ajax.php', type: 'POST', data: 'method=prices&id='+ps_product_id+'&lang='ps_language_id+'&shop='+ps_shop_id, //dataType: 'json' success: function(json) { //console.log(json); } }); Now you can see it working fine Link following: http://doc.prestashop.com/display/PS16/Using+jQuery+and+Ajax Edited August 6, 2016 by phinq1910 (see edit history) 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