Spluf Posted September 29, 2014 Share Posted September 29, 2014 (edited) Hi guys, In case anyone needs to add multiple values for features for their products in prestashop here is how you can do it in 1.6x versions: In classes/product.php on line 3295 you can find this code: public function addFeaturesToDB($id_feature, $id_value, $cust = 0) { if ($cust) { $row = array('id_feature' => (int)$id_feature, 'custom' => 1); Db::getInstance()->insert('feature_value', $row); $id_value = Db::getInstance()->Insert_ID(); } $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); } The only thing you need to do in order to accept multiple values is to change that code into this: public function addFeaturesToDB($id_feature, $id_value, $cust = 0) { // Default behavior. if ($cust) { $row = array('id_feature' => (int)$id_feature, 'custom' => 1); Db::getInstance()->insert('feature_value', $row); $id_value = 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); } You can find attatched a picture with how it looks in the backend. One more thing in order for this to work, you'll have to drop the primary keys for id_feature and id_product in the ps_feature_product table in your database. I home you find this usefull. Have a nice day everyone P.s. if someone tries and encounters some problems with this please get back to me, i did this some time ago and i hope i haven't forgot anything . Edited September 29, 2014 by Spluf (see edit history) 2 Link to comment Share on other sites More sharing options...
benjamin utterback Posted September 29, 2014 Share Posted September 29, 2014 Hi, thanks for the post. I'm going to go ahead and move this to the Adapting PrestaShop section of the Forum. Thanks for the tutorial! Link to comment Share on other sites More sharing options...
Spluf Posted September 29, 2014 Author Share Posted September 29, 2014 You are welcome, i'm just glad i can help . Link to comment Share on other sites More sharing options...
Casper_O Posted January 26, 2015 Share Posted January 26, 2015 Your modification looks similar to this thread, [MODIFICATION] Select multiple values for one feature but I have an issue with the default Layered Navigation Block Hello!This is truly great modification to a default Prestashop functionality - thanks a lot, that is exactly I was seaching for. And I would agree with others that this functionality should be default in Prestashop.It works perfecty, but I have an issue with the default Layered Navigation Block.Consider you have two products:TShirt1 with feature "Color" set to "Red" and "Blue"TShirt2 with feature "Color" set to "Red" and "Green"Consider those two items are in the same category. We put "Color" as indexable and in Layered Nagigation configuration enable this to work for filtering.Now in a Front Office you'll see feature "Color" with 3 options "Red", "Blue" and "Green" in the Layered Navigation Block. Suppose you select "Blue" checkbox (i.e. you want to see T-Shirts having only blue color), and Prestashop filters the product and shows you the product TShirt1 - all as expected.Problem is that from the Layered Nagigation Block on left the "Green" checkbox doesn't disappear - but it should, because after application of filter "Blue" there are no products available with "Green" feature.Does anybody has an idea how one should modify Layered Navigation module to make it to work as expected with multiple features?P.S. I know that color is better to set as an attribute, but here it was chosen to be a feature for the sake of simplicity. Link to comment Share on other sites More sharing options...
memodemo Posted February 4, 2015 Share Posted February 4, 2015 Thank you for sharing, I try but not changed, don't know why, anyone can advise.... 1. In classes/product.php to change the code 2. to drop the primary keys for id_feature and id_product in the ps_feature_product table in database. Thank you! Link to comment Share on other sites More sharing options...
kingsinnersoul Posted April 17, 2015 Share Posted April 17, 2015 Were you successful in getting a solution? Link to comment Share on other sites More sharing options...
Casper_O Posted April 17, 2015 Share Posted April 17, 2015 Were you successful in getting a solution? What solution? If you mean for layered navigation, no. If you ask for Multi value in features, yes it did work. Link to comment Share on other sites More sharing options...
creative7 Posted May 7, 2015 Share Posted May 7, 2015 Followed this step by step and hasn't changed anything? all it does is display an error when trying to open the features tab any help appreciated, pulling my hair out with this one. Also, tried this https://github.com/jdanthinne/advancedfeaturesvalues which doesn't install and just gives a ton of errors. Presta v1.6.0.14 PHP v5.2.1.7 Link to comment Share on other sites More sharing options...
carolinalour Posted September 19, 2016 Share Posted September 19, 2016 Hi, How can we import all of the features through CSV? Is that possible? Thank you Link to comment Share on other sites More sharing options...
Casper_O Posted September 19, 2016 Share Posted September 19, 2016 You would need to modify the import class/controller to do so 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