Page 1 of 1

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

PostPosted: Wed Aug 08, 2018 4:15 pm
by admin
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:


\administrator\components\com_virtuemart\controllers\translate.php

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
      $table->load($id);

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

      $json['fields'] = array();
      foreach($lf as $v){
         if(isset($vs[$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();
         array_shift($tableDescribe);
         $fields=array();
         foreach ($tableDescribe as $key =>$val) {
            $fields[$val['Field']] = html_entity_decode($val['Field']);
         }
         $json['fields'] = $fields;
         VmLanguage::loadJLang('com_virtuemart');
         $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:

\components\com_virtuemart\views\productdetails\view.html.php


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
```
$document->setMetaData
```

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

best regards, stan