【问题标题】:Configurable product asking for a super attribute要求超级属性的可配置产品
【发布时间】:2014-06-17 03:26:58
【问题描述】:

我正在 Magento 中以编程方式创建一个可配置的产品,除了当我浏览到该产品时,它要求我为该产品选择一个可配置的属性。

我似乎找不到可以添加可配置属性的代码。我的代码如下:

$parentProduct->setAttributeSetId(4)
    ->setTypeId('configurable')
    ->setStockData(array(
        'manage_stock'  => 0,
        'is_in_stock'   => 1,
        'qty'           => 99999,
        'min_sale_qty'  => 0,
        'max_sale_qty'  => 0,
    ))
    ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
    ->setTaxClassId(12) // P0000000
    ->setCreatedAt(time())
    ->setName($row['name'])
    ->setSku($sku)
    ->setPrice($row['price'])
    ->setCategoryIds(array(2, 3))
    ->setStatus(1)
    ->setWeight(1)
    ->setWebsiteIDs(array(1))
    ->setDescription($row['description'])
    ->setShortDescription($row['short_desc'])
    ->setHasOptions(true)
    ->setRequiredOptions(true);

$parentProduct->save();

【问题讨论】:

  • 那么问题出在哪里?
  • @hindmost 当 Francis 以编程方式创建产品然后进行编辑时,Magento 将“创建新的可配置产品”工作流程交给他。他在问如何以编程方式分配将成为可配置产品的“可配置”部分的超级属性。简短版:它非常特定于 Magento API。

标签: php magento


【解决方案1】:

终于找到了我要找的东西。

$parentProduct->setUsedProductAttributeIds(array(80)); // where 80 is color

$data = array(
    '0' => array(
        'id'        => NULL,
        'label'     => 'Color',
        'position'  => NULL,
        'values'    => array(
            '0' => array(
                'value_index'   => 4,
                'label'         => 'Silver',
                'is_percent'    => 0,
                'pricing_value' => '0',
                'attribute_id'  =>'80',
            ),
            '1' => array(
                'value_index'   => 3,
                'label'         => 'Gold',
                'is_percent'    => 0,
                'pricing_value' => '0',
                'attribute_id'  =>'80',
            ),
        ),
        'attribute_id'      => 80,
        'attribute_code'    => 'color',
        'frontend_label'    => 'Color',
        'html_id'           => 'config_super_product__attribute_0',
    ),
);
$parentProduct->setConfigurableAttributesData($data);

现在当我访问产品时,它不再要求我指定可配置属性。

【讨论】:

    猜你喜欢
    • 2012-04-22
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多