开发者

Magento's getAttributeText is inconsistent

开发者 https://www.devze.com 2023-02-17 19:35 出处:网络
I\'m trying to write some custom logic for browsing and searching in a Magento store. So I figured I\'d overwrite getProductCollection for both Mage_Catalog_Model_Layer and Mage_CatalogSearch_Model_L

I'm trying to write some custom logic for browsing and searching in a Magento store.

So I figured I'd overwrite getProductCollection for both Mage_Catalog_Model_Layer and Mage_CatalogSearch_Model_Layer.

I'm trying to make decisions b开发者_如何学运维ased on what the value of certain Attributes are for some of the products in the collection, but I can't seem to get the text value of all attributes.

The function as I've overwritten is:

public function getProductCollection()
{
    if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
        $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
    } else {
        $collection = $this->getCurrentCategory()->getProductCollection();
        $this->prepareProductCollection($collection);
        $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
    }

    //ben
    $collection->addAttributeToSelect('parent_sku');
    $collection->addAttributeToSelect('door_color');
    foreach($collection as $product) {
            echo "\nSKU: ".$product->getSku()."\n";
            $product_data = $product->getData();
            if(isset($product_data['parent_sku']) && ($product_data['parent_sku'] != '')) {
                    echo "GETDATA PARENT: ".$product_data['parent_sku']."\n";
            }
            if($product->getAttributeText('parent_sku') != '') {
                    echo "ATTR TEXT PARENT: ".$product->getAttributeText('parent_sku')."\n";
            }
            if($product->getAttributeText('door_color') != '') {
                    echo "ATTR TEXT COLOR: ".$product->getAttributeText('door_color')."\n";
            }
    }
    //end ben

    return $collection;
}

This produces output like:

SKU: TEST_SKU_1

GETDATA PARENT: TEST_SKU_2

ATTR TEXT COLOR: Black

Notice:

I add both 'parent_sku' and 'door_color' as attributes to select.

I can access door_color using $product->getAttributeText()

I cannot access parent_sku using $product->getAttributeText()

I can access parent_sku through $product->getData()

Any time I call $product->getAttributeText('parent_sku') it returns false.

I assumed that this was a caching problem, but I flushed the cache and that didn't seem to help.

Does anyone have a clue why I can't access the value of 'parent_sku' through getAttributeText()?


Is parent_sku implemented as a dropdown box? My understanding is that getAttributeText loaded dropdown options and mapped them from and ID to text for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号