我正在寻找可以删除主捆绑产品中添加的捆绑项目的API。
有人可以指导我使用该API吗?
的问候, 伊尔凡
答案 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)
如果您只想从可配置产品中删除简单产品:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.delete
答案 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();
}