VM3.2.14 - product name's special characters twice encoded

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

VM3.2.14 - product name's special characters twice encoded

Postby admin » Wed Aug 08, 2018 4:15 pm

dear friends, we would like to share another fix for VM3.2.14 when you use special characters such as ampersand within the product name

example product name: "3 & 5 doors"

when you use & symbol within product name and you also run a multi language site you can run into a problem that these special characters gets twice encoded.

to fix this problem you can adjust your core virtuemart to:


Code: Select all
private function getData($id, $lang, $viewKey, $dblang, $json) {

      $tables = array ('category' =>'categories','product' =>'products','manufacturer' =>'manufacturers','manufacturercategories' =>'manufacturercategories','vendor' =>'vendors', 'paymentmethod' =>'paymentmethods', 'shipmentmethod' =>'shipmentmethods');
      $tableName = '#__virtuemart_'.$tables[$viewKey].'_'.$dblang;

      $m = VmModel::getModel('coupon');
      $table = $m->getTable($tables[$viewKey]);
      if (empty($table)) {
          $json['fields'] = 'error' ;
         $json['msg'] = 'Table not found '.$viewKey;
         return $json;
      //Todo create method to load lang fields only

      $vs = $table->loadFieldValues();
      $lf = $table->getTranslatableFields();

      $json['fields'] = array();
      foreach($lf as $v){
            $json['fields'][$v] = html_entity_decode($vs[$v]);

      //if ($json['fields'] = $db->loadAssoc()) {
      if ($table->getLoaded()) {
         $json['structure'] = 'filled' ;
         $json['msg'] = vmText::_('COM_VIRTUEMART_SELECTED_LANG').':'.$lang;
         $json['byfallback'] = $table->_loadedWithLangFallback;

      } else {
         $db = JFactory::getDBO();

         $json['structure'] = 'empty' ;
         $db->setQuery('SHOW COLUMNS FROM '.$tableName);
         $tableDescribe = $db->loadAssocList();
         foreach ($tableDescribe as $key =>$val) {
            $fields[$val['Field']] = html_entity_decode($val['Field']);
         $json['fields'] = $fields;
         $json['msg'] = vmText::sprintf('COM_VIRTUEMART_LANG_IS_EMPTY',$lang ,vmText::_('COM_VIRTUEMART_'.strtoupper( $viewKey)) ) ;
      return $json;

replace the original function with the modified one. the only difference is a new html_entity_decode function for loaded values since VM stores values from BE already encoded to html entities.

to fix product title within "meta name title" (your google search page) you may want to modify:


Code: Select all
if ($app->getCfg('MetaTitle') == '1') {
            $document->setMetaData('title', html_entity_decode($product->product_name));  //Maybe better product_name

the above modified line adds html_entity_decode to the line.

same should be applied for all lines containing

since the data are expected to be already encoded and thus setMetaData will encode it another time.

best regards, stan
Site Admin
Posts: 2593
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 3 on Joomla 3.x