AnilaN Posted August 14, 2012 Share Posted August 14, 2012 (edited) I'm using prestashop 1.4.8.2. i've recently noticed that when I add a new product, it's feature tab shows each feature twice. I've tested while modifying old products' features but they are shown correctly. My guess is that when I add a new product it's features are added twice in the database, but can't find a problem in AdminProduct.php (where I thought could be a problem). Has anyone else had this problem before? Any help will be appreciated. Thanks Edited August 14, 2012 by aany (see edit history) Link to comment Share on other sites More sharing options...
bocanila Posted October 26, 2012 Share Posted October 26, 2012 (edited) In file Products.php in Classes folder, modify function public static function cacheFrontFeatures($product_ids, $id_lang) from foreach ($result as $row) { if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)) self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array(); self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][] = $row; } (this version added the same feature in the array without checking if it was already added, leading to duplicates) to foreach ($result as $row) { self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array(); } foreach ($result as $row) { /* if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)) self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array(); */ self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][] = $row; } Edited October 26, 2012 by bocanila (see edit history) 2 Link to comment Share on other sites More sharing options...
pieter314 Posted November 7, 2012 Share Posted November 7, 2012 I had the same problem. Great Help! Thanks. Link to comment Share on other sites More sharing options...
furehead Posted November 29, 2012 Share Posted November 29, 2012 (edited) Thanks bocanila, your solution saved me a lot of time! This is still a problem in 1.5.2 (although seems to be solved in Github-version). There is just one { missing after the if clause row. I corrected line 3185 and added the missing character "{" at the end: if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)){ The result is the same as written by bocanila, but with less code changes ;-) Edited November 29, 2012 by furehead (see edit history) Link to comment Share on other sites More sharing options...
Housy Posted August 3, 2015 Share Posted August 3, 2015 (edited) How can i fix this in PS 1.6.0.14? Thanks and regards, Housy Edited August 3, 2015 by Housy (see edit history) Link to comment Share on other sites More sharing options...
luko Posted July 17, 2019 Share Posted July 17, 2019 Hi, i have the same issue in PS 1.7.5.1. How to fix it? There are a lot of duplicate features and i can't open product page in BO. Thanks and regards Luko 1 Link to comment Share on other sites More sharing options...
Steven Tuyau Posted August 10, 2020 Share Posted August 10, 2020 Hello Guys, I'm facing this same issue on prestashop vs 1.7.5.2 Whenever i add a product caracteristics and save, it is automatically duplicated, i can't even delete, it is duplicated no matter what. I tried above solution but not working. Please help. Link to comment Share on other sites More sharing options...
zenerry Posted November 5, 2020 Share Posted November 5, 2020 On 7/17/2019 at 6:36 AM, luko said: Hi, i have the same issue in PS 1.7.5.1. How to fix it? There are a lot of duplicate features and i can't open product page in BO. Thanks and regards Luko Hi @luko did you find how to solve this? Thanks. Link to comment Share on other sites More sharing options...
MURAT ONUR YUKSEL Posted May 28, 2023 Share Posted May 28, 2023 I made a small change in product.php file and now it is adding the same to the other languages what it finds in the first language.. ...\classes\product.php FROM: /** * Add new feature to product. * * @param int $id_value Feature identifier * @param int $lang Language identifier * @param string $cust Text of custom value * * @return bool */ public function addFeaturesCustomToDB($id_value, $lang, $cust) { $row = ['id_feature_value' => (int) $id_value, 'id_lang' => (int) $lang, 'value' => pSQL($cust)]; return Db::getInstance()->insert('feature_value_lang', $row); } CHANGE TO: * Add new feature to product. * * @param int $id_value Feature identifier * @param int $lang Language identifier * @param string $cust Text of custom value * * @return bool */ public function addFeaturesCustomToDB($id_value, $lang, $cust) { if (trim($cust)=='') { $sql = 'SELECT f.`value`' .' FROM `'. _DB_PREFIX_.'feature_value_lang` f ' .' WHERE f.id_feature_value = '.$id_value.' and id_lang<>'.$lang; $cust= Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } $row = array('id_feature_value' => (int) $id_value, 'id_lang' => (int) $lang, 'value' => pSQL($cust)); return Db::getInstance()->insert('feature_value_lang', $row); } /** * @param int $id_feature Feature identifier * @param int $id_value FeatureValue identifier * @param int $cust 1 = use a custom value, 0 = use $id_value * * @return int|string|void FeatureValue identifier or void if it fail */ public function addFeaturesToDB($id_feature, $id_value, $cust = 0) { if ($cust) { $row = ['id_feature' => (int) $id_feature, 'custom' => 1]; Db::getInstance()->insert('feature_value', $row); $id_value = Db::getInstance()->Insert_ID(); } $row = ['id_feature' => (int) $id_feature, 'id_product' => (int) $this->id, 'id_feature_value' => (int) $id_value]; Db::getInstance()->insert('feature_product', $row); SpecificPriceRule::applyAllRules([(int) $this->id]); if ($id_value) { return $id_value; } } 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