Jump to content

Product page: duplicate features problem


Recommended Posts

I'm using prestashop 1.4.8.2. i've recently noticed that when I add a new product, it's feature tab shows each feature twice.

 

I've tested while modifying old products' features but they are shown correctly. My guess is that when I add a new product it's features are added twice in the database, but can't find a problem in AdminProduct.php (where I thought could be a problem).

 

Has anyone else had this problem before?

Any help will be appreciated.

Thanks

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

  • 2 months later...

In file Products.php in Classes folder, modify function

 

public static function cacheFrontFeatures($product_ids, $id_lang)

 

from

 

foreach ($result as $row)

{

if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache))

self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array();

self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][] = $row;

}

 

(this version added the same feature in the array without checking if it was already added, leading to duplicates)

 

to

 

foreach ($result as $row)

{

self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array();

}

 

foreach ($result as $row)

{

/* if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache))

self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang] = array(); */

self::$_frontFeaturesCache[$row['id_product'].'-'.$id_lang][] = $row;

}

Edited by bocanila (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Thanks bocanila, your solution saved me a lot of time!

 

This is still a problem in 1.5.2 (although seems to be solved in Github-version).

 

There is just one { missing after the if clause row.

I corrected line 3185 and added the missing character "{" at the end:

 

if (!array_key_exists($row['id_product'].'-'.$id_lang, self::$_frontFeaturesCache)){

 

The result is the same as written by bocanila, but with less code changes ;-)

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

  • 2 years later...
  • 3 years later...
  • 1 year later...
  • 2 months later...
  • 2 years later...

 

I made a small change in product.php file and now it is adding the same to the other languages what it finds in the first language..

 

...\classes\product.php

 

 

FROM:


    /**
     * Add new feature to product.
     *
     * @param int $id_value Feature identifier
     * @param int $lang Language identifier
     * @param string $cust Text of custom value
     *
     * @return bool
     */
    public function addFeaturesCustomToDB($id_value, $lang, $cust)
    {
        $row = ['id_feature_value' => (int) $id_value, 'id_lang' => (int) $lang, 'value' => pSQL($cust)];

        return Db::getInstance()->insert('feature_value_lang', $row);
    }
 

 

CHANGE TO:

  * Add new feature to product.
     *
     * @param int $id_value Feature identifier
     * @param int $lang Language identifier
     * @param string $cust Text of custom value
     *
     * @return bool
     */
    public function addFeaturesCustomToDB($id_value, $lang, $cust)
   {

     if (trim($cust)=='') {

       $sql = 'SELECT f.`value`'
           .' FROM `'. _DB_PREFIX_.'feature_value_lang` f '
           .' WHERE f.id_feature_value = '.$id_value.' and id_lang<>'.$lang;
       $cust=  Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
     }

       $row = array('id_feature_value' => (int) $id_value, 'id_lang' => (int) $lang, 'value' => pSQL($cust));

       return Db::getInstance()->insert('feature_value_lang', $row);
   }


    /**
     * @param int $id_feature Feature identifier
     * @param int $id_value FeatureValue identifier
     * @param int $cust 1 = use a custom value, 0 = use $id_value
     *
     * @return int|string|void FeatureValue identifier or void if it fail
     */
    public function addFeaturesToDB($id_feature, $id_value, $cust = 0)
    {
        if ($cust) {
            $row = ['id_feature' => (int) $id_feature, 'custom' => 1];
            Db::getInstance()->insert('feature_value', $row);
            $id_value = Db::getInstance()->Insert_ID();
        }
        $row = ['id_feature' => (int) $id_feature, 'id_product' => (int) $this->id, 'id_feature_value' => (int) $id_value];
        Db::getInstance()->insert('feature_product', $row);
        SpecificPriceRule::applyAllRules([(int) $this->id]);
        if ($id_value) {
            return $id_value;
        }
    }

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