Jump to content

[SOLVED]New added info not updated with ajax on shopping-cart.tpl


Recommended Posts

Hi,

 

It's a bit complicated to explain so it might be easier if you have a look on my shop to see the problem.

*www.tokyo-smart.com/en/*

I have created a little function to have all my prices in dual display (yen + an other one).

 

This function works almost everywhere even on the blockcart with ajax but I have one problem that I've been working on for hours and can't figure out how to solve it.

 

Here is the problem:

- the customer add a product to the cart

- then he goes to the cart summary page (template is shopping-cart.tpl)

- if he add a coupon everything is fine, all the information are updated including the converted price

- however when the customer change the number of one of the products in the list, ajax update everything except the converted total price.

 

I tried to play with a few files including shopping-cart-product-line.tpl, cart-summary.js and Cart.php but nothing work I'm completely lost on this one :(

 

My PS version is 1.4.2.5 and the function is located in classes/Product.php.

 

Thanks !

Edited by cactusman2 (see edit history)
Link to comment
Share on other sites

Hi,

 

Thank you for your answer. I tried for hours but I couldn't figure out how it works.

It was easy to implement it to the blockcart but for the cart-summary.js it seems much more complicated as they use a totally different way to update the data with ajax.

 

Here is what I have in shopping-cart.tpl (total is total products+discount-shipping)

<tr class="cart_total_price2">
 <td colspan="5">{l s='Total:'}</td>
 <td colspan="1" class="price" id="total_price">{displayPrice price=$total}</td>
</tr>
<tr class="cat_total_price2">
 <td colspan="5" class="price" style="padding: 0em 0.5em 0.5em;">{l s='Converted prices for reference only - Payments are made in Japanese yens'}</td>
 <td class="price" id="total_price2" style="padding: 0em 0.5em 0.5em;">{multiprices price=$total}</td>

 

In cart-summary.js ajax is updated this way (this one works):

$('#total_price').html(formatCurrency(json.total, currencyFormat, currencySign, currencyBlank));

 

I cannot figure out how to updated {multiprices price=$total} in cart-summary.js

I tried many things like the following but it didn't work...

$('#total_price2').html(formatCurrency(json.total, currencyFormat, currencySign, currencyBlank));

 

The variable total has been declared on the Cart.php file in the getSummaryDetails function

$total = $this->getOrderTotal(false, Cart::BOTH_WITHOUT_SHIPPING);

then

'total' => $total,

This is a big problem as the converted total is incorrect on the summary page. I tried everything I could :(

 

Any help would be great on this one

Link to comment
Share on other sites

Ok I have to be a bit more specific.

If I do what I said last, the price 'multiprices' is updated but back in Japanese yens.

I think I need to specify the other currency in the formatCurrency function but I don't know how.

The other currency is passed through a cookie called 'currency2'

from this cookie I have created a variable called $other_currency which actually is the id of the currency.

Link to comment
Share on other sites

Hi,

 

Thank you for your answer.

I don't have problem with the blockcart but with the cart summary.

 

However for the blockcart I couldn't use the multiprices function (from the classes/Product.php file) right away so I had to add some code straight on the /modules/blockcart/blockcart.php file (on the smartAssigns function).

But now I'm thinking there is something easier to do for block cart

 

The multiprices function (from the classes/Product.php file) is this one

static function multiprices($params, &$smarty)
	{		  
	global $cookie;
	$price=$params['price'];
  	 if(!isset($cookie->currency2)) {
		$other_currency = 1;
		} else {
	$other_currency = $cookie->currency2;
	}
  	 //deuxieme currency
	$currency2 = new Currency($other_currency);
  	 $rate2 = (is_array($currency2) ? $currency2['conversion_rate'] : $currency2->conversion_rate);
	$price2=$price*$rate2;
  	 $ret1en= ''.number_format($price2, 2, '.', ',');		
	$ret2en= '$'.number_format($price2, 2, '.', ',');
	$ret3en= '£'.number_format($price2, 2, '.', ',');
	$ret5en= 'C$'.number_format($price2, 2, '.', ',');
	$ret6en= 'A$'.number_format($price2, 2, '.', ',');
	$ret7en= 'NZ$'.number_format($price2, 2, '.', ',');
	$ret8en= 'CHF '.number_format($price2, 2, '.', ',');
	$ret1fr= number_format($price2, 2, ',', '.').' ';		
	$ret2fr= number_format($price2, 2, ',', '.').' $';
	$ret3fr= number_format($price2, 2, ',', '.').' £';
	$ret5fr= number_format($price2, 2, ',', '.').' C$';
	$ret6fr= number_format($price2, 2, ',', '.').' A$';
	$ret7fr= number_format($price2, 2, ',', '.').' NZ$';
	$ret8fr= number_format($price2, 2, ',', '.').' CHF';
	$langid= intval($cookie->id_lang);
  	 if ($langid=="1") {
		$textcurrency2 = ${'ret'.$other_currency.'en'};
		echo $textcurrency2;
	}
	else {
		$textcurrency2 = ${'ret'.$other_currency.'fr'};
		echo $textcurrency2;
		}
	}

 

I think it's possible to integrate it in a more simple way to blockcart.php by adding in the smartyAssigns function something like that:

'multiprices' => Product::multiprices($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $smarty),

after

'total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency),

But it does not work :(

 

My main problem is still with the cart summary I can't find any solution to my problem :(

My second problem is with the blockcart. I found a workaround but I would like to integrate it in a easier way.

 

Sorry but I on't know much about javascript and ajax. I've spent hours on this problem and it seems I'm getting moe and more confuse :(

Link to comment
Share on other sites

Hi,

 

I finally found a solution.

My multiprices function is very useless there is a much simpler solution using Tools::convertPrice and Tools::displayPrice.

When I created this multiprices function 2 years ago I didn't know much about Prestashop but now I can see I made an easy thing complicated !

 

I can't find where to change the title of the topic to add [solved]

 

Thank you again for your help !

Link to comment
Share on other sites

Sorry but actually I still have a problem :(

 

Here is my new multiprices function located in classes/Product.php

static function multiprices($params, &$smarty)
   {          
       global $cookie;
       $price=$params['price'];

       if(!isset($cookie->currency2)) {
           $other_currency = 1;
           } else {
       $other_currency = $cookie->currency2;
       }
       //deuxieme currency
       $currency2 = new Currency($other_currency);
       $price2 = Tools::convertPrice($price, $currency2);
       $price3 = Tools::displayPrice($price2, $currency2, $no_utf8 = false, $convert = true);
       return $price3;    
   }

 

I would like to use this function in cart-summary.js in the same way as formatCurrency but I don't know how to do.

I tried something like that:

$('#total_price2').html(multiprices(json.total, smarty));

or

$('#total_price2').html(Product::multiprices(json.total, smarty));

 

But it does not work.

The function works perfectly on the template files by simply adding {multiprices price=$whatever.price}

Link to comment
Share on other sites

Ok I noticed that formatCurrency is a javascript function so I'm creating a javascript variation of formatCurrency called formatCurrency2 on the same file (js/tools.js)>

 

Now I'm stuck again because I don't know how to read a cookie info with javascript on Prestashop :(

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...