int Posted August 26, 2015 Share Posted August 26, 2015 We had previously hired someone to fix our WHMCS 5 templates to allow for multilanguage product descriptions; we have since lost touch with this developer, so need some guidance from you guys. Here's the code we used to use for this in WHMCS 5: -- {foreach key=num item=productgroup from=$productgroups} {php} // multilanguage product name and description $groupvar=$template->get_template_vars('productgroup'); $gname=$groupvar['name']; if( strpos($gname,'<french>') !== FALSE && strpos($gname,'<english>') !== FALSE ) { if( $template->get_template_vars('language') == 'french' ) { $gname=substr($gname,strpos($gname,'<french>')+14); $gname=substr($gname,0,strpos($gname,'</french>')); } else { $gname=substr($gname,strpos($gname,'<english>')+15); $gname=substr($gname,0,strpos($gname,'</english>')); } } $template->assign('multilanggroupname',$gname); {/php} {if $gid eq $productgroup.gid}<span class="btn btn-default active">{$multilanggroupname}</span> {else}<a class="btn btn-sm btn-default" href="{$smarty.server.PHP_SELF}?gid={$productgroup.gid}">{$multilanggroupname}</a> {/if} {/foreach} -- The above code has been modified for smarty 3 (using $template instead of $this, per WHMCS guidelines in WHMCS 6), but even with this change, the product groups no longer display multilanguage like they used to. Same issue for this the products and product descriptions (code snippet below): -- {foreach key=num item=product from=$products} <div class="panel panel-default"> {php} // multilanguage product name and description $myvar=$template->get_template_vars('product'); $pname=$myvar['name']; if( strpos($pname,'<french>') !== FALSE && strpos($pname,'<english>') !== FALSE ) { if( $template->get_template_vars('language') == 'french' ) { $pname=substr($pname,strpos($pname,'<french>')+14); $pname=substr($pname,0,strpos($pname,'</french>')); } else { $pname=substr($pname,strpos($pname,'<english>')+15); $pname=substr($pname,0,strpos($pname,'</english>')); } } $template->assign('multilangproductname',$pname); if( isset($myvar['description']) ) { $descr=$myvar['description']; if( strpos($descr,'<french>') !== FALSE && strpos($descr,'<english>') !== FALSE ) { if( $template->get_template_vars('language') == 'french' ) { $descr=substr($descr,strpos($descr,'<french>')+; $descr=substr($descr,0,strpos($descr,'</french>')); } else { $descr=substr($descr,strpos($descr,'<english>')+9); $descr=substr($descr,0,strpos($descr,'</english>')); } } $template->assign('multilangproductdescr',$descr); } {/php} <div class="panel-heading"><h3 class="panel-title">{$multilangproductname}{if $product.qty!=""} ({$product.qty} {$LANG.orderavailable}){/if}</h3> {if $product.description}<div class="description">{$multilangproductdescr}</div>{/if} -- What changed in WHMCS 6 that no longer allows this to work? How do we modify the above code to properly read the variables and return the correct multilanguage value? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted August 26, 2015 Share Posted August 26, 2015 # Modify Both $this-> # And $template-> # To $smarty-> 0 Quote Link to comment Share on other sites More sharing options...
int Posted August 26, 2015 Author Share Posted August 26, 2015 # Modify Both $this-> # And $template-> # To $smarty-> I had done this before after reading the WHMCS documentation on the template changes, but I tried it again after your response. Having made the changes again (only to orderforms/<cart>/products.tpl), when accessing cart.php, I now see: -- Browse Products & Services Fatal error: Call to a member function get_template_vars() on a non-object in <whmcs_root>/vendor/smarty/smarty/libs/SmartyBC.class.php(464) : eval()'d code on line 3 -- I had someone look into this, to which he replied: -- You will need to hire programmer to write a hook that assigns smarty variables. Those variables will need to be included in template code for description, product name, group name, etc. -- Is this true? Shouldn't the hooks already exist, or did WHMCS remove them in v6? Can someone with knowledge of this please comment? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 26, 2015 Share Posted August 26, 2015 i'm assuming this solution is based on the code in the thread below? http://forum.whmcs.com/showthread.php?65242-Multilanguage-product-description-a-simple-approach if so, I would seriously be starting to look for an alternative to this - even if you could fix it, it is only a matter of time before {php} is disabled in WHMCS and when that occurs, this solution will definitely fail to work. to be honest, you shouldn't even need to use {php} in the templates to do this - in the cart, it can be done purely using Smarty (certainly v2, and i've just tested some v3 code to change name and desc in products.tpl and it works fine) - it's just one line of code for each. however, the difficulty with a Smarty solution would depend on how far you need it to translate - it would certainly work in the cart and the client area (would require some templates to be edited), it might work in the PDF invoice (would require some serious testing though!), but certainly wouldn't work with the email templates (that would probably need a hook or alternate solution)... I might test this further in v6 at the weekend. btw - there is a multi-language addon by Kian which is compatible with v6 - I don't think it handles the email templates issue, but it should take care of the cart and invoicing. http://forum.whmcs.com/showthread.php?97943-Finally-Multilanguage-Cart!-Groups-products-names-descriptions 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 26, 2015 Share Posted August 26, 2015 btw - there is a multi-language addon by Kian which is compatible with v6 - I don't think it handles the email templates issue, but it should take care of the cart and invoicing. http://forum.whmcs.com/showthread.php?97943-Finally-Multilanguage-Cart!-Groups-products-names-descriptions I've seen the bat-signal Yep, it translates invoice items too based on user language. That said, lets go back to the bat cave! Tanananananananananana Batmaaan Batmaaan 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.