Jump to content

[MODIFICATION] Select multiple values for one feature


Recommended Posts

I found the solution for the above.

 

I updated override/classes/Product.php so it now also override cacheFrontFeatures:

public static function cacheFrontFeatures($product_ids, $id_lang)
	{
		if (!Feature::isFeatureActive())
			return;

		$product_implode = array();
		foreach ($product_ids as $id_product)
			if ((int)$id_product && !array_key_exists($id_product.'-'.$id_lang, self::$_cacheFeatures))
				$product_implode[] = (int)$id_product;
		if (!count($product_implode))
			return;

		$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT id_product, name, GROUP_CONCAT(value SEPARATOR \', \') AS value, pf.id_feature
		FROM '._DB_PREFIX_.'feature_product pf
		LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature)
		'.Shop::addSqlAssociation('feature', 'f').'
		WHERE `id_product` IN ('.implode($product_implode, ',').')
		GROUP BY id_product, pf.id_feature
		ORDER BY f.position ASC');

		foreach ($result as $row)
		{
			if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache))
				self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array();
			if (!isset(self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']]))
				self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']] = $row;
		}
	}

To show the features in your product-list.tpl, you could do it this way (I only want to list the feature with ID: 8)

{if isset($product.features.8)}
    <div class="features">	
        <div>
            <span>{$product.features.8}</span>
        </div>
    </div>
{/if}

Product.php

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • Replies 245
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

1.6 version attached. select-multiple-features-values_1.6.zip

Modification for PS 1.5.3.1 and 1.5.4.0   I have resigned from those overrides /override/controllers/front/ProductController.php /override/controllers/front/CompareController.php   and I have ad

OK, for Prestashop v1.5.1 :   In PS 1.5, admin controllers and admin templates are overridable, so we no longer need to modify core files.   There was 4 files to modify : /controllers/admin/Admin

Posted Images

I have Prestahop 1.6.0.9 and I'm unable to do the first step, enter pd_feature_product, since I have no idea what is phpmyadmin and seems that it can't be done with Filezilla or directly entering the server. Can someone help me? Thanks!

Edited by UnaiSC (see edit history)

Share this post


Link to post
Share on other sites
  • 3 weeks later...

Hello everyone.

 

I'm using Prestashop 1.6.0.11 and this fix is great! exactly what i needed.

The problem is that when i add alot of features, scroll bars apear, how can i increase the size of this "box" to allow it to display more features without interruption?

 

picture attached:

 

post-94107-0-56641100-1424258911_thumb.jpg

 

Thank you.

Share this post


Link to post
Share on other sites
  • 3 weeks later...
  • 2 months later...

I tried all your suggestions but none work because in the Database I can't ALTER ps_feature_product

 

I am using:

ALTER TABLE ps_feature_product DROP PRIMARY KEY, ADD PRIMARY KEY (id_feature, id_product, id_feature_value);

 

on 1.6.0.14 but that table doesn't have a primary key.

Has something changed in 1.6.0.14?

 

Thanks!

Share this post


Link to post
Share on other sites
  • 3 weeks later...

Mine was all worked fine but for some reason it is displaying the features like this all of a sudden?

Previously the airlines we're grouped together

Prestashop v1.6.0.14

 

Any help greatly appreciated, thanks in advance

 

blocklayered.png

Share this post


Link to post
Share on other sites

@jdanthinne haven't changed or updated anything, cleared cache and this happened which is really weird. I have also tried your module on github but unfortunately, threw up errors during install.

Share this post


Link to post
Share on other sites

Okay so, I have the features displaying correctly now but have a new problem.

The features tab in the back end of the product now doesn't display any option to insert features?

 

 

 

features.png

  • Like 1

Share this post


Link to post
Share on other sites
  • 5 weeks later...

I tried module on prestashop 1.5.4.1 and i get error how to fix this

 

The following module(s) were not installed properly:

  • - advancedfeaturesvalues :
    The version of your module is not compliant with your PrestaShop version.

Share this post


Link to post
Share on other sites

 

I tried module on prestashop 1.5.4.1 and i get error how to fix this

 

The following module(s) were not installed properly:

  • - advancedfeaturesvalues :

    The version of your module is not compliant with your PrestaShop version.

I installed on presta 1.6.14 and works perfectly.. i also used the override file to match another module! it is really easy and cool

Share this post


Link to post
Share on other sites
  • 3 months later...

@mikajaxxxx

 

I tried the module you are talking about on a fresh install of prestashop v1.6.0.9

 

I can't save because button are "turning" in a loop like on my screen capture.

Any idea to fix it ?

 

439785Capture.png

 

--------------
EDIT
--------------

I think I fix it

in "modules\advancedfeaturesvalues\views\templates\admin\products\features.tpl"

 

line 140 : delete this > disabled="disabled" and replace process-icon-loading by process-icon-save

do the same thing for the other button on the line 139

it work for me ! :) v1.6.0.9

Edited by elgringolo (see edit history)

Share this post


Link to post
Share on other sites
  • 1 month later...

@krawless & @mjcasalins did you try the module than @mikajaxxx is talking about there : https://github.com/jdanthinne/advancedfeaturesvalues  ?

Install

1. Download and copy the advancedfeaturesvalues folder into the /modules folder of your Prestashop installation.

Important: be sure to remove the -master suffix after downloading the archive from GitHub.

 

2. Install the module in your prestashop backend (looking for "features")

 

3. If you have the problem with the inactived buttons, modify  like I explain here :
https://www.prestashop.com/forums/topic/176242-modification-select-multiple-values-for-one-feature/page-11?do=findComment&comment=2162173

Work like a charm for me on a 1.6.0.9 version and it's free :)

  • Like 1

Share this post


Link to post
Share on other sites
  • 1 month later...
  • 2 weeks later...

Hi, i have version1.6.1.1 and i can't find solution to solve this problem to features..anyone can help me..i installed module advancedfeaturesvalues-master but i can't find it in BO

Share this post


Link to post
Share on other sites
  • 2 months later...

@krawless & @mjcasalins did you try the module than @mikajaxxx is talking about there : https://github.com/jdanthinne/advancedfeaturesvalues  ?

Install

1. Download and copy the advancedfeaturesvalues folder into the /modules folder of your Prestashop installation.

Important: be sure to remove the -master suffix after downloading the archive from GitHub.

 

2. Install the module in your prestashop backend (looking for "features")

 

3. If you have the problem with the inactived buttons, modify  like I explain here :

https://www.prestashop.com/forums/topic/176242-modification-select-multiple-values-for-one-feature/page-11?do=findComment&comment=2162173

 

Work like a charm for me on a 1.6.0.9 version and it's free :)

 

This module is great

But after installing and using module for 1 day, all the changes have come back to before. then I cannot select multiple value, and all saved feature become single value.

Do you know what is the problem.

I used 1.6.1.2

Share this post


Link to post
Share on other sites
  • 5 weeks later...

Works for me, thanks!

 

Is there any chance to group features by categories?

 

Hi, i have version1.6.1.1 and i can't find solution to solve this problem to features..anyone can help me..i installed module advancedfeaturesvalues-master but i can't find it in BO

 

Dont install it via admin, just unpack zip, change folder name to 'advancedfeaturesvalues' and copy it to 'modules' folder on FTP. After that find and install it in admin panel.

 

--

 

I found a problem, when i try to fill customized value, when there is already pre-defined ones, then it simply dont save to DB.

 

When there is no pre-defined values, then cutomized value works fine. Anyone solve this?

Edited by proghead (see edit history)

Share this post


Link to post
Share on other sites
  • 1 month later...

@locen

Maybe it's too late but I had the same trouble. Solution : unzip and copy in your "modules" files (using Filezilla) after having erased "-master" (warning, if you erase "-master" from the zip file when unzip it keeps the "-master" in the file name! so delete after unzip ^_^ )

Share this post


Link to post
Share on other sites
  • 2 months later...

Hi, 

 

Sorry in advance for this, but the topic is 12 pages long and I could not understand it fully.  I've installed this module. However, the values I import with CSV, even though they show up in product details page, they dont show up in filters.

 How to make them appear ?

 

Thanks 

Edited by carolinalour (see edit history)

Share this post


Link to post
Share on other sites
  • 2 weeks later...

So it does not work in PS 1.6.1.7.

 

I have tried installing the overrides, changing the database.

It looks good in backoffice, but the selected product features do not save upon saving product.

 

 

So now I am left with possibility to purchase 1 out of these 2 modules:

http://addons.prestashop.com/nl/6356-multiple-features-assign-your-features-as-you-want.html

http://addons.prestashop.com/nl/8196-multiple-features-for-products.html

 

The first does not have layered navigation in front office demo.

The second just doesn't add up. When selecting a feature value (in the layered navigation) with 1 product (compositions/cotton) I still get 7 results.

 

 

Anyone have some experience with one of these 2 addons? Any recommendations?

 

 

Thanks

Edited by Tomzie (see edit history)

Share this post


Link to post
Share on other sites

Hello Tomzie,

 

I purchased this two modules a few weeks ago. This modules do not work either with prestashop 1.6.1.5. And the support ist bu******t! They don´t answear my questions.

 

So now I am looking for another solution.. Important is that I need to import multiple features. I have more than 6000 products with multiple features to import...

Share this post


Link to post
Share on other sites

Hi TKV,

 

Yeah. Don't have any great experience with the addons support either.

I would gladly pay for this function. But if and when I pay for it, it should work without problems/delays.

So no solution there. Hopefully someone will find a fix for this.

 

The only problem in latest version of the override proposed by David Bucur is that feature values do not save in Back Office

I have done every step correctly. Also I have tried in a fresh PS 1.6.1.7 installation.

Share this post


Link to post
Share on other sites

is it working on PS 1.6.1.6 well? 

 

installed on PS 1.6.1.6 as said by Tomzie, it is not working on front office

 

(The error is: Fatal error: Class 'ProductCore' not found in E:\xampp\htdocs\classes\Product.php on line 4)

 

Back office working well...

 

 

I really want to know how can we use check box instead of radio buttons. multiple selection must be necessary for this system i think... 

Edited by EvrenE (see edit history)

Share this post


Link to post
Share on other sites
  • 1 month later...

 

I found the solution for the above.

 

I updated override/classes/Product.php so it now also override cacheFrontFeatures:

public static function cacheFrontFeatures($product_ids, $id_lang)
	{
		if (!Feature::isFeatureActive())
			return;

		$product_implode = array();
		foreach ($product_ids as $id_product)
			if ((int)$id_product && !array_key_exists($id_product.'-'.$id_lang, self::$_cacheFeatures))
				$product_implode[] = (int)$id_product;
		if (!count($product_implode))
			return;

		$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT id_product, name, GROUP_CONCAT(value SEPARATOR \', \') AS value, pf.id_feature
		FROM '._DB_PREFIX_.'feature_product pf
		LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
		LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature)
		'.Shop::addSqlAssociation('feature', 'f').'
		WHERE `id_product` IN ('.implode($product_implode, ',').')
		GROUP BY id_product, pf.id_feature
		ORDER BY f.position ASC');

		foreach ($result as $row)
		{
			if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache))
				self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array();
			if (!isset(self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']]))
				self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']] = $row;
		}
	}

To show the features in your product-list.tpl, you could do it this way (I only want to list the feature with ID: 8)

{if isset($product.features.8)}
    <div class="features">	
        <div>
            <span>{$product.features.8}</span>
        </div>
    </div>
{/if}

 

 

Ok, try this override:

Place file AdminImportController.php in overide/controllers/admin/

 

attachicon.gifAdminImportContoller.php

 

I also correctes some bugs in it (my last post)

 

Let me know if there are any problems

 

Hello!

I'm having trouble with feature import, could you please help?

Here is my feature line in CSV:

Size:Large adult|Standard adult:1:0;Measuring method:Korotkov tones|Ocillometric:2:0;Cuff type:Standard with ring:3:0;AC Adapter:Yes:4:0

Here is what I get in features values when importing products:

e42907a111.jpg

 

As I assume features are combined somehow and import is misbehaving.

Help, please

Share this post


Link to post
Share on other sites
  • 3 weeks later...
  • 3 weeks later...

Hi everybody

 

I found something really good module to do this and it is FREE! 

 

 

https://github.com/jdanthinne/advancedfeaturesvalues

 

this module works much better than you think . the only problem i faced is that it have some kind of overrides for Layered navigation block. and if you use a replacement for this module it will not work for you

 

the owner didn't update it for a year.. but if we could update it will work like a charm

  • Like 1

Share this post


Link to post
Share on other sites
  • 2 weeks later...

OK smile.png

 

Now, the front display is another problem due to a strange cache which isn't always updated.

 

The only workaround I could find, is to avoid testing this cache when displaying features.

Try replacing the code in /override/classes/Product.php with this one :

<?php
class Product extends ProductCore
{
	public static function getFrontFeaturesStatic($id_lang, $id_product)
	{
		if (!Feature::isFeatureActive())
			return array();
		//if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
		//{
			self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
				SELECT name, value, pf.id_feature
				FROM '._DB_PREFIX_.'feature_product pf
				LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
				LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
				LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
				WHERE pf.id_product = '.(int)$id_product.'
				ORDER BY f.position ASC'
			);
			
			//PWeb: join multiple values of one feature into one value
			$features =& self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
			$features_key = array();
			foreach ($features as $key => $feature) {
				if (!array_key_exists($feature['name'], $features_key)) {
					$features_key[$feature['name']] = $key;
				} else {
					$features[ (int)$features_key[$feature['name']] ]['value'] .= ', ' . $feature['value'] ;
					unset($features[$key]);
				}
			}
		//}
		return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
	}
}
Note that this is a temporary workaround, hoping someone will find how to handle this strange "frontFeaturesCache" properly

 

 

THX 4 this one! My sollution to fix the caching issue is to override the cacheFrontFeatures class Product method like this to get the caching working:

    /*
    * module: advancedfeaturesvalues fix for caching
    */
    public static function cacheFrontFeatures($product_ids, $id_lang)
    {
        if (!Feature::isFeatureActive()) {
            return;
        }

        $product_implode = array();
        foreach ($product_ids as $id_product) {
            if ((int)$id_product && !array_key_exists($id_product.'-'.$id_lang, self::$_cacheFeatures)) {
                $product_implode[] = (int)$id_product;
            }
        }
        if (!count($product_implode)) {
            return;
        }

        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT id_product, name, GROUP_CONCAT(value ORDER BY f.position SEPARATOR ", ") AS value, pf.id_feature
        FROM '._DB_PREFIX_.'feature_product pf
        LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
        LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
        LEFT JOIN '._DB_PREFIX_.'feature f ON (f.id_feature = pf.id_feature)
        '.Shop::addSqlAssociation('feature', 'f').'
        WHERE `id_product` IN ('.implode($product_implode, ',').')
        GROUP BY id_product, f.position
        ORDER BY id_product,f.position ASC');

        foreach ($result as $row) {
            if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)) {
                self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array();
            }
            if (!isset(self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']])) {
                self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][$row['id_feature']] = $row;
            }
        }
    }

Edited by prestowicz (see edit history)

Share this post


Link to post
Share on other sites
  • 5 months later...

Hi,

 

Anything like this for prestashop 1.7?

 

I'm using the latest Prestashop 1.7 and I've been able to find the first code and adjust it (see the first post) in the /controllers/admin/adminproductscontroller.php

                    if ($val && $val[0] != 0)
                        foreach ($val AS $feature_val) $product->addFeaturesToDB($match[1], $feature_val);

I also adjusted the database (drop primary key)

 

But what's the next step for 1.7? I don't know much about code, but any help with with which files to adjust with the right code would be greatly appreciated. I think lots of people are looking for this in the latest Prestashop (this should've been one of the basics that comes with Prestashop anyway)

 

Anyone? :)

Edited by PinkyPurple (see edit history)

Share this post


Link to post
Share on other sites
  • 3 weeks later...

Ok, so I did it myself

If You want to Import Multiple features (with this mod) in presta 1.6+ (I tested it on 1.6.0.9) you should modify 1 File:

/controllers/admin/AdminImportController.php

....

ID;Feature (Name:Value:Position:Customized)
11;Grupa roślin:Iglaste|Liściaste:0

Notice that You should use | as a multiple feature devider.

 

 

Should work :)

It's not working on PS 1.6.1.11  :( (with php7)

Edited by trace (see edit history)

Share this post


Link to post
Share on other sites
  • 5 months later...

Hi guys,

I struggled with this issue in presta 1.7 for 3 days now and finally i found out a solution :D

It's not "elegant" (you have to modify core file in "/src" folder) but it works.

Maybe someone will come up with a more suitable solution after seeing mine.

 

Here it goes:

1st step is modifing table "(your_prefix)_feature_product" to allow inserting multiple lines with same "id_feature" and "id_product", like in 1st post in this topic (see it for more detailed instructions).

2nd step is modyfing file "AdminModelAdapter.php" found in "/src/PrestaShopBundle/Model/Product/" folder.

We just have to change line 340 (in my Presta version) from:

$form_data['feature_'.$idFeature.'_value'] = $dataFeature['value'];

to:

$form_data['feature_'.$idFeature.'_value'.$dataFeature['value']] = $dataFeature['value'];

Point of this step is to change the way Prestashop converts data from $_POST variable.

 

And that's it, now you can add multiple values to one feature in Back Office (like in the attached screenshot), enjoy ! :)

 

scr1.jpg

Edited by bTk (see edit history)

Share this post


Link to post
Share on other sites
  • 1 year later...
  • 2 weeks later...

 

14 hours ago, Edel said:

Hello,

It's now native in PrestaShop.

What version of 1.7 is it native in? I'm using 1.7.5.1 and Can't select/display multiple values. I can, as always set multiple values for a given 'feature' but only one can be selected at any one time using the drop-down or preset.

Am I missing something or is it still not possible to select and display multiple values for a given feature?

  • Confused 1

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More