Uploaded image for project: 'PrestaShop 1.7'
  1. PrestaShop 1.7
  2. BOOM-6108

Product variants not working as expected after updating from 1.7.3.4 to 1.7.4.1

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.7.4.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • How to reproduce the issue ?:
      Hide
      - Add combinations to a product
      - Try selecting a combinations of variants that don't match with each other
      - Check the network console to see that the request fails
      Show
      - Add combinations to a product - Try selecting a combinations of variants that don't match with each other - Check the network console to see that the request fails
    • Tests & Expected Results:
      N/A
    • Documentation Change:
      N/A

      Description

      Previously when selecting variants in a product in Prestashop, it's attributes where being filtered. For example when I selected the attribute "small" the other attributes where being filtered to only show combinations working with the "small" attribute.

      Now the system shows attributes that don't work with each other. So when I select for example attribute "large", if the 3 other attributes don't make a combination with "large" the POST request crashes and nothing happens.

      Here's a sample of the request being sent :

      https://www.myshop.com/fr/index.php?controller=product?token=c1ee6e0772be03902cdf3c2c9eacff39&id_product=8&id_customization=0&group[3]=41&group[4]=23&group[5]=47&group[6]=53&qty=1

      And if the combination doesn't exist, here's the error I get :

      (1/1) ContextErrorException
      Notice: Undefined variable: find_best
      --
      in Product.php line 6103
      at ProductCore::getIdProductAttributeByIdAttributes(8, array('41', '23', '47', '53'), false)in Product.php line 6155
      at ProductCore::getIdProductAttributesByIdAttributes(8, array('41', '23', '47', '53'))in ProductController.php line 956
      at ProductControllerCore->getIdProductAttribute(true)in ProductController.php line 996
      at ProductControllerCore->getTemplateVarProduct()in ProductController.php line 330
      at ProductControllerCore->initContent()in Controller.php line 255
      at ControllerCore->run()in Dispatcher.php line 428
      at DispatcherCore->dispatch()in index.php line 28

      I took a look inside the ProductController.php code and I saw that, between V. 1.7.3.4 and V. 1.7.4.1 changes where made to the ProductCore::getIdProductAttributesByIdAttributes. Here it is :

      V.1.7.3.4

      private function getIdProductAttribute()
      {{{}}
          $requestedIdProductAttribute = (int)Tools::getValue('id_product_attribute');

          if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) {
              $productAttributes = array_filter(
                  $this->product->getAttributeCombinations(),
                  function ($elem) {
      {{                 return $elem['quantity'] > 0;}}
      {{             }}}

              );
              $productAttribute = array_filter(
                  $productAttributes,
      {{             function ($elem) use ($requestedIdProductAttribute) {}}
      {{                 return $elem['id_product_attribute'] == $requestedIdProductAttribute;}}
      {{             }}}

              );
      {{    }}

             if (empty($productAttribute) && !empty($productAttributes))         {
              return (int)array_shift($productAttributes)['id_product_attribute'];
             }
      {{    }}}
      {{    }}

          return $requestedIdProductAttribute;
      }

      V.1.7.4.1

      private function getIdProductAttribute($useGroups = false)
      {{{}}
          $requestedIdProductAttribute = (int)Tools::getValue('id_product_attribute');

              if ($useGroups === true) {
                  $groups = Tools::getValue('group');

                  if (!empty($groups)) {
                      $requestedIdProductAttribute = (int) Product::getIdProductAttributesByIdAttributes(
                              $this->product->id,
                              $groups
                      );
                  }
      {{        }}}

          if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) {
              $productAttributes = array_filter(
                  $this->product->getAttributeCombinations(),
                  function ($elem) {
                      return $elem['quantity'] > 0;
                  }

              );
              $productAttribute = array_filter(
                  $productAttributes,
                  function ($elem) use ($requestedIdProductAttribute) {
                      return $elem['id_product_attribute'] == $requestedIdProductAttribute;
                  }

              );
         

             if (empty($productAttribute) && !empty($productAttributes))         {
              return (int)array_shift($productAttributes)['id_product_attribute'];
             }
      {{    }}}
         

          return $requestedIdProductAttribute;
      }

       

      And what's also strange is that even though all my product combinations have a quantity of 0, changing 'PS_DISP_UNAVAILABLE_ATTR' doesn't affect the view : it always shows me all the combinations.

      I there a way to deactivate combinations that don't work with each other, like in the previous version ?

      Don't know if it's related to the 1-Click Upgrade or V. 1.7.4.1 of Prestashop, I will open an issue on autoupgrade's Git about this too.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                newslang Thierry Mathez
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: