1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: abstract class Mage_Catalog_Block_Product_View_Options_Abstract extends Mage_Core_Block_Template
36: {
37: 38: 39: 40: 41:
42: protected $_product;
43:
44: 45: 46: 47: 48:
49: protected $_option;
50:
51: 52: 53: 54: 55: 56:
57: public function setProduct(Mage_Catalog_Model_Product $product = null)
58: {
59: $this->_product = $product;
60: return $this;
61: }
62:
63: 64: 65: 66: 67:
68: public function getProduct()
69: {
70: return $this->_product;
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function setOption(Mage_Catalog_Model_Product_Option $option)
80: {
81: $this->_option = $option;
82: return $this;
83: }
84:
85: 86: 87: 88: 89:
90: public function getOption()
91: {
92: return $this->_option;
93: }
94:
95: public function getFormatedPrice()
96: {
97: if ($option = $this->getOption()) {
98: return $this->_formatPrice(array(
99: 'is_percent' => ($option->getPriceType() == 'percent'),
100: 'pricing_value' => $option->getPrice($option->getPriceType() == 'percent')
101: ));
102: }
103: return '';
104: }
105:
106: 107: 108: 109: 110: 111:
112: protected function _formatPrice($value, $flag=true)
113: {
114: if ($value['pricing_value'] == 0) {
115: return '';
116: }
117:
118: $taxHelper = Mage::helper('tax');
119: $store = $this->getProduct()->getStore();
120:
121: $sign = '+';
122: if ($value['pricing_value'] < 0) {
123: $sign = '-';
124: $value['pricing_value'] = 0 - $value['pricing_value'];
125: }
126:
127: $priceStr = $sign;
128: $_priceInclTax = $this->getPrice($value['pricing_value'], true);
129: $_priceExclTax = $this->getPrice($value['pricing_value']);
130: if ($taxHelper->displayPriceIncludingTax()) {
131: $priceStr .= $this->helper('core')->currencyByStore($_priceInclTax, $store, true, $flag);
132: } elseif ($taxHelper->displayPriceExcludingTax()) {
133: $priceStr .= $this->helper('core')->currencyByStore($_priceExclTax, $store, true, $flag);
134: } elseif ($taxHelper->displayBothPrices()) {
135: $priceStr .= $this->helper('core')->currencyByStore($_priceExclTax, $store, true, $flag);
136: if ($_priceInclTax != $_priceExclTax) {
137: $priceStr .= ' ('.$sign.$this->helper('core')
138: ->currencyByStore($_priceInclTax, $store, true, $flag).' '.$this->__('Incl. Tax').')';
139: }
140: }
141:
142: if ($flag) {
143: $priceStr = '<span class="price-notice">'.$priceStr.'</span>';
144: }
145:
146: return $priceStr;
147: }
148:
149: 150: 151: 152: 153: 154: 155:
156: public function getPrice($price, $includingTax = null)
157: {
158: if (!is_null($includingTax)) {
159: $price = Mage::helper('tax')->getPrice($this->getProduct(), $price, true);
160: } else {
161: $price = Mage::helper('tax')->getPrice($this->getProduct(), $price);
162: }
163: return $price;
164: }
165:
166: 167: 168: 169: 170: 171:
172: public function getCurrencyPrice($price)
173: {
174: $store = $this->getProduct()->getStore();
175: return $this->helper('core')->currencyByStore($price, $store, false);
176: }
177: }
178: