Jump to content
thirty bees forum

SuperLosiek

Members
  • Posts

    2
  • Joined

  • Last visited

SuperLosiek's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Nvm, I found the solution here: https://www.prestashop.com/forums/topic/587538-select-multiple-values-for-one-feature/ works for 1.7.2.1 :)
  2. Hello. I'm new in Prestashop, got my page done few days ago. I'm looking for the option mentioned in this topic. I have electronic equipment and my goal is to be able to assign multiple values of the same feature to one device (e.g. a device can have 24Vdc or 230Vac power supply version) so the customers can filter it correctly. I do not care about printing this features on product front page. All I want to do is I went through the whole Internet and the only useful information I can see here and here: https://www.prestashop.com/forums/topic/176242-modification-select-multiple-values-for-one-feature/ . I'm working on Prestashop 1.7.2.1 and I'm too scared to update to newest 1.7.4.2 :) Yes, I've heard that multi features option is available since 1.7.3 but for sure it can be also done by modifying core files in 1.7.2 What I've done so far: 1) Step 1 of this instruction. SQL database accepts multiple idfeaturevalue for the same idfeature. I can manually add suitable records to SQL psfeature_products and it is working properly on the website, filtering etc. . Even when I open product editing page, Prestashop loads all the features from the DB. The problem is that when I want to change something in the product, only the last feature is saved (Prestashop overrides SQL database) - I want to change this. 2) From what I understand the whole thing is about modifying processFeatures() funtion in AdminProductsController.php and maybe addFeaturesToDB() function in Product.php. The approach is to gather feature values in processFeatures() function and pass it to addFeaturesToDB() function as an array. Then in addFeaturesToDB() function add to the array idfeature, idproduct and write it to DB. AdminProductsController.php: ``` public function processFeatures($id_product = null) { if (!Feature::isFeatureActive()) { return; } $id_product = (int) $id_product ? $id_product : (int)Tools::getValue('id_product'); if (Validate::isLoadedObject($product = new Product($id_product))) { // delete all objects $product->deleteFeatures(); // add new objects $languages = Language::getLanguages(false); foreach ($_POST as $key => $val) { if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) { if ($val && $val[0] != 0){ foreach ($val as $feature_val) $product->addFeaturesToDB($match[1], $feature_val); } else { if ($default_value = $this->checkFeatures($languages, $match[1])) { $id_value = $product->addFeaturesToDB($match[1], 0, 1); foreach ($languages as $language) { if ($cust = Tools::getValue('custom_'.$match[1].'_'.(int)$language['id_lang'])) { $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $cust); } else { $product->addFeaturesCustomToDB($id_value, (int)$language['id_lang'], $default_value); } } } } } } } else { $this->errors[] = $this->trans('A product must be created before adding features.', array(), 'Admin.Catalog.Notification'); } } This suppose to get all the features values into array val and pass it to addFeaturesToDB(). I have also tried the way it is shown in this post so without "foreach ($val as $feature_val) $product->addFeaturesToDB($match[1], $feature_val);" but only "$product->addFeaturesToDB($match[1], $val);" in this place. Then we have: addFeaturesToDB(): public function addFeaturesToDB($idfeature, $idvalue, $cust = 0) { // Default behavior. if ($cust) { $row = array('idfeature' => (int)$idfeature, 'custom' => 1); Db::getInstance()->insert('featurevalue', $row); $idvalue = Db::getInstance()->Insert_ID(); } // For multi-value features, build array of rows and insert into db. $base = array( 'id_feature' => (int)$id_feature, 'id_product' => (int)$this->id, ); $rows = array(); foreach ($id_value as $value) { if(!empty($value)) { $rows[] = $base + array('id_feature_value' => $value); } } $row = array('id_feature' => (int)$id_feature, 'id_product' => (int)$this->id, 'id_feature_value' => (int)$id_value); Db::getInstance()->insert('feature_product', $row); SpecificPriceRule::applyAllRules(array((int)$this->id)); if ($id_value) return ($id_value); } ``` I build an array with idfeature and idproduct and add id_value array which is val from processFeatures() function. But it does not work. Can you help me, please? Maybe since Prestashop 1.7.4 is released someone can look up how they are solving this issue? Best regards, Jacek
×
×
  • Create New...