00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Bundle_Block_Catalog_Product_View_Type_Bundle extends Mage_Catalog_Block_Product_View_Abstract
00036 {
00037 protected $_optionRenderers = array();
00038 protected $_options = null;
00039
00040 public function getOptions()
00041 {
00042 if (!$this->_options) {
00043 $this->getProduct()->getTypeInstance(true)->setStoreFilter($this->getProduct()->getStoreId(), $this->getProduct());
00044
00045 $optionCollection = $this->getProduct()->getTypeInstance(true)->getOptionsCollection($this->getProduct());
00046
00047 $selectionCollection = $this->getProduct()->getTypeInstance(true)->getSelectionsCollection(
00048 $this->getProduct()->getTypeInstance(true)->getOptionsIds($this->getProduct()),
00049 $this->getProduct()
00050 );
00051
00052 $this->_options = $optionCollection->appendSelections($selectionCollection, false, false);
00053 }
00054 return $this->_options;
00055 }
00056
00057 public function hasOptions()
00058 {
00059 $this->getOptions();
00060 if (empty($this->_options) || !$this->getProduct()->isSalable()) {
00061 return false;
00062 }
00063 return true;
00064 }
00065
00066 public function getJsonConfig()
00067 {
00068 Mage::app()->getLocale()->getJsPriceFormat();
00069 $store = Mage::app()->getStore();
00070 $optionsArray = $this->getOptions();
00071 $options = array();
00072 $selected = array();
00073
00074 foreach ($optionsArray as $_option) {
00075 if (!$_option->getSelections()) {
00076 continue;
00077 }
00078 $option = array (
00079 'selections' => array(),
00080 'title' => $_option->getTitle(),
00081 'isMulti' => ($_option->getType() == 'multi' || $_option->getType() == 'checkbox')
00082 );
00083
00084 $selectionCount = count($_option->getSelections());
00085
00086 foreach ($_option->getSelections() as $_selection) {
00087 $_qty = !($_selection->getSelectionQty()*1)?'1':$_selection->getSelectionQty()*1;
00088 $selection = array (
00089 'qty' => $_qty,
00090 'customQty' => $_selection->getSelectionCanChangeQty(),
00091 'price' => Mage::helper('core')->currency($_selection->getFinalPrice(), false, false),
00092 'priceValue' => Mage::helper('core')->currency($_selection->getSelectionPriceValue(), false, false),
00093 'priceType' => $_selection->getSelectionPriceType(),
00094 'tierPrice' => $_selection->getTierPrice(),
00095 'name' => $_selection->getName(),
00096 'plusDisposition' => 0,
00097 'minusDisposition' => 0,
00098 );
00099 $responseObject = new Varien_Object();
00100 $args = array('response_object'=>$responseObject, 'selection'=>$_selection);
00101 Mage::dispatchEvent('bundle_product_view_config', $args);
00102 if (is_array($responseObject->getAdditionalOptions())) {
00103 foreach ($responseObject->getAdditionalOptions() as $o=>$v) {
00104 $selection[$o] = $v;
00105 }
00106 }
00107 $option['selections'][$_selection->getSelectionId()] = $selection;
00108
00109 if (($_selection->getIsDefault() || ($selectionCount == 1 && $_option->getRequired())) && $_selection->isSalable()) {
00110 $selected[$_option->getId()][] = $_selection->getSelectionId();
00111 }
00112 }
00113 $options[$_option->getId()] = $option;
00114 }
00115
00116 $config = array(
00117 'options' => $options,
00118 'selected' => $selected,
00119 'bundleId' => $this->getProduct()->getId(),
00120 'priceFormat' => Mage::app()->getLocale()->getJsPriceFormat(),
00121 'basePrice' => Mage::helper('core')->currency($this->getProduct()->getPrice(), false, false),
00122 'priceType' => $this->getProduct()->getPriceType(),
00123 'specialPrice' => $this->getProduct()->getSpecialPrice()
00124 );
00125
00126 return Zend_Json::encode($config);
00127 }
00128
00129 public function addRenderer($type, $block)
00130 {
00131 $this->_optionRenderers[$type] = $block;
00132 }
00133
00134 public function getOptionHtml($option)
00135 {
00136 if (!isset($this->_optionRenderers[$option->getType()])) {
00137 return $this->__('There is no defined renderer for "%s" option type', $option->getType());
00138 }
00139 return $this->getLayout()->createBlock($this->_optionRenderers[$option->getType()])
00140 ->setOption($option)->toHtml();
00141 }
00142
00143 }