Magento使用API​​删除捆绑项

时间:2010-10-12 21:52:18

标签: magento

我正在寻找可以删除主捆绑产品中添加的捆绑项目的API。

有人可以指导我使用该API吗?

的问候, 伊尔凡

3 个答案:

答案 0 :(得分:1)

上面的

不起作用,捆绑产品中的捆绑商品的处理方式不同。有选项内部,称为选择。

    // get all the options of your bundle product assumed as $bundle
    $optionCollection = $bundle->getTypeInstance()->getOptionsCollection($bundle);
    $selectionIds = $optionIds = array();
    // and their Id into an array
    foreach($optionCollection as $opt) {
        $optionIds[] = $opt->getOptionId();
    }
    // fetch all the selections from all the previous Ids
    $selectionCollection = $bundle->getTypeInstance()->getSelectionsCollection($optionIds);
    foreach($selectionCollection as $sc) {
        if ($sc->getId()!=$itemToRemoveId) $selectionIds[] = $sc->getSelectionId();
    }

    // remove the Selection/Bundle association from database, we need to pass all the others except the one we need to drop
    Mage::getModel('bundle/mysql4_bundle')->dropAllUnneededSelections($bundle->getId(), $selectionIds);

另一种更简单的方法是从捆绑/选择表中删除您的项目:

$sql = "DELETE FROM " . $this->getTable('bundle/selection') . " WHERE 'product_id' = " . $YOUR_ITEM_TO_REMOVE_ID ;

答案 1 :(得分:0)

答案 2 :(得分:0)

这样的事情应该有效:

    $bundled_product = Mage::getModel('catalog/product');
    $bundled_product->load($product->getId());

    $optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
    $selectionCollection = $bundled_product
    ->getTypeInstance(true)
    ->getSelectionsCollection(
    $bundled_product
    ->getTypeInstance(true)
    ->getOptionsIds($bundled_product),
    $bundled_product
    );
    foreach($optionCollection as $option){
        $option->delete();
    }