Magento PHP:如何设置产品的可配置属性?

Magento PHP:如何设置产品的可配置属性?,php,magento,Php,Magento,设置可配置产品的可配置属性时遇到问题。 我的可配置和简单产品将显示在管理端。 但是当我点击一个可配置的产品时,我看到了这一点 我发现这个问题与我的问题相似 但我仍然无法正确设置配置产品 我正在调用我的类MagentoProduct,并将“color\u of\u product”作为属性代码传递给我的“setConfigurableAttributesData”方法。 我稍后通过调用“save()”来保存产品 } my setConfigurableAttributesData函数中的回声

设置可配置产品的可配置属性时遇到问题。
我的可配置和简单产品将显示在管理端。
但是当我点击一个可配置的产品时,我看到了这一点

我发现这个问题与我的问题相似
但我仍然无法正确设置配置产品



我正在调用我的类MagentoProduct,并将“color\u of\u product”作为属性代码传递给我的“setConfigurableAttributesData”方法。
我稍后通过调用“save()”来保存产品

}

my setConfigurableAttributesData函数中的回声正在打印:

颜色
0
数组
176
产品的颜色
颜色

我做错了什么?

我已经试着调试了几个小时,但仍然无法解决这个问题。

如果要使用产品的颜色设置可配置产品,则必须将此属性设置为

1) 全球的

2) 下拉列表

3) 适用于可配置产品和简单产品

4) 设置“是”用于创建可配置产品

如果要了解更多信息,请检查默认magento的颜色属性


如果要使用产品的颜色设置可配置产品,则必须将此属性设置为

1) 全球的

2) 下拉列表

3) 适用于可配置产品和简单产品

4) 设置“是”用于创建可配置产品

如果要了解更多信息,请检查默认magento的颜色属性

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());
    }   
}