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 \Magento\ConfigurableProduct\Helper\Data $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  \Magento\Catalog\Model\Product $product
     * @return \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute[]
     */
    public function getConfigurableAttributes($product)
    {
        \Magento\Framework\Profiler::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);
        }
        \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
        return $product->getData($this->_configurableAttributes);
    }

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

image

  • 1
    Don't know if it willl help you, but check in this file: /vendor/magento/module-inventory-catalog/Model/ResourceModel/AddStockDataToCollection.php In line 49 it's join instead of leftJoin which is causing deleting collection items not existing inside inventory tables. – dudzio Feb 11 at 10:37
  • yep I made that post on reddit 2 weeks ago. I've worked it out. Just forgot about my own question. – Pathfinder Feb 12 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.