Jump to content

Multiple languages and $product->description


Recommended Posts

Hi folks,

 

I'm currently facing a pretty stupid situation and really don't know how to solve this in a nice and efficient way. In 1.3 I could use $product->description in all templates to get a product-description based on the current frontend-language. However, in 1.4 I only get "Array" returned by $product->description - even though it's used just like that in the prestashop theme that comes with the source. Is that a bug or just misconfiguration on my side?!

 

I found out that $product->description is now containing all languages when called in smarty and print_r returns an array like:

[1] => english text

[4] => german text

 

So presta obviously doesn't choose the right description in the productController and wants me to do this in the template... this would be pretty much work actually since I had to go through every single template and I don't really think it's intended to work like this, since there's no reference to this in the prestashop theme. Or was this theme created with only one language in mind (which would be kinda sloppy...)?!

 

I'm currently defining an array with all needed language-vars in the frontendController and get the desired description for the product like this:

$product->description[$langAssets[$lang_iso].id]

 

 

Almost the same happens with my "speaking urls"... instead of ID-Productname.html the pages are now ID-Array.html...

 

 

Thanks for any help!

Martin

Link to comment
Share on other sites

OK since there's no help in sight, I did it the way I thought would be wrong... at least it's working.

 

Still need to find a fix for the friendly URLs... the links look ok in the frontend, but the adressbar always shows /ID-Array.html instead of the product name....

Link to comment
Share on other sites

  • 4 months later...

I solved it: I was overriding the "product" class _constructor method

 

public function __construct($id_product = NULL, $full = false, $id_lang = NULL)
{
 parent::__construct($id_product,$id_lang);
 //some content
}

 

but instead of calling

parent::__construct($id_product,$id_lang);

that had the parameters of the ObjectModel constructor (copy paste error) I should have been calling

parent::__construct($id_product,$full,$id_lang); 

because the parent of my overridden Product class is ProductCore, not ObjectModel as is for ProductCore.

 

Sooo, the $id_lang parameter (being the second parameter) was interpreted as $full (the second parameter from the prototype of the parent) and automatically the id_lang information was lost and the ObjectModel constructor retrieved all the values for all the translated fields (the ones in the product_lang database table).

 

The bottom line is: my overridden _construct() method should have looked like this:

 

public function __construct($id_product = NULL, $full = false, $id_lang = NULL)
{
 parent::__construct($id_product,$full,$id_lang);
 //some content
}

 

Hope this helps someone in the future :)

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...