2

We are trying to display the prices on some configurable products, but the prices always show 0, unless we force the object. Here's what I mean, in code :

foreach ($this->getAllowProducts() as $product) {
    $productId  = $product->getId();
    $price = $product->getPrice();
}

$productId has the correct value. $price is 0.

Now, if I force the object like so :

foreach ($this->getAllowProducts() as $product) {
    $productId  = $product->getId();
    $product = Mage::getModel('catalog/product')->load($productId);
    $price = $product->getPrice();
}

Now $price has the correct value.

Thanks,

3

the method getAllowProducts calls Mage_Catalog_Model_Product_Type_Configurable::getUsedProducts() that contains this code:

$collection = $this->getUsedProductCollection($product)
    ->addFilterByRequiredOptions();

// Provides a mechanism for attaching additional attributes to the children of configurable products
// Will primarily have affect on the configurable product view page
$childAttributes = Mage::getConfig()->getNode(self::XML_PATH_PRODUCT_CONFIGURABLE_CHILD_ATTRIBUTES);

if ($childAttributes) {
    $childAttributes = $childAttributes->asArray();
    $childAttributes = array_keys($childAttributes);

    $collection->addAttributeToSelect($childAttributes);
}

this means that the attributes found in the config node self::XML_PATH_PRODUCT_CONFIGURABLE_CHILD_ATTRIBUTES are added to the collection.
the value of self::XML_PATH_PRODUCT_CONFIGURABLE_CHILD_ATTRIBUTES is frontend/product/configurable/child/attributes.

This means you can try to create a custom module and in the config.xml of the module add this:

<config>
    ...
    <frontend>
        <product>
            <configurable>
                <child>
                    <attributes>
                        <price />
                    </attributes>
                </child>
            </configurable>
        </product>
    </frontend>
    ...
</config>

this should add the price attribute to the collection.

  • Thanks, I was having trouble figuring out why the child products all had status set to 1. Turns out it is because by default the getStatus() method returns 1 if the attribute value was not fetched. Since the upgrade to EE 1.14 the status attribute of child products was no longer being fetched by default but logic depending on it was just carrying on as if all products were set to "enabled". – fantasticrice Jul 8 '16 at 21:59
0

This problem may occur when updating from a Magento version older than 1.9.1.0 to version 1.9.1.0 or later. The behavior described by Marius has been introduced in version 1.9.1.0 which is mentioned in the release notes:

Improved calculation performance on configurable products with thousands of attributes.

Before 1.9.1.0 simply all attributes were loaded into the collection by addAttributeToSelect('*')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.