【问题标题】:Add selection to bundle programmatically以编程方式将选择添加到捆绑包
【发布时间】:2011-11-09 02:10:17
【问题描述】:

在导入时我想将导入的产品作为捆绑产品添加到捆绑产品列表中。

我扩展了 Mage_Catalog_Model_Convert_Adapter_Product 并在自定义数据流中使用了这个类,在保存导入的行之前执行以下代码:

//Load product model collection filtered by attribute set id        
$products = Mage::getModel('catalog/product')
                ->getCollection()
                ->addAttributeToSelect('name')
                ->addFieldToFilter('attribute_set_id', 12);

// loop through products
foreach($products as $p){
    // get product options
    $options = $p->getTypeInstance(true)->getOptionsCollection($p);
}

接下来我需要做的是确定什么是正确的选项(按标题),并将产品作为选择添加到其中。

$option->addSelection($selection);

但是我如何获得选项标题以及如何从我的产品中创建选择?

【问题讨论】:

    标签: php oop model-view-controller zend-framework magento


    【解决方案1】:

    要获得我所做的选项标题:

    $option->getData('default_title');
    

    创建我所做的选择:

    $selection = new Mage_Bundle_Model_Selection();
    $selection->addData(array(
    'entity_id' => //bundle id,
    'option_id' => $option->getId(),
    'product_id' => //bundled item id,
    'selection_price_value' => 0.00,
    'selection_qty' => 1,
    'selection_can_change_qty' => 0,
    ));
    
    $selection->save();
    

    将选择添加到我所做的选项中:

    $option->addSelection($selection);
    $option->addData(array(
        'store_id' => 1,
        'title' => 'Abonnement'
    ));
    
     $option->save();
    

    我不知道为什么我必须设置标题和 store_id,因为该选项已经存在,所以我认为没有必要,但如果我不这样做,我会得到“缺少 store_id”或“缺少标题”错误。

    我喜欢 Magento,但它很大,文档应该更好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多