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...

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 11/8/2017 at 1:53 PM, 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.

 

 

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

Link to comment
Share on other sites

  • 3 months later...
On 5.12.2017 at 1:58 PM, horiatb said:

This feature should be available in 1.7.30 according to forge. I'd advice to wait for the official feature insead of altering core and database manually.

 

It is available now but unfortunately quite uncomfortable when used in all products.

Link to comment
Share on other sites

On 3/29/2018 at 6:58 AM, canabislt said:

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

 

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 18.10.2017 at 7: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  ;)

 

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...
3 hours ago, ukbaz said:

I'm running Prestashop 1.7.5.1

 

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

 

Baz

 

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...