当我尝试获取产品的属性但只返回 NULL 时,我遇到了问题。
我正在尝试以下方法:
<? php
require 'app/Mage.php';
$app = Mage::app('default');
try {
$id = '4';
$product = Mage::getModel('catalog/product')->load($id);
$_attributes = $product->getAllowAttributes();
var_dump($_attributes);
} Catch(Exception $e){
echo $e->getMessage();
}
?>
我不知道我的产品是否缺少某些东西,如果您真的必须在可配置产品中拥有某些东西,请让我知道您应该拥有什么。
谢谢
产品模型中没有这种方法。因此,getAllowAttributes
将始终返回 null,除非您有一个名为 allow_attribtues
的属性,或者在调用方法之前调用 this:$product->setAllowAttributes('something')
。
如果您正在寻找一种方法来获取构建可配置产品所允许的属性,那么这就是您需要的:
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);