首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento使用API删除捆绑项

Magento使用API删除捆绑项
EN

Stack Overflow用户
提问于 2010-10-13 05:52:18
回答 3查看 1.8K关注 0票数 1

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

有人能带我去那个API吗?

问候你,伊尔凡

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-03-21 22:52:24

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

代码语言:javascript
复制
    // 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);

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

代码语言:javascript
复制
$sql = "DELETE FROM " . $this->getTable('bundle/selection') . " WHERE 'product_id' = " . $YOUR_ITEM_TO_REMOVE_ID ;
票数 1
EN

Stack Overflow用户

发布于 2010-10-14 20:47:29

如果您只是想从可配置的产品中删除一个简单的产品:

http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.delete

票数 0
EN

Stack Overflow用户

发布于 2010-12-15 08:06:05

像这样的东西应该是有效的:

代码语言:javascript
复制
    $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();
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3919332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档