Jump to content

mihainord

Recommended Posts

I am trying to do the following modification in the admin panel:

 

In the Features section I want to add a new field (besides value, url, meta title). I've added the field value_plus in PREFIX_feature_value_lang. I've added to the query in product.php. I can use it just fine.

 

The only problem I have is that I want its content to be editable from Catalog>Features>Edit Feature / Add Feature.

 

I looked at the admin tabs but I can't find any way to do it.

 

Thanks!

Link to comment
Share on other sites

I have modified AdminFeaturesValues and I can see the new field in admin, when I try to edit a feature. However, I can't see the information inside the box. It has $this->getFieldValue($obj, 'value_plus', (int)($language['id_lang'])), where value_plus is the existing new database field (in feature_value_lang). And it also doesn't save.

 

<label>Value plus</label>

<div class="margin-form">';

 

echo '

<div id="value_plus_6" style="display:block; float: left;">

<input size="33" type="text" name="value_plus_6" value="'.$this->getFieldValue($obj, 'value_plus', (int)($language['id_lang'])).'" />

</div>

<div class="clear"></div>

</div>

Link to comment
Share on other sites

CREATE TABLE IF NOT EXISTS `foar_feature_value_lang` (
 `id_feature_value` int(10) unsigned NOT NULL,
 `id_lang` int(10) unsigned NOT NULL,
 `value` varchar(255) DEFAULT NULL,
 `value_plus` text,
 PRIMARY KEY (`id_feature_value`,`id_lang`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

... where value_plus is the field I want to manage from Catalog>Features>Edit (sub) value.

 

Thanks in advance for any advice you may have for my issue!

Link to comment
Share on other sites

I think you have to override the FeatureValue.php class.

 

Add your new field value there.

 

eg.

public   $value_plus;

 

 

And override the function getFields() as well.

 

Maybe :

 

public function getFields()
{
 parent::validateFields();
 $fields['id_feature'] = (int)$this->id_feature;
 $fields['custom'] = (int)$this->custom;
 $fields['value_plus'] = (int)$this->value_plus;
 return $fields;
}

 

 

I have not tested this,but it should work.

 

It will save and retrieve your values of value_plus.

 

Hope this helps.

  • Like 1
Link to comment
Share on other sites

I made the modification. I now get this errror when I edit try to edit a value: feature_value (Unknown column 'value_plus' in 'field list'). I think I need to edit something more. value_plus is located in the feature_value_lang table. Maybe it's trying to find it in feature_value. Any ideeas?

 

Thanks for the help. I feel like we're moving forward.

Link to comment
Share on other sites

My feature_value class:

 

class FeatureValueCore extends ObjectModel
{
/** @var integer Group id which attribute belongs */
public  $id_feature;

/** @var string Name */
public   $value;
public   $value_plus;

/** @var boolean Custom */
public   $custom = 0;

 protected  $fieldsRequired = array('id_feature');
protected  $fieldsValidate = array('id_feature' => 'isUnsignedId', 'custom' => 'isBool');
 protected  $fieldsRequiredLang = array('value');
 protected  $fieldsSizeLang = array('value' => 255);
 protected  $fieldsValidateLang = array('value' => 'isGenericName');

protected  $table = 'feature_value';
protected  $identifier = 'id_feature_value';

protected $webserviceParameters = array(
 'objectsNodeName' => 'product_feature_values',
 'objectNodeName' => 'product_feature_value',
 'fields' => array(
  'id_feature' => array('xlink_resource'=> 'product_features'),
 ),
);
public function getFields()
{
 parent::validateFields();
 $fields['id_feature'] = (int)$this->id_feature;
 $fields['custom'] = (int)$this->custom;
 $fields['value_plus'] = (int)$this->value_plus;
 return $fields;
}

/**
* Check then return multilingual fields for database interaction
*
* @return array Multilingual fields
*/
public function getTranslationsFieldsChild()
{
 parent::validateFieldsLang();
 return parent::getTranslationsFields(array('value'));
}

/**
 * Get all values for a given feature
 *
 * @param boolean $id_feature Feature id
 * @return array Array with feature's values
 * @static
 */
public static function getFeatureValues($id_feature)
{
 return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
 SELECT *
 FROM `'._DB_PREFIX_.'feature_value`
 WHERE `id_feature` = '.(int)$id_feature);
}

/**
 * Get all values for a given feature and language
 *
 * @param integer $id_lang Language id
 * @param boolean $id_feature Feature id
 * @return array Array with feature's values
 * @static
 */
public static function getFeatureValuesWithLang($id_lang, $id_feature)
{
 return Db::getInstance()->ExecuteS('
 SELECT *
 FROM `'._DB_PREFIX_.'feature_value` v
 LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.')
 WHERE v.`id_feature` = '.(int)$id_feature.' AND (v.`custom` IS NULL OR v.`custom` = 0)
 ORDER BY vl.`value` ASC');
}
/**
 * Get all language for a given value
 *
 * @param boolean $id_feature_value Feature value id
 * @return array Array with value's languages
 * @static
 */
public static function getFeatureValueLang($id_feature_value)
{
 return Db::getInstance()->ExecuteS('
 SELECT *
 FROM `'._DB_PREFIX_.'feature_value_lang`
 WHERE `id_feature_value` = '.(int)$id_feature_value.'
 ORDER BY `id_lang`');
}

/**
 * Select the good lang in tab
 *
 * @param array $lang Array with all language
 * @param integer $id_lang Language id
 * @return string String value name selected
 * @static
 */
public static function selectLang($lang, $id_lang)
{
 foreach ($lang as $tab)
  if ($tab['id_lang'] == $id_lang)
return $tab['value'];
}

public static function addFeatureValueImport($id_feature, $name)
{
 $rq = Db::getInstance()->ExecuteS('
 SELECT fv.`id_feature_value`
 FROM '._DB_PREFIX_.'feature_value fv
 LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.`id_feature_value` = fv.`id_feature_value`)
 WHERE `value` = \''.pSQL($name).'\'
 AND fv.`id_feature` = '.(int)$id_feature.'
 AND fv.`custom` = 0
 GROUP BY fv.`id_feature_value` LIMIT 1');
 if (!isset($rq[0]['id_feature_value']) OR !$id_feature_value = (int)$rq[0]['id_feature_value'])
 {
  // Feature doesn't exist, create it
  $featureValue = new FeatureValue();

  $languages = Language::getLanguages();
  foreach ($languages AS $language)
$featureValue->value[$language['id_lang']] = strval($name);
  $featureValue->id_feature = (int)$id_feature;
  $featureValue->custom = 1;
  $featureValue->add();
  return (int)$featureValue->id;
 }
 return (int)$id_feature_value;
}
public function add($autodate = true, $nullValues = false)
{
 $return = parent::add($autodate, $nullValues);
 if ($return)
  Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
 return $return;
}
public function delete()
{
 /* Also delete related products */
 Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'feature_product` WHERE `id_feature_value` = '.(int)$this->id);
 $return = parent::delete();

 if ($return)
  Module::hookExec('afterDeleteFeatureValue', array('id_feature_value' => $this->id));
 return $return;
}
public function update($nullValues = false)
{
 $return = parent::update($nullValues);
 if ($return)
  Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
 return $return;
}
}

 

AdminFeature (from admin/tab)

 

include_once(PS_ADMIN_DIR.'/tabs/AdminFeaturesValues.php');
class AdminFeatures extends AdminTab
{
public function __construct()
{
 $this->adminFeaturesValues = new AdminFeaturesValues();
 $this->table = 'feature';
 $this->className = 'Feature';
 $this->lang = true;
 $this->edit = true;
 $this->delete = true;
 $this->fieldsDisplay = array(
  'name' => array('title' => $this->l('Name'), 'width' => 128),
  'value' => array('title' => $this->l('Values'), 'width' => 255, 'orderby' => false, 'search' => false),
  'value_plus' => array('title' => 'HTML Value', 'width' => 300, 'orderby' => false, 'search' => false)
  );
 parent::__construct();
}
public function display()
{
 global $currentIndex;
 if ((isset($_POST['submitAddfeature_value']) AND sizeof($this->adminFeaturesValues->_errors))
  OR isset($_GET['updatefeature_value']) OR isset($_GET['addfeature_value']))
 {
  $this->adminFeaturesValues->displayForm($this->token);
  echo '<br /><br /><a href="'.$currentIndex.'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" alt="" /> '.$this->l('Back to the features list').'</a><br />';
 }
 else
  parent::display();
}
/* Report to AdminTab::displayList() for more details */
public function displayList()
{
 global $currentIndex;
 echo '<br />
  <a href="'.$currentIndex.'&add'.$this->table.'&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> <b>'.$this->l('Add a new feature').'</b></a><br />
  <a href="'.$currentIndex.'&addfeature_value&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new feature value').'</a><br /><br />
 '.$this->l('Click on a feature name to view its values and then click again if you want to hide them.').'<br /><br />';
 $this->displayListHeader();
 echo '<input type="hidden" name="groupid" value="0">';
 if (!sizeof($this->_list))
  echo '<tr><td class="center" colspan="'.sizeof($this->_list).'">'.$this->l('No features found.').'</td></tr>';
 $irow = 0;
 foreach ($this->_list AS $tr)
 {
  $id = (int)($tr['id_'.$this->table]);
  echo '
  <tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center"><input type="checkbox" name="'.$this->table.'Box[]" value="'.$id.'" class="noborder" /></td>
<td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#features_values_'.$id.'\').slideToggle();">'.$tr['name'].'</td>
<td style="vertical-align: top; padding: 4px 0 4px 0; width: 340px">
 <div id="features_values_'.$id.'" style="display: none">
 <table class="table" cellpadding="0" cellspacing="0">
  <tr>
   <th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'feature_value'.$id.'Box[]\', this.checked)" /></th>
   <th width="100%">'.$this->l('Value').'</th>
   <th>'.$this->l('Actions').'</th>
  </tr>';
  $features = FeatureValue::getFeatureValuesWithLang((int)(Configuration::get('PS_LANG_DEFAULT')), $id);
  foreach ($features AS $feature)
  {
echo '
<tr>
 <td class="center"><input type="checkbox" name="feature_value'.$id.'Box[]" value="'.$feature['id_feature_value'].'" class="noborder" /></td>
 <td>'.$feature['value'].'</td>
 <td class="center">
  <a href="'.$currentIndex.'&id_feature_value='.$feature['id_feature_value'].'&updatefeature_value&token='.$this->token.'">
  <img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>
  <a href="'.$currentIndex.'&id_feature_value='.$feature['id_feature_value'].'&deletefeature_value&token='.$this->token.'"
  onclick="return confirm(\''.$this->l('Delete value', __CLASS__, true, false).' #'.$feature['id_feature_value'].'?\');">
  <img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
 </td>
</tr>';
  }
  if (!sizeof($features))
echo '
  <tr><td colspan="3" style="text-align:center">'.$this->l('No values defined').'</td></tr>';
  echo '
 </table>
 <p><input type="Submit" class="button" name="submitDelfeature_value" value="'.$this->l('Delete selection').'"
 onclick="changeFormParam(this.form, \'?tab=AdminFeatures\', '.$id.'); return confirm(\''.$this->l('Delete selected items?', __CLASS__, true, false).'\');" /></p>
 </div>
 </td>';
  echo '
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center">
 <a href="'.$currentIndex.'&id_'.$this->table.'='.$id.'&update'.$this->table.'&token='.$this->token.'">
 <img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>
 <a href="'.$currentIndex.'&id_'.$this->table.'='.$id.'&delete'.$this->table.'&token='.$this->token.'" onclick="return confirm(\''.$this->l('Delete item', __CLASS__, true, false).' #'.$id.'?\');">
 <img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
</td>
  </tr>';
 }
 $this->displayListFooter();
}
public function displayForm($isMainTab = true)
{
 global $currentIndex;
 parent::displayForm();
 if (!($obj = $this->loadObject(true)))
  return;
 echo '
 <h2>'.$this->l('Add a new feature').'</h2>
 <form action="'.$currentIndex.'&token='.$this->token.'"" method="post">
 '.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
  <fieldset class="width2">
<legend><img src="../img/t/AdminFeatures.gif" />'.$this->l('Add a new feature').'</legend>
<label>'.$this->l('Name:').'</label>
<div class="margin-form">';
 foreach ($this->_languages AS $language)
  echo '
 <div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
  <input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'name', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
  <span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>
 </div>
<script type="text/javascript">
 var flag_fields = \'name\';
</script>';
 $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true);
 echo '
 <div class="clear"></div>
</div>


'.Module::hookExec('featureForm', array('id_feature' => $obj->id)).'
<div class="margin-form">
 <input type="submit" value="'.$this->l('   Save   ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
  </fieldset>
 </form>';
}
public function displayErrors()
{
 $this->adminFeaturesValues->displayErrors();
 parent::displayErrors();
}
public function postProcess()
{
 global $cookie, $currentIndex;
 $this->adminFeaturesValues->tabAccess = Profile::getProfileAccess($cookie->profile, $this->id);
 $this->adminFeaturesValues->postProcess($this->token);

 Module::hookExec('postProcessFeature',
 array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeature to stop saving process
 if (Tools::getValue('submitDel'.$this->table))
 {
  if ($this->tabAccess['delete'] === '1')
  {
if (isset($_POST[$this->table.'Box']))
{
 $object = new $this->className();
 if ($object->deleteSelection($_POST[$this->table.'Box']))
  Tools::redirectAdmin($currentIndex.'&conf=2'.'&token='.$this->token);
 $this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
}
else
 $this->_errors[] = Tools::displayError('You must select at least one element to delete.');
  }
  else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
 }
 else
  parent::postProcess();
}
}

 

 

... and AdminFeatureValues (admin/tab)

 

class AdminFeaturesValues extends AdminTab
{
public function __construct()
{
  $this->table = 'feature_value';
  $this->className = 'FeatureValue';
  $this->lang = true;
  $this->edit = true;
  $this->delete = true;
 parent::__construct();
}
/**
 * Display form
 *
 * @global string $currentIndex Current URL in order to keep current Tab
 */
public function displayForm($isMainTab = true)
{
 global $currentIndex;
 parent::displayForm();
 if (!($obj = $this->loadObject(true)))
  return;
 echo '
 <h2>'.$this->l('Add a new feature value').'</h2>
 <form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.Tools::getValue('token').'" method="post">
 '.($obj->id ? '<input type="hidden" name="id_feature_value" value="'.$obj->id.'" />' : '').'
  <fieldset class="width2">
<legend><img src="../img/t/AdminFeatures.gif" />'.$this->l('Add a new feature value').'</legend>
<label>'.$this->l('Value:').' </label>
<div class="margin-form">';
 foreach ($this->_languages as $language)
  echo '
 <div id="value_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
  <input size="33" type="text" name="value_'.$language['id_lang'].'" value="'.htmlentities($this->getFieldValue($obj, 'value', (int)($language['id_lang'])), ENT_COMPAT, 'UTF-8').'" /><sup> *</sup>
  <span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer"> </span></span>
 </div>
 <script type="text/javascript">
  var flag_fields = \'value\';
 </script>';
 $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'value', false, true);
 echo '
 <div class="clear"></div>
</div>';





  echo ' <label>Value plus</label>
 <div class="margin-form">
  <div id="value_plus" style="display:block; float: left;">
   <input size="33" type="text" name="value_plus" value="'.$this->getFieldValue($obj, 'value_plus', (int)($language['id_lang'])).'" />
  </div>
  <div class="clear"></div>
 </div>



<label>'.$this->l('Feature:').' </label>
<div class="margin-form">
 <select name="id_feature">';
 $features = Feature::getFeatures($this->_defaultFormLanguage);
 foreach ($features AS $feature)
  echo '<option value="'.$feature['id_feature'].'"'.($this->getFieldValue($obj, 'id_feature') == $feature['id_feature']? ' selected="selected"' : '').'>'.$feature['name'].'</option>';
 echo '
 </select><sup> *</sup>
</div>
'.Module::hookExec('featureValueForm', array('id_feature_value' => $obj->id)).'
<div class="margin-form">
 <input type="submit" value="'.$this->l('   Save   ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
  </fieldset>
 </form>';
}
/**
 * Manage page processing
 *
 * @global string $currentIndex Current URL in order to keep current Tab
 */
public function postProcess($token = NULL)
{
 global $currentIndex;

 Module::hookExec('postProcessFeatureValue',
 array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeatureValue to stop saving process
 if (Tools::getValue('submitDel'.$this->table))
 {
  if ($this->tabAccess['delete'] === '1')
  {
if (isset($_POST[$this->table.$_POST['groupid'].'Box']))
{
 $object = new $this->className();
 if ($object->deleteSelection($_POST[$this->table.$_POST['groupid'].'Box']))
  Tools::redirectAdmin($currentIndex.'&conf=2'.'&token='.($token ? $token : $this->token));
 $this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
}
else
 $this->_errors[] = Tools::displayError('You must select at least one element to delete.');
  }
  else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
 }
 else
  parent::postProcess();
}
}

 

PS: If we manage to get this thing going I'll post a tutorial for everybody: How to add a new field in Features. :)

Link to comment
Share on other sites

I made the modifications. However, I get value_plus is required error. I think itcould be something from the form the AdminFeaturesValues.php (admin/tab).

 

My form has this:

echo ' <label>Value plus</label>
 <div class="margin-form">
  <div id="value_plus" style="display:block; float: left;">
   <input size="33" type="text" name="value_plus"  value="'.$this->getFieldValue($obj, 'value_plus', (int)($language['id_lang'])).'" />
  </div>
  <div class="clear"></div>
 </div>

Link to comment
Share on other sites

ok! I managed to resolve the problem regarding the viewing of the value_plus value when I edit, but I get the Unknown column 'value_plus' in 'field list' error. I think, like I posted earlier, that this field is not defined somewhere.

 

Ideas? We're very close!

Link to comment
Share on other sites

public function getFields()
{
 parent::validateFields();
 $fields['id_feature'] = (int)$this->id_feature;
 $fields['custom'] = (int)$this->custom;
 $fields['value_plus'] = (int)$this->value_plus;
 return $fields;
}

 

this is incorrect. You should remove $fields['value_plus'] = (int)$this->value_plus;

 

In FeaturedValue.php change this;

 

public function getTranslationsFieldsChild()
{
 parent::validateFieldsLang();
 return parent::getTranslationsFields(array('value'));
}

 

 

to

 

 

public function getTranslationsFieldsChild()
{
 parent::validateFieldsLang();
 return parent::getTranslationsFields(array('value', 'value_plus'));
}

Link to comment
Share on other sites

Yes. Here's my FeatureValue class again:

 

class FeatureValueCore extends ObjectModel
{
   /** @var integer Group id which attribute belongs */
   public        $id_feature;

   /** @var string Name */
   public         $value;
   public         $value_plus;

   /** @var boolean Custom */
   public         $custom = 0;

    protected     $fieldsRequired = array('id_feature');
   protected     $fieldsValidate = array('id_feature' => 'isUnsignedId', 'custom' => 'isBool');
    protected     $fieldsRequiredLang = array('value', 'value_plus');
    protected     $fieldsSizeLang = array('value' => 255, 'value_plus' => 1200);
    protected     $fieldsValidateLang = array('value' => 'isGenericName', 'value_plus');

   protected     $table = 'feature_value';
   protected     $identifier = 'id_feature_value';

   protected    $webserviceParameters = array(
       'objectsNodeName' => 'product_feature_values',
       'objectNodeName' => 'product_feature_value',
       'fields' => array(
           'id_feature' => array('xlink_resource'=> 'product_features'),
       ),
   );

   public function getFields()
   {
       parent::validateFields();

       $fields['id_feature'] = (int)$this->id_feature;
       $fields['custom'] = (int)$this->custom;

       return $fields;
   }

   /**
   * Check then return multilingual fields for database interaction
   *
   * @return array Multilingual fields
   */
   public function getTranslationsFieldsChild()
   {
       parent::validateFieldsLang();
       return parent::getTranslationsFields(array('value', 'value_plus'));
   }

   /**
    * Get all values for a given feature
    *
    * @param boolean $id_feature Feature id
    * @return array Array with feature's values
    * @static
    */
   public static function getFeatureValues($id_feature)
   {
       return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
       SELECT *
       FROM `'._DB_PREFIX_.'feature_value`
       WHERE `id_feature` = '.(int)$id_feature);
   }

   /**
    * Get all values for a given feature and language
    *
    * @param integer $id_lang Language id
    * @param boolean $id_feature Feature id
    * @return array Array with feature's values
    * @static
    */
   public static function getFeatureValuesWithLang($id_lang, $id_feature)
   {
       return Db::getInstance()->ExecuteS('
       SELECT *
       FROM `'._DB_PREFIX_.'feature_value` v
       LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.')
       WHERE v.`id_feature` = '.(int)$id_feature.' AND (v.`custom` IS NULL OR v.`custom` = 0)
       ORDER BY vl.`value` ASC');
   }

   /**
    * Get all language for a given value
    *
    * @param boolean $id_feature_value Feature value id
    * @return array Array with value's languages
    * @static
    */
   public static function getFeatureValueLang($id_feature_value)
   {
       return Db::getInstance()->ExecuteS('
       SELECT *
       FROM `'._DB_PREFIX_.'feature_value_lang`
       WHERE `id_feature_value` = '.(int)$id_feature_value.'
       ORDER BY `id_lang`');
   }

   /**
    * Select the good lang in tab
    *
    * @param array $lang Array with all language
    * @param integer $id_lang Language id
    * @return string String value name selected
    * @static
    */
   public static function selectLang($lang, $id_lang)
   {
       foreach ($lang as $tab)
           if ($tab['id_lang'] == $id_lang)
               return $tab['value'];
   }

   public static function addFeatureValueImport($id_feature, $name)
   {
       $rq = Db::getInstance()->ExecuteS('
       SELECT fv.`id_feature_value`
       FROM '._DB_PREFIX_.'feature_value fv
       LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.`id_feature_value` = fv.`id_feature_value`)
       WHERE `value` = \''.pSQL($name).'\'
       AND fv.`id_feature` = '.(int)$id_feature.'
       AND fv.`custom` = 0
       GROUP BY fv.`id_feature_value` LIMIT 1');

       if (!isset($rq[0]['id_feature_value']) OR !$id_feature_value = (int)$rq[0]['id_feature_value'])
       {
           // Feature doesn't exist, create it
           $featureValue = new FeatureValue();

           $languages = Language::getLanguages();
           foreach ($languages AS $language)
               $featureValue->value[$language['id_lang']] = strval($name);

           $featureValue->id_feature = (int)$id_feature;
           $featureValue->custom = 1;
           $featureValue->add();

           return (int)$featureValue->id;
       }
       return (int)$id_feature_value;
   }

   public function add($autodate = true, $nullValues = false)
   {
       $return = parent::add($autodate, $nullValues);
       if ($return)
           Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
       return $return;
   }

   public function delete()
   {
       /* Also delete related products */
       Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'feature_product` WHERE `id_feature_value` = '.(int)$this->id);
       $return = parent::delete();

       if ($return)
           Module::hookExec('afterDeleteFeatureValue', array('id_feature_value' => $this->id));
       return $return;
   }

   public function update($nullValues = false)
   {
       $return = parent::update($nullValues);
       if ($return)
           Module::hookExec('afterSaveFeatureValue', array('id_feature_value' => $this->id));
       return $return;
   }
}

 

Now I don't get any errors but it doesn't update the value_plus field in the database.

Link to comment
Share on other sites

It WORKS. I can't belive it. It realy works! I've added another function to the Validate class. I guess I could have used isString instead.

 

Anyway:

 

Now, in admin panel I have the value plus field where I can insert a long string of characters. In product.tpl I've added an exception: {if $feature.value_plus}<a href="#" class="fetool" title="{$feature.value_plus}">{$feature.value}</a>{else}{$feature.value}{/if}

 

I've inserted a tooltip script into the code and now, if the value plus field is filled in, I have a tooltip over the feature.

 

Here's the live example: http://store.bombastic.ro/12-ceas-de-mana-barbati-timex-t2m979.html

The website isn't out yet. Just testing and uploading products.

 

I'll try, with my limited but hopefully growing knowledge of Prestashop to make a module for tooltips on features.

 

Thanks a lot CartExpert.net. You are a great help! I sent you a PM.

Link to comment
Share on other sites

  • 3 years later...
  • 1 year later...

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