Get Out of Stock products to show in magento 2.3












0















I'm trying to get options which are out of stock to be passed to the frontend js renderer.



However I've found that getJsonConfig() does not return attribute data (attribute labels and other data) for the options array that I pass it.



// I have found that the configurable $options data is initially set here
// I have made it so that this returns the entire array of attribute codes and product numbers -
// - for the configurable regardless of stock status
/* @var MagentoConfigurableProductHelperData $this->$helper */
$options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());


Note that the $options[array] correctly contains all out of stock attribute ids => product ids



$options array



This $options array is passed to a function that attempts to serialize/add extra data that is required buy the js renderer such as labels.



$attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);



/**
* Get product attributes
*
* @param Product $product
* @param array $options
* @return array
*/
public function getAttributesData(Product $product, array $options = )
{
$defaultValues = ;
$attributes = ;
$productInstance = $product->getTypeInstance();
$productEnabledAttributes = $productInstance ->getConfigurableAttributes($product);
foreach ($productEnabledAttributes as $attribute) {
$attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
if ($attributeOptionsData) {
$productAttribute = $attribute->getProductAttribute();
$attributeId = $productAttribute->getId();
$attributes[$attributeId] = [
'id' => $attributeId,
'code' => $productAttribute->getAttributeCode(),
'label' => $productAttribute->getStoreLabel($product->getStoreId()),
'options' => $attributeOptionsData,
'position' => $attribute->getPosition(),
];
$defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
}
}
return [
'attributes' => $attributes,
'defaultValues' => $defaultValues,
];
}


However getAttributesData does not obey the $options param. A sub call function must unwittingly run a filter operation. Observe below how the return $attributesData has filtered attribute "138"



data filtered



From the getAttributesData() function, I'm suspecting getConfigurableAttributes() to be the cause of out of stock options not displaying in magento 2.3, this function retrieves data from a cache that was generated a few clock cycles ago.



/**
* Retrieve configurable attributes data
*
* @param MagentoCatalogModelProduct $product
* @return MagentoConfigurableProductModelProductTypeConfigurableAttribute
*/
public function getConfigurableAttributes($product)
{
MagentoFrameworkProfiler::start(
'CONFIGURABLE:' . __METHOD__,
['group' => 'CONFIGURABLE', 'method' => __METHOD__]
);
if (!$product->hasData($this->_configurableAttributes)) {
$configurableAttributes = $this->getConfigurableAttributeCollection($product);
$this->extensionAttributesJoinProcessor->process($configurableAttributes);
$configurableAttributes->orderByPosition()->load();
$product->setData($this->_configurableAttributes, $configurableAttributes);
}
MagentoFrameworkProfiler::stop('CONFIGURABLE:' . __METHOD__);
return $product->getData($this->_configurableAttributes);
}


Here's a stack trace to help show where I'm up to.



image










share|improve this question



























    0















    I'm trying to get options which are out of stock to be passed to the frontend js renderer.



    However I've found that getJsonConfig() does not return attribute data (attribute labels and other data) for the options array that I pass it.



    // I have found that the configurable $options data is initially set here
    // I have made it so that this returns the entire array of attribute codes and product numbers -
    // - for the configurable regardless of stock status
    /* @var MagentoConfigurableProductHelperData $this->$helper */
    $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());


    Note that the $options[array] correctly contains all out of stock attribute ids => product ids



    $options array



    This $options array is passed to a function that attempts to serialize/add extra data that is required buy the js renderer such as labels.



    $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);



    /**
    * Get product attributes
    *
    * @param Product $product
    * @param array $options
    * @return array
    */
    public function getAttributesData(Product $product, array $options = )
    {
    $defaultValues = ;
    $attributes = ;
    $productInstance = $product->getTypeInstance();
    $productEnabledAttributes = $productInstance ->getConfigurableAttributes($product);
    foreach ($productEnabledAttributes as $attribute) {
    $attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
    if ($attributeOptionsData) {
    $productAttribute = $attribute->getProductAttribute();
    $attributeId = $productAttribute->getId();
    $attributes[$attributeId] = [
    'id' => $attributeId,
    'code' => $productAttribute->getAttributeCode(),
    'label' => $productAttribute->getStoreLabel($product->getStoreId()),
    'options' => $attributeOptionsData,
    'position' => $attribute->getPosition(),
    ];
    $defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
    }
    }
    return [
    'attributes' => $attributes,
    'defaultValues' => $defaultValues,
    ];
    }


    However getAttributesData does not obey the $options param. A sub call function must unwittingly run a filter operation. Observe below how the return $attributesData has filtered attribute "138"



    data filtered



    From the getAttributesData() function, I'm suspecting getConfigurableAttributes() to be the cause of out of stock options not displaying in magento 2.3, this function retrieves data from a cache that was generated a few clock cycles ago.



    /**
    * Retrieve configurable attributes data
    *
    * @param MagentoCatalogModelProduct $product
    * @return MagentoConfigurableProductModelProductTypeConfigurableAttribute
    */
    public function getConfigurableAttributes($product)
    {
    MagentoFrameworkProfiler::start(
    'CONFIGURABLE:' . __METHOD__,
    ['group' => 'CONFIGURABLE', 'method' => __METHOD__]
    );
    if (!$product->hasData($this->_configurableAttributes)) {
    $configurableAttributes = $this->getConfigurableAttributeCollection($product);
    $this->extensionAttributesJoinProcessor->process($configurableAttributes);
    $configurableAttributes->orderByPosition()->load();
    $product->setData($this->_configurableAttributes, $configurableAttributes);
    }
    MagentoFrameworkProfiler::stop('CONFIGURABLE:' . __METHOD__);
    return $product->getData($this->_configurableAttributes);
    }


    Here's a stack trace to help show where I'm up to.



    image










    share|improve this question

























      0












      0








      0








      I'm trying to get options which are out of stock to be passed to the frontend js renderer.



      However I've found that getJsonConfig() does not return attribute data (attribute labels and other data) for the options array that I pass it.



      // I have found that the configurable $options data is initially set here
      // I have made it so that this returns the entire array of attribute codes and product numbers -
      // - for the configurable regardless of stock status
      /* @var MagentoConfigurableProductHelperData $this->$helper */
      $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());


      Note that the $options[array] correctly contains all out of stock attribute ids => product ids



      $options array



      This $options array is passed to a function that attempts to serialize/add extra data that is required buy the js renderer such as labels.



      $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);



      /**
      * Get product attributes
      *
      * @param Product $product
      * @param array $options
      * @return array
      */
      public function getAttributesData(Product $product, array $options = )
      {
      $defaultValues = ;
      $attributes = ;
      $productInstance = $product->getTypeInstance();
      $productEnabledAttributes = $productInstance ->getConfigurableAttributes($product);
      foreach ($productEnabledAttributes as $attribute) {
      $attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
      if ($attributeOptionsData) {
      $productAttribute = $attribute->getProductAttribute();
      $attributeId = $productAttribute->getId();
      $attributes[$attributeId] = [
      'id' => $attributeId,
      'code' => $productAttribute->getAttributeCode(),
      'label' => $productAttribute->getStoreLabel($product->getStoreId()),
      'options' => $attributeOptionsData,
      'position' => $attribute->getPosition(),
      ];
      $defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
      }
      }
      return [
      'attributes' => $attributes,
      'defaultValues' => $defaultValues,
      ];
      }


      However getAttributesData does not obey the $options param. A sub call function must unwittingly run a filter operation. Observe below how the return $attributesData has filtered attribute "138"



      data filtered



      From the getAttributesData() function, I'm suspecting getConfigurableAttributes() to be the cause of out of stock options not displaying in magento 2.3, this function retrieves data from a cache that was generated a few clock cycles ago.



      /**
      * Retrieve configurable attributes data
      *
      * @param MagentoCatalogModelProduct $product
      * @return MagentoConfigurableProductModelProductTypeConfigurableAttribute
      */
      public function getConfigurableAttributes($product)
      {
      MagentoFrameworkProfiler::start(
      'CONFIGURABLE:' . __METHOD__,
      ['group' => 'CONFIGURABLE', 'method' => __METHOD__]
      );
      if (!$product->hasData($this->_configurableAttributes)) {
      $configurableAttributes = $this->getConfigurableAttributeCollection($product);
      $this->extensionAttributesJoinProcessor->process($configurableAttributes);
      $configurableAttributes->orderByPosition()->load();
      $product->setData($this->_configurableAttributes, $configurableAttributes);
      }
      MagentoFrameworkProfiler::stop('CONFIGURABLE:' . __METHOD__);
      return $product->getData($this->_configurableAttributes);
      }


      Here's a stack trace to help show where I'm up to.



      image










      share|improve this question














      I'm trying to get options which are out of stock to be passed to the frontend js renderer.



      However I've found that getJsonConfig() does not return attribute data (attribute labels and other data) for the options array that I pass it.



      // I have found that the configurable $options data is initially set here
      // I have made it so that this returns the entire array of attribute codes and product numbers -
      // - for the configurable regardless of stock status
      /* @var MagentoConfigurableProductHelperData $this->$helper */
      $options = $this->helper->getOptions($currentProduct, $this->getAllowProducts());


      Note that the $options[array] correctly contains all out of stock attribute ids => product ids



      $options array



      This $options array is passed to a function that attempts to serialize/add extra data that is required buy the js renderer such as labels.



      $attributesData = $this->configurableAttributeData->getAttributesData($currentProduct, $options);



      /**
      * Get product attributes
      *
      * @param Product $product
      * @param array $options
      * @return array
      */
      public function getAttributesData(Product $product, array $options = )
      {
      $defaultValues = ;
      $attributes = ;
      $productInstance = $product->getTypeInstance();
      $productEnabledAttributes = $productInstance ->getConfigurableAttributes($product);
      foreach ($productEnabledAttributes as $attribute) {
      $attributeOptionsData = $this->getAttributeOptionsData($attribute, $options);
      if ($attributeOptionsData) {
      $productAttribute = $attribute->getProductAttribute();
      $attributeId = $productAttribute->getId();
      $attributes[$attributeId] = [
      'id' => $attributeId,
      'code' => $productAttribute->getAttributeCode(),
      'label' => $productAttribute->getStoreLabel($product->getStoreId()),
      'options' => $attributeOptionsData,
      'position' => $attribute->getPosition(),
      ];
      $defaultValues[$attributeId] = $this->getAttributeConfigValue($attributeId, $product);
      }
      }
      return [
      'attributes' => $attributes,
      'defaultValues' => $defaultValues,
      ];
      }


      However getAttributesData does not obey the $options param. A sub call function must unwittingly run a filter operation. Observe below how the return $attributesData has filtered attribute "138"



      data filtered



      From the getAttributesData() function, I'm suspecting getConfigurableAttributes() to be the cause of out of stock options not displaying in magento 2.3, this function retrieves data from a cache that was generated a few clock cycles ago.



      /**
      * Retrieve configurable attributes data
      *
      * @param MagentoCatalogModelProduct $product
      * @return MagentoConfigurableProductModelProductTypeConfigurableAttribute
      */
      public function getConfigurableAttributes($product)
      {
      MagentoFrameworkProfiler::start(
      'CONFIGURABLE:' . __METHOD__,
      ['group' => 'CONFIGURABLE', 'method' => __METHOD__]
      );
      if (!$product->hasData($this->_configurableAttributes)) {
      $configurableAttributes = $this->getConfigurableAttributeCollection($product);
      $this->extensionAttributesJoinProcessor->process($configurableAttributes);
      $configurableAttributes->orderByPosition()->load();
      $product->setData($this->_configurableAttributes, $configurableAttributes);
      }
      MagentoFrameworkProfiler::stop('CONFIGURABLE:' . __METHOD__);
      return $product->getData($this->_configurableAttributes);
      }


      Here's a stack trace to help show where I'm up to.



      image







      magento2 configurable-product product-attribute






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 mins ago









      PathfinderPathfinder

      13711




      13711






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258091%2fget-out-of-stock-products-to-show-in-magento-2-3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258091%2fget-out-of-stock-products-to-show-in-magento-2-3%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy