Jump to content

Back Office : erreur de calcul des quantités en stock sur la page catalogue


Recommended Posts

Bonjour,

J'ai une erreur de calcul de quantités produits en stock sur la nouvelle version PS 1.2.5
- 4 produits à 1000 exemplaires donnent 8000 sur 1.2.5
- 4 produits à 1000 exemplaires donnent 4000 sur 1.2.4
Dans les 2 cas les produits se trouvent dans une catégorie principale et dans une sous-catégories.

L'erreur provient de la fonction countNbProductAndSub() qui se trouve dans classes/Category.php
Elle a été modifiée entre la version 1.2.4 et 1.2.5

Est-ce un bug ?

Dois-je réécraser 1.2.5/Category.php par 1.2.4/Category.php ?

merci

Link to comment
Share on other sites

  • 6 months later...

Salut Florent,

Dans la version 1.2.5 j'ai tout simplement remplacé (dans classes/Category.php) la fonction countNbProductAndSub() par un ancien code et ça faisait l'affaire. Voir ci-dessous.

Ceci dit je crois me rappeler que la version 1.2.4 était bonne, tu n'as peut-être pas exactement le même problème.

Aujourd'hui je suis en version 1.3.1 et le problème ne se pose plus dans le BO vu que l'équipe Prestashop a supprimé la colonne Produits en stocks. De ce fait, la fonction countNbProductAndSub() n'existe plus elle non plus.

salutations


routine qui ne marche pas:

        public static function countNbProductAndSub($id_category, $id_lang)
   {
       $tab = array(intval($id_category));
       Category::getAllSubCats($tab, intval($id_category), intval($id_lang));
       $listCategories = implode(',', $tab);
       $sql = '
           SELECT SUM(IFNULL(pa.`quantity`, p.`quantity`)) AS nb
           FROM `'._DB_PREFIX_.'category` c
           INNER JOIN `'._DB_PREFIX_.'category_product` pc ON (pc.`id_category` = c.`id_category` AND c.`id_category` IN ('.$listCategories.'))
           INNER JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pc.`id_product`)
           LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product` = p.`id_product`)';
       $result = Db::getInstance()->getRow($sql);
       return $result['nb'];
   }



routine qui marche :

    public static function countNbProductAndSub($id_category, $id_lang)
   {
       $tab = array(intval($id_category));
       Category::getAllSubCats($tab, intval($id_category), intval($id_lang));

       $listCategories = implode(',', $tab);
       $sql = 'SELECT
       (
         (
           /* quantity of products witch don\'t have attributes */
           IFNULL((
                 SELECT SUM(quantity)
                 FROM `'._DB_PREFIX_.'product`
                 WHERE id_product NOT IN
                 (
                   /* products with attributes */
                   SELECT DISTINCT(id_product)
                   FROM `'._DB_PREFIX_.'product_attribute`
                 )
                 AND id_product IN
                 (
                     /* products direclty in the categories listed bellow */
                     SELECT DISTINCT(id_product)
                     FROM `'._DB_PREFIX_.'category_product`
                     WHERE id_category IN ('.$listCategories.')
                 )
               ),0)
         )
         +
         (
           /* quantity of products witch have attributes */
               IFNULL((
                 SELECT SUM(quantity)
                 FROM `'._DB_PREFIX_.'product_attribute` pa
                 WHERE pa.id_product IN
                 (
                     /* products direclty in the categories listed bellow */
                     SELECT DISTINCT(id_product)
                     FROM `'._DB_PREFIX_.'category_product`
                     WHERE id_category IN ('.$listCategories.')
                 )
               ),0)
         )
       ) as nb';
       $result = Db::getInstance()->getRow($sql);
       return $result['nb'];
   }

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