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: class Mage_Downloadable_Block_Catalog_Product_Links extends Mage_Catalog_Block_Product_Abstract
35: {
36: 37: 38: 39: 40:
41: public function getLinksPurchasedSeparately()
42: {
43: return $this->getProduct()->getLinksPurchasedSeparately();
44: }
45:
46: 47: 48: 49: 50:
51: public function getLinkSelectionRequired()
52: {
53: return $this->getProduct()->getTypeInstance(true)
54: ->getLinkSelectionRequired($this->getProduct());
55: }
56:
57: 58: 59: 60: 61:
62: public function hasLinks()
63: {
64: return $this->getProduct()->getTypeInstance(true)
65: ->hasLinks($this->getProduct());
66: }
67:
68: 69: 70: 71: 72:
73: public function getLinks()
74: {
75: return $this->getProduct()->getTypeInstance(true)
76: ->getLinks($this->getProduct());
77: }
78:
79: 80: 81: 82: 83: 84:
85: public function getFormattedLinkPrice($link)
86: {
87: $price = $link->getPrice();
88: $store = $this->getProduct()->getStore();
89:
90: if (0 == $price) {
91: return '';
92: }
93:
94: $taxCalculation = Mage::getSingleton('tax/calculation');
95: if (!$taxCalculation->getCustomer() && Mage::registry('current_customer')) {
96: $taxCalculation->setCustomer(Mage::registry('current_customer'));
97: }
98:
99: $taxHelper = Mage::helper('tax');
100: $coreHelper = $this->helper('core');
101: $_priceInclTax = $taxHelper->getPrice($link->getProduct(), $price, true);
102: $_priceExclTax = $taxHelper->getPrice($link->getProduct(), $price);
103:
104: $priceStr = '<span class="price-notice">+';
105: if ($taxHelper->displayPriceIncludingTax()) {
106: $priceStr .= $coreHelper->currencyByStore($_priceInclTax, $store);
107: } elseif ($taxHelper->displayPriceExcludingTax()) {
108: $priceStr .= $coreHelper->currencyByStore($_priceExclTax, $store);
109: } elseif ($taxHelper->displayBothPrices()) {
110: $priceStr .= $coreHelper->currencyByStore($_priceExclTax, $store);
111: if ($_priceInclTax != $_priceExclTax) {
112: $priceStr .= ' (+'.$coreHelper
113: ->currencyByStore($_priceInclTax, $store).' '.$this->__('Incl. Tax').')';
114: }
115: }
116: $priceStr .= '</span>';
117:
118: return $priceStr;
119: }
120:
121: 122: 123: 124: 125: 126:
127: public function getCurrencyPrice($price)
128: {
129: $store = $this->getProduct()->getStore();
130: return $this->helper('core')->currencyByStore($price, $store, false);
131: }
132:
133: 134: 135: 136: 137:
138: public function getJsonConfig()
139: {
140: $config = array();
141: $coreHelper = Mage::helper('core');
142:
143: foreach ($this->getLinks() as $link) {
144: $config[$link->getId()] = $coreHelper->currency($link->getPrice(), false, false);
145: }
146:
147: return $coreHelper->jsonEncode($config);
148: }
149:
150: public function getLinkSamlpeUrl($link)
151: {
152: return $this->getUrl('downloadable/download/linkSample', array('link_id' => $link->getId()));
153: }
154:
155: 156: 157: 158: 159:
160: public function getLinksTitle()
161: {
162: if ($this->getProduct()->getLinksTitle()) {
163: return $this->getProduct()->getLinksTitle();
164: }
165: return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE);
166: }
167:
168: 169: 170: 171: 172:
173: public function getIsOpenInNewWindow()
174: {
175: return Mage::getStoreConfigFlag(Mage_Downloadable_Model_Link::XML_PATH_TARGET_NEW_WINDOW);
176: }
177:
178: 179: 180: 181: 182: 183:
184: public function getIsLinkChecked($link)
185: {
186: $configValue = $this->getProduct()->getPreconfiguredValues()->getLinks();
187: if (!$configValue || !is_array($configValue)) {
188: return false;
189: }
190:
191: return $configValue && (in_array($link->getId(), $configValue));
192: }
193:
194: 195: 196: 197: 198: 199:
200: public function getLinkCheckedValue($link)
201: {
202: return $this->getIsLinkChecked($link) ? 'checked' : '';
203: }
204: }
205: