Magento的getAttributeText不一致
我正在尝试编写一些用于在 Magento 商店中浏览和搜索的自定义逻辑。
所以我想我应该覆盖 Mage_Catalog_Model_Layer 和 Mage_CatalogSearch_Model_Layer 的 getProductCollection。
我试图根据集合中某些产品的某些属性的值做出决策,但我似乎无法获取所有属性的文本值。
我重写的函数是:
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;
}
这会产生如下输出:
SKU:TEST_SKU_1
获取父级数据:TEST_SKU_2
ATTR 文本颜色:黑色
注意:
我添加“parent_sku”和“door_color”作为要选择的属性。
我可以使用 $product->getAttributeText() 访问door_color
我无法使用 $product->getAttributeText() 访问parent_sku
我可以通过 $product->getData() 访问parent_sku
任何时候我调用 $product->getAttributeText('parent_sku') 它都会返回 false。
我认为这是一个缓存问题,但我刷新了缓存,但这似乎没有帮助。
有谁知道为什么我无法通过 getAttributeText() 访问“parent_sku”的值?
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 based 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()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Parent_sku 是否实现为下拉框?我的理解是 getAttributeText 加载下拉选项并将它们从 ID 映射到文本。
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.