Jump to content

Select multiple values for one feature


Phantom48

Recommended Posts

  • 1 month later...
  • 5 months later...

I think I found solution to this problem that works for me in Prestashop 1.7.1.1.

 

In file "/src/PrestaShopBundle/Model/Product/AdminModelAdapter.php" you need to go to line around 308 with comment //map features and change code from this:

//map features
if (!empty($form_data['features'])) {
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value'] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value'] = $dataFeature['value'];
        }
    }
}

to this:

//map features
if (!empty($form_data['features'])) {
    $n = 0;
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value_'. $n] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value_'. $n] = $dataFeature['value'];
        }
        $n += 1;
    }
}

then in the database alter table primary key "ps_feature_product"

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

It's worth to notice that I used standard prefix. If you have changed your prefix then you should update it in this query.

 

Give me some feedback. I'd like to know if it works for you.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...
  On 8/11/2017 at 11:53 AM, Devhub said:

I think I found solution to this problem that works for me in Prestashop 1.7.1.1.

 

In file "/src/PrestaShopBundle/Model/Product/AdminModelAdapter.php" you need to go to line around 308 with comment //map features and change code from this:

//map features
if (!empty($form_data['features'])) {
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value'] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value'] = $dataFeature['value'];
        }
    }
}

to this:

//map features
if (!empty($form_data['features'])) {
    $n = 0;
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value_'. $n] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value_'. $n] = $dataFeature['value'];
        }
        $n += 1;
    }
}

then in the database alter table primary key "ps_feature_product"

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

It's worth to notice that I used standard prefix. If you have changed your prefix then you should update it in this query.

 

Give me some feedback. I'd like to know if it works for you.

Worked for me, PS 1.7.2.0

 

thanks!

Link to comment
Share on other sites

  • 1 month later...

Hi all (first post here) and thanks devhub for your suggestion! I just tried this method on PS 1.7.2.3 and it works great, except for one thing:

the product details tab in product page (front office) displays  the same feature several times, one for each value.

Do you know how to show all values on the same line separated for example by  " / " or " - "?

Thanks in advance  ;)

Edited by DLC86 (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  On 8/11/2017 at 11:53 AM, Devhub said:

I think I found solution to this problem that works for me in Prestashop 1.7.1.1.

 

In file "/src/PrestaShopBundle/Model/Product/AdminModelAdapter.php" you need to go to line around 308 with comment //map features and change code from this:

//map features
if (!empty($form_data['features'])) {
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value'] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value'] = $dataFeature['value'];
        }
    }
}

to this:

//map features
if (!empty($form_data['features'])) {
    $n = 0;
    foreach ($form_data['features'] as $dataFeature) {
        $idFeature = $dataFeature['feature'];

        //custom value is defined
        if ($dataFeature['custom_value'][$this->defaultLocale]) {
            foreach ($this->locales as $locale) {
                $form_data['feature_'.$idFeature.'_value_'. $n] = null;
                $form_data['custom_'.$idFeature.'_'.$locale['id_lang']] = $dataFeature['custom_value'][$locale['id_lang']];
            }
        } elseif ($dataFeature['value']) {
            $form_data['feature_'.$idFeature.'_value_'. $n] = $dataFeature['value'];
        }
        $n += 1;
    }
}

then in the database alter table primary key "ps_feature_product"

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

It's worth to notice that I used standard prefix. If you have changed your prefix then you should update it in this query.

 

Give me some feedback. I'd like to know if it works for you.

Expand  

 

 

You made my day, Devhub!! Thanks for sharing that - super easy - solution!
Thanks!

Link to comment
Share on other sites

  • 3 months later...
  On 3/29/2018 at 11:58 AM, canabislt said:

This feature added on 1.7.3 by default :) tested and working good

Expand  

 

Is it multiple values in one line of feature, or multiple lines of the same feature?

I upgraded to 1.7.3, but found I still couldn't select multiple values for one feature under the product page.

 

Link to comment
Share on other sites

  • 2 months later...
  On 10/18/2017 at 5:07 PM, DLC86 said:

Hi all (first post here) and thanks devhub for your suggestion! I just tried this method on PS 1.7.2.3 and it works great, except for one thing:

the product details tab in product page (front office) displays  the same feature several times, one for each value.

Do you know how to show all values on the same line separated for example by  " / " or " - "?

Thanks in advance  ;)

Expand  

 

the same problem for me, any1 have solutions how to make it not double but in one line?

Link to comment
Share on other sites

  • 1 year later...
  On 6/28/2019 at 1:00 PM, ukbaz said:

I'm running Prestashop 1.7.5.1

 

I can't find where to set multiple features - where is it anyone?

 

Baz

Expand  

 

Hi Baz,

You actually need to add each feature multiple times, with different values. In the front office, it will look like one feature with multiple values.

This is not ideal, but that's how PS implemented this function (don 't know why).

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