我正在寻找一个API,可以删除添加在主捆绑产品中的捆绑项目。
有人能带我去那个API吗?
问候你,伊尔凡
发布于 2012-03-21 22:52:24
以上不起作用,捆绑产品内的捆绑项目将以不同方式处理。有内部选项,称为选择。
// 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 ;发布于 2010-10-14 20:47:29
如果您只是想从可配置的产品中删除一个简单的产品:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.delete
发布于 2010-12-15 08:06:05
像这样的东西应该是有效的:
$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();
}https://stackoverflow.com/questions/3919332
复制相似问题