/** * Get bundled selections (slections-products collection) * * Returns array of options objects. * Each option object will contain array of selections objects * * @return array */ public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $options = array(); $product = $item->getProduct(); $foundItem = Mage::getModel("catalog/product")->load($product->getId()); /** * @var Mage_Bundle_Model_Product_Type */ $typeInstance = $product->getTypeInstance(true); // get bundle options $optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids'); $bundleOptionsIds = unserialize($optionsQuoteItemOption->getValue()); 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'); $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) { if (!Mage::helper('not2order')->getShowPrice($foundItem)) { $option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName()); } else { $option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName()) . ' ' . Mage::helper('core')->currency($this->getSelectionFinalPrice($item, $bundleSelection)); } } } if ($option['value']) { $options[] = $option; } } } } return $options; }
/** * Prepare custom option for display, returns false if there's no value * * @param string $code * @return mixed */ public function prepareCustomOption(Mage_Catalog_Model_Product_Configuration_Item_Interface $item, $code) { $option = $item->getOptionByCode($code); if ($option) { $value = $option->getValue(); if ($value) { return $this->escapeHtml($value); } } return false; }
/** * Retrieves item links options * * @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item * @return array */ public function getLinks(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $product = $item->getProduct(); $itemLinks = array(); $linkIds = $item->getOptionByCode('downloadable_link_ids'); if ($linkIds) { $productLinks = $product->getTypeInstance(true)->getLinks($product); foreach (explode(',', $linkIds->getValue()) as $linkId) { if (isset($productLinks[$linkId])) { $itemLinks[] = $productLinks[$linkId]; } } } return $itemLinks; }
/** * Retrieves configuration options for grouped product * * @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item * @return array */ public function getGroupedOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $product = $item->getProduct(); $typeId = $product->getTypeId(); if ($typeId != Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { Mage::throwException($this->__('Wrong product type to extract configurable options.')); } $options = array(); /** * @var Mage_Catalog_Model_Product_Type_Grouped */ $typeInstance = $product->getTypeInstance(true); $associatedProducts = $typeInstance->getAssociatedProducts($product); if ($associatedProducts) { foreach ($associatedProducts as $associatedProduct) { $qty = $item->getOptionByCode('associated_product_' . $associatedProduct->getId()); $option = array('label' => $associatedProduct->getName(), 'value' => $qty && $qty->getValue() ? $qty->getValue() : 0); $options[] = $option; } } $options = array_merge($options, $this->getCustomOptions($item)); $isUnConfigured = true; foreach ($options as &$option) { if ($option['value']) { $isUnConfigured = false; break; } } return $isUnConfigured ? array() : $options; }
/** * Get bundled selections (slections-products collection) * * Returns array of options objects. * Each option object will contain array of selections objects * * @return array */ 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'); $additional_options = array(); $total_points = 0; foreach ($item->getChildren() as $bundle_item) { $_params = unserialize($bundle_item->getOptionByCode('info_buyRequest')->getValue()); if (isset($_params['additional_options'])) { try { $add_opts = end($_params['additional_options']); $additional_options[$bundle_item->getProductId()] = $add_opts; $total_points += intval($add_opts['orgi_value']); } catch (Exception $e) { Mage::log($e->getMessage()); } } } $store_id = Mage::app()->getStore()->getId(); if ($total_points > 0) { $options[] = array('label' => Mage::helper('rewardpoints')->__('Sell in Points'), 'value' => array(Mage::helper('rewardpoints')->formatPoints($total_points, $store_id))); } $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 (isset($additional_options[$bundleSelection->getId()]) && $additional_options[$bundleSelection->getId()]) { /*$option['value'][] = "<dt>".$additional_options[$bundleSelection->getId()]['label'] . "-" ."</dt><dd>".$additional_options[$bundleSelection->getId()]['value']."</dd>";*/ } } } if ($option['value']) { $options[] = $option; } } } } } return $options; }
/** * Get bundled selections (slections-products collection) * * Returns array of options objects. * Each option object will contain array of selections objects * * @return array */ 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'); $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) { $val = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName()) . ' '; if ($bundleSelection->getTypeId() == 'reservation') { if ($product->getBundlePricingtype() == ITwebexperts_Payperrentals_Model_Product_Bundlepricingtype::PRICING_BUNDLE_PERPRODUCT) { $customerGroup = ITwebexperts_Payperrentals_Helper_Data::getCustomerGroup(); if (!is_object($product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION))) { $source = unserialize($product->getCustomOption('info_buyRequest')->getValue()); if (isset($source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION])) { $start_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION]; $end_date = $source[ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION]; } } else { $start_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::START_DATE_OPTION)->getValue(); $end_date = $product->getCustomOption(ITwebexperts_Payperrentals_Model_Product_Type_Reservation::END_DATE_OPTION)->getValue(); } $data = new Varien_Object(array('start_date' => $start_date, 'end_date' => $end_date)); Mage::dispatchEvent('payperrentals_bundle_option_calculate_price_before', array('data' => $data, 'item' => $item, 'selection' => $bundleSelection)); extract($data->getData(), EXTR_OVERWRITE); $priceAmount = ITwebexperts_Payperrentals_Helper_Price::calculatePrice($bundleSelection, $start_date, $end_date, $qty, $customerGroup); $val .= Mage::helper('core')->currency($priceAmount); } else { } } else { $val .= Mage::helper('core')->currency($this->getSelectionFinalPrice($item, $bundleSelection)); } $option['value'][] = $val; } } if ($option['value']) { $options[] = $option; } } } } return $options; }
/** * Retrieves product configuration options * * @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item * @return array */ public function getCustomOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item) { $product = $item->getProduct(); $options = array(); $optionIds = $item->getOptionByCode('option_ids'); if ($optionIds) { $options = array(); foreach (explode(',', $optionIds->getValue()) as $optionId) { $option = $product->getOptionById($optionId); if ($option) { $itemOption = $item->getOptionByCode('option_' . $option->getId()); $group = $option->groupFactory($option->getType())->setOption($option)->setConfigurationItem($item)->setConfigurationItemOption($itemOption); if ('file' == $option->getType()) { $downloadParams = $item->getFileDownloadParams(); if ($downloadParams) { $url = $downloadParams->getUrl(); if ($url) { $group->setCustomOptionDownloadUrl($url); } $urlParams = $downloadParams->getUrlParams(); if ($urlParams) { $group->setCustomOptionUrlParams($urlParams); } } } $options[] = array('label' => $option->getTitle(), 'value' => $group->getFormattedOptionValue($itemOption->getValue()), 'print_value' => $group->getPrintableOptionValue($itemOption->getValue()), 'option_id' => $option->getId(), 'option_type' => $option->getType(), 'custom_view' => $group->isCustomizedView()); } } } $addOptions = $item->getOptionByCode('additional_options'); if ($addOptions) { $options = array_merge($options, unserialize($addOptions->getValue())); } return $options; }