Jump to content

understanding FeatureValue class - custom attribute?


codegrunt

Recommended Posts

Howdy. I am currently working on a custom import module and am specifically working on product "features" at the moment.

Looking at the FeatureValue object, there is this method (it is used in the stock import tab as well):

static public 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` = '.intval($id_feature).'
           GROUP BY fv.`id_feature_value` LIMIT 1');
       if (!isset($rq[0]['id_feature_value']) OR !$id_feature_value = intval($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 = $id_feature;
           $featureValue->custom=1;
           $featureValue->add();
           return $featureValue->id;
       }
       return $id_feature_value;
   }



What I am curious about is the purpose of "$featureValue->custom=1;" in this method. The attribute is not declared in the class file itself and the above method does not update the column value in the database. I am unclear whether this is a bug, a not fully fleshed out feature or what. Anyone know the intended purpose for "custom" in the "feature_value" MYSQL table?

Cheers

Link to comment
Share on other sites

Ok, the "custom" attribute of feature_value is used in this query:

line 77 of classes/FeatureValue.php:

static public 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` = '.intval($id_lang).')
       WHERE v.`id_feature` = '.intval($id_feature).' AND (v.`custom` IS NULL OR v.`custom` = 0)
       ORDER BY vl.`value` ASC');
   }



This does allow for a one off feature value which is *pure awesome* as it avoids problems with massive lists on a given product's admin edit features page if you have lots of possible values.

Unfortunately, I am not fully up to speed yet with the overall object structure here and so am not having much luck solving why Feature_Value->add() does not record the custom attribute properly.

Is there an architecture document anywhere that fleshes out the flow from ObjectModel.php down to its child classes (in this case Feature_Value)?

Cheers

Link to comment
Share on other sites

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