I am looking for an API that can remove bundle items added in a main bundle product.
Can some one gui开发者_如何学运维de me to that API?
regards, Irfan
above does not work , Bundled items inside a bundle product are treated differently. There are inside Options and are called Selections.
// 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);
Another Easyier way is to Delete your Item from the bundle/Selection table :
$sql = "DELETE FROM " . $this->getTable('bundle/selection') . " WHERE 'product_id' = " . $YOUR_ITEM_TO_REMOVE_ID ;
If your just trying to remove a simple product from a configurable product:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.delete
Something like this should work:
$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();
}
精彩评论