dongshu7162 2011-09-02 10:50
浏览 20
已采纳

添加选择以编程方式捆绑

on import I would like to add imported products as bundled products to a list of bundle products.

I extended Mage_Catalog_Model_Convert_Adapter_Product and used this class in a custom Dataflow, before the imported row is saved the following code is executed:

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

What I need to do next is determine what is the right option (by title), and add the product as a selection to it.

$option->addSelection($selection);

But how do I get the option title and how do i create the selection from my product?

  • 写回答

1条回答 默认 最新

  • douketangyouzh5219 2011-09-05 12:25
    关注

    To get the option title i did:

    $option->getData('default_title');
    

    To create the selection i did:

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

    to add the selection to the option i did:

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

    I don't know why i have to set the title and store_id, because the option already exists so i think it shouldn't be necessary, but if i don't do this i get a "missing store_id" or "missing title" error.

    I like Magento but it's huge, documentation should be better.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题