public function checkProductBuyState($product = null) { Mage_Catalog_Model_Product_Type_Abstract::checkProductBuyState($product); $product = $this->getProduct($product); $productOptionIds = $this->getOptionsIds($product); $productSelections = $this->getSelectionsCollection($productOptionIds, $product); $selectionIds = $product->getCustomOption('bundle_selection_ids'); $selectionIds = unserialize($selectionIds->getValue()); $buyRequest = $product->getCustomOption('info_buyRequest'); $buyRequest = new Varien_Object(unserialize($buyRequest->getValue())); $bundleOption = $buyRequest->getBundleOption(); if (empty($bundleOption)) { Mage::throwException($this->getSpecifyOptionMessage()); } $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck(); foreach ($selectionIds as $selectionId) { /* @var $selection Mage_Bundle_Model_Selection */ $selection = $productSelections->getItemById($selectionId); if (!$selection || !$selection->isSalable() && !$skipSaleableCheck) { Mage::throwException(Mage::helper('bundle')->__('Selected required options are not available.')); } } /* $product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product); $optionsCollection = $this->getOptionsCollection($product); foreach ($optionsCollection->getItems() as $option) { if ($option->getRequired() && empty($bundleOption[$option->getId()])) { Mage::throwException( Mage::helper('bundle')->__('Required options are not selected.') ); } } */ return $this; }
/** * Allow Fixed Bundles to be added to the cart without needing to submit the add to cart form * * @param Varien_Object $buyRequest * @param Mage_Catalog_Model_Product $product * @param string $processMode * @return array|string * @author Paul Hachmang <*****@*****.**> */ protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) { $product = $this->getProduct($product); $options = $buyRequest->getBundleOption(); $optionsCollection = $this->getOptionsCollection($product); if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && count($options) <= 0) { foreach ($optionsCollection->getItems() as $option) { if ($option->getType() == self::OPTION_TYPE_FIXED && $option->getRequired() && !isset($options[$option->getId()])) { $selectionData = Mage::getResourceSingleton('bundle/bundle')->getSelectionsData($product->getId()); foreach ($selectionData as $prod) { $options[$option->getId()][] = $prod['selection_id']; } } } //we are placing the new information in the request $buyRequest->setBundleOption($options); } return parent::_prepareProduct($buyRequest, $product, $processMode); }
/** * Prepare selected options for bundle product * * @param Mage_Catalog_Model_Product $product * @param Varien_Object $buyRequest * @return array */ public function processBuyRequest($product, $buyRequest) { $option = $buyRequest->getBundleOption(); $optionQty = $buyRequest->getBundleOptionQty(); $option = is_array($option) ? array_filter($option, 'intval') : array(); $optionQty = is_array($optionQty) ? array_filter($optionQty, 'intval') : array(); $options = array('bundle_option' => $option, 'bundle_option_qty' => $optionQty); return $options; }