Created
August 16, 2018 08:16
-
-
Save zeloc/4d1764fc3aeda6b7020fa7d9efd3be1d to your computer and use it in GitHub Desktop.
magento get bundle selected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ini_set('memory_limit','10G'); | |
require_once('abstract.php'); | |
class Bundle_Cart_Item_Option_Items extends Mage_Shell_Abstract | |
{ | |
/** | |
* Entry point | |
*/ | |
public function run() | |
{ | |
$selections = array(); | |
$cart = Mage::getModel('checkout/cart')->getQuote(); | |
if(!$cart->getAllItems()){ | |
var_dump('empty cart'); | |
return; | |
} | |
foreach ($cart->getAllItems() as $_item) { | |
$selections = $this->getBundleOrderItemSelections($_item->getProduct()); | |
} | |
var_dump($selections); | |
} | |
/** | |
* @param $bundleProduct Mage_Catalog_Model_Product | |
* @return array | |
*/ | |
public function getBundleOrderItemSelections($bundleProduct) | |
{ | |
$selectionSkus = array(); | |
if($bundleProduct->getTypeId()==='bundle') { | |
/** @var Mage_Bundle_Model_Product_Type $instance */ | |
$instance = $bundleProduct->getTypeInstance(true); | |
$customOption = $bundleProduct->getCustomOption('bundle_selection_ids'); | |
$selectionIds = unserialize($customOption->getValue()); | |
$selections = $instance->getSelectionsByIds($selectionIds, $bundleProduct); | |
foreach ($selections->getItems() as $selection) { | |
$selectionSkus[] = $selection->getSku(); | |
} | |
} | |
return array_unique($selectionSkus); | |
} | |
} | |
$ids = new Bundle_Cart_Item_Option_Items(); | |
$ids->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment