How to use language variable in product description?

Hi,



Is there any way that I can use language variables in product description box. e.g I have a language variable in english “ship_from” = “Orders ships from warehouse in 2 days”



Now i want to use this variable in product description, so if i need to change value of this variable it get reflected in all products. I don;t need to go individual item to change sentence.



I have tried to use {$lang.ship_from} in textarea of product description, but it don;t interpret this variable and displays simply {$lang.ship_from}.



Any idea how to do this?



Regards,

Vinic

You can’t use smarty template variables in text boxes…

You would need to create a new language variable (i.e. desc_append) and give it a value.



Then you would need to alter the templates you want this info to display in by appending your {$lang.desc_append} after the description. You might be able to do it everywhere by making the change in the common_templates/product_data.tpl file.



Good luck.

Thanks for reply. But actually this value will differ from category to category so in that case i will have to use if else conditions in template to display appropriate language variable.



I was thinking another way, what if we add another logic,



search product description for spacific pattern “{anything in between}” using preg_replace function and then replace value of language variable in place of these curly braces. and pass this value to template for display.



will that work?

Just add a field to the product data that you can fill in in the addons area. Then, append that field to the description.



See the SEO addon for an example.



You’ll need to do a fn_set_hook(‘get_product_data’, ‘update_product’, ‘delete_product’, ‘get_products’); in addons/my_changes/init.php

and then have a functions specifically named (for my_changes and the get_product_data hook) fn_my_changes_get_product_data() (and the other hooks too) that deal with storing and retrieving the information…

Vinic,



It sounds like the functionality that you’re looking for is already available in this free add-on from ShippingKit.com:



Shipping Availability addon for CS-Cart 2.0-2.1

@sixnin9



Cool, glad there’s a solution already available for him… I loose track sometimes of what other developers have in stock!

@sixnin9, thanks for the link, but actually i was not looking for that “shipping availability” that was an example.



Actually there are few fix lines that i need to add in description of each items on basis of category like declaimer or warranty information. Some time details get changed and we need to edit each product individually to reflect changes.



So was thinking if there could be any option, that if i change values in one place and it get reflected every where just like global options.



@tbirnseth, thanks for your guidance but i am not advance level developer of CS, and i m not much familiar with hooks concept of cs.



What about solution that i have suggested is that correct way to do this task?

There are 10,000 ways to skin a cat.

Your way would work if you’re comfortable doing it that way. If you’re going to have potentially 3 or 4 different replacements then it gets more complex and more difficult to maintain.



You’re still going to want to do this in a ‘get_product_data’ hook so you can run your replacment filter on both the short and long descriptions.



I’ll go through this once and then you’re on your own:



In addons/my_changes/init.php, add a line (or add the parameter if fn_register_hooks already exists) of:


fn_register_hooks('get_product_data_more');




Then in addons/my_changes/func.php add:


function your_filter_function($string) {
// Note: str_replace would be much faster if you are looking for a fixed pattern
return preg_replace('/your pattern/', "your replacment", $string);
}

function fn_my_changes_get_product_data_more(&$product_data) {
foreach( array('short_description', 'full_description') as $key) {
$product_data[$key] = your_filter_function($product_data[$key]);
}
}




You will have to design “your_filter_function” to do what you want with the string parameter which will be either the short or full description.



Good luck.

thanks tbirnseth for detailed instructions on how to use code hook.



will try it out and let you know result.