vnovak Posted February 1, 2023 Share Posted February 1, 2023 Hello, I have product ID (e.g. 2049) and feature ID (e.g. 14). Can you please advice how to get the value of this feature without making the full array of features first? Thank you! Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Hi. Somehow it is not understood what you need. Where do you want to get the name of the value by id? Can you please write more detailed information? Link to comment Share on other sites More sharing options...
vnovak Posted February 2, 2023 Author Share Posted February 2, 2023 Well, imagine creation of XML, please. We are inserting there $product->id, $product->name, etc.. and we have to insert there value of the specific feature with ID 14. Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Thank you. ID feature can have multiple values. Link to comment Share on other sites More sharing options...
vnovak Posted February 2, 2023 Author Share Posted February 2, 2023 1 minute ago, ps8moduly.cz said: Thank you. ID feature can have multiple values. Ok, because of the $lang_id ? If we know language id and feature id, will it helps? 1 Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 $idLang = 1; $idFeature = 14; $getFeatureValues = FeatureValue::getFeatureValuesWithLang($idLang, $idFeature); $fv = array(); foreach ($getFeatureValues as $f){ $fv[] = $f['value']; } $export = implode(', ', $fv); 1 Link to comment Share on other sites More sharing options...
vnovak Posted February 2, 2023 Author Share Posted February 2, 2023 Thank you for the code. It looks like here we are doing array and then fetch it to the $export string, isn't it? What about if we need the value of ONLY one specific feature? Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 Feature = parent Feature Value = children of Feature id_feature = parent id_feature_value = one child of id_feature 1 Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 (edited) You can also check the ps_feature_product table. You will see it there. Edited February 2, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
vnovak Posted February 2, 2023 Author Share Posted February 2, 2023 Thx! 1 Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 (edited) If there is only one value, it's simple. $idlang = 1; $idFeature = 14; $idProduct = 222; $getFeatureValue = Db::getInstance()->getValue(' SELECT a.value FROM '._DB_PREFIX_.'feature_value_lang a LEFT JOIN '._DB_PREFIX_.'feature_product b ON (a.id_feature_value = b.id_feature_value) WHERE b.id_feature = '.$idFeature.' AND b.id_product = '.$idProduct.' AND a.id_lang = '.$idLang); Result one value: Edited February 2, 2023 by ps8moduly.cz (see edit history) 1 Link to comment Share on other sites More sharing options...
vnovak Posted February 2, 2023 Author Share Posted February 2, 2023 Cool! Did not consider direct request to DB 1 Link to comment Share on other sites More sharing options...
ps8modules Posted February 2, 2023 Share Posted February 2, 2023 (edited) If you want to get more information, you use, for example: $idlang = 1; $idFeature = 14; $idProduct = 222; $getFeatureInfo = Db::getInstance()->getRow(' SELECT a.id_feature_value, a.value as feature_value_name, c.name as feature_name FROM '._DB_PREFIX_.'feature_value_lang a LEFT JOIN '._DB_PREFIX_.'feature_product b ON (a.id_feature_value = b.id_feature_value) LEFT JOIN '._DB_PREFIX_.'feature_lang c ON (c.id_feature = b.id_feature) WHERE b.id_feature = '.$idFeature.' AND b.id_product = '.$idProduct.' AND a.id_lang = '.$idLang.' AND c.id_lang = '.$idlang); $featureName = $getFeatureInfo['feature_name']; $featureValueName = $getFeatureInfo['feature_value_name']; $featureValueId = $getFeatureInfo['id_feature_value']; result: And you can play endlessly like this 😄 Edited February 2, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now