【发布时间】:2016-10-28 19:55:56
【问题描述】:
我在为可配置产品设置可配置属性时遇到问题。
我的可配置和简单的产品正在管理端显示。
但是当我点击一个可配置的产品时,我看到了这个
我发现这个问题与我的类似
Magento 'Select Configurable Attributes' with PHP
但我仍然无法正确设置我的配置产品。
我正在调用我的类 MagentoProduct 并将“color_of_product”作为我的属性代码传递给我的“setConfigurableAttributesData”方法。
我稍后通过调用“save()”来保存产品。
class MagentoProduct {
private $product;
public function __construct ( ) {
Mage::init();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$this->product = Mage::getModel('catalog/product');
}
...
...
...
public function setConfigurableAttributesData($attribute_code){
$super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attribute_code);
$configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute);
$newAttributes[] = array(
'id' => $configurableAtt->getId(),
'label' => $configurableAtt->getLabel(),
'position' => $super_attribute->getPosition(),
//not 100% if values is correct, what do I set this to?
'values' => $configurableAtt->getPrices() ? $this->product->getPrices() : array(),
'attribute_id' => $super_attribute->getId(),
'attribute_code' => $super_attribute->getAttributeCode(),
'frontend_label' => $super_attribute->getFrontend()->getLabel(),
);
echo $configurableAtt->getId()."\n";
echo $configurableAtt->getLabel()."\n";
echo $super_attribute->getPosition()."\n";
//not 100% if values is correct, what do I set this to?
$temp = $configurableAtt->getPrices() ? $this->product->getPrices() : array();
echo $temp."\n";
echo $super_attribute->getId()."\n";
echo $super_attribute->getAttributeCode()."\n";
echo $super_attribute->getFrontend()->getLabel()."\n";
$this->product->setCanSaveConfigurableAttributes(true);
$this->product->setConfigurableAttributesData($newAttributes);
}
...
...
public function save(){
try{
$this->product->save();
}catch(Exception $e){
echo $e->getMessage();
Mage::log($e->getMessage());
}
}
}
我的 setConfigurableAttributesData 函数中的回声正在打印:
颜色
0
数组
176
产品颜色
颜色
我做错了什么?
我已经尝试调试了几个小时,但无法弄清楚。
【问题讨论】: