Suppose I have a bundle product added into the cart. Now when I try to get all cart items that time I need to find particular bundle child is added with x bundle product.
Is it possible to find ?
addtocartbundled-productshopping-cart
Suppose I have a bundle product added into the cart. Now when I try to get all cart items that time I need to find particular bundle child is added with x bundle product.
Is it possible to find ?
answering self for future seekers:
$item->getParentItemId()
source: http://davehiren.blogspot.co.il/2014/02/magento-get-cart-items-how-to-get.html
First copied from
app/code/core/Mage/Bundle/Helper/Catalog/Product/Configuration.php
file and put it to
app/code/local/Mage/Bundle/Helper/Catalog/Product/Configuration.php
After replace code from function getBundleOptions()
public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
$options = array();
$product = $item->getProduct();
/**
* @var Mage_Bundle_Model_Product_Type
*/
$typeInstance = $product->getTypeInstance(true);
// get bundle options
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
$bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
if ($bundleOptionsIds) {
/**
* @var Mage_Bundle_Model_Mysql4_Option_Collection
*/
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
// get and add bundle selections collection
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
$bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
if (!empty($bundleSelectionIds)) {
$selectionsCollection = $typeInstance->getSelectionsByIds(
unserialize($selectionsQuoteItemOption->getValue()),
$product
);
$bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
foreach ($bundleOptions as $bundleOption) {
if ($bundleOption->getSelections()) {
$option = array(
'label' => $bundleOption->getTitle(),
'value' => array()
);
$bundleSelections = $bundleOption->getSelections();
foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
. ' ' . Mage::helper('core')->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
}
}
if ($option['value']) {
$options[] = $option;
}
}
}
}
}
return $options;
}
TO
public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
$options = array();
$product = $item->getProduct();
/**
* @var Mage_Bundle_Model_Product_Type
*/
$typeInstance = $product->getTypeInstance(true);
// get bundle options
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
$bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue()) : array();
if ($bundleOptionsIds) {
/**
* @var Mage_Bundle_Model_Mysql4_Option_Collection
*/
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
// get and add bundle selections collection
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
$bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue());
if (!empty($bundleSelectionIds)) {
$selectionsCollection = $typeInstance->getSelectionsByIds(
unserialize($selectionsQuoteItemOption->getValue()),
$product
);
$bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
foreach ($bundleOptions as $bundleOption) {
if ($bundleOption->getSelections()) {
$option = array(
'label' => $bundleOption->getTitle(),
'value' => array()
);
$bundleSelections = $bundleOption->getSelections();
foreach ($bundleSelections as $bundleSelection) {
$thumbnail = Mage::helper('catalog/image')->init($bundleSelection, 'thumbnail')->resize();
$imageUrl = '<img src="'.$thumbnail.'" width="75" height="75"/>';
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $imageUrl.' '. $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
. ' ' . Mage::helper('core')->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
}
}
if ($option['value']) {
$options[] = $option;
}
}
}
}
}
return $options;
}
Best Answer
You can try below code rendering bundle product items from quote.