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: 36: 37: 38:
39: class Eabi_DpdEE_Helper_Data extends Mage_Core_Helper_Abstract {
40: protected $_apis = array();
41:
42: 43: 44: 45: 46: 47:
48: public function getApi($storeId = null, $code = 'eabidpdee') {
49: if ($storeId === null) {
50: $storeId = Mage::app()->getStore($storeId)->getId();
51: }
52: if (isset($this->_apis[$code]) && isset($this->_apis[$code][$storeId])) {
53: return $this->_apis[$code][$storeId];
54: }
55: if (!isset($this->_apis[$code])) {
56: $this->_apis[$code] = array();
57: }
58: $api = Mage::getModel('eabi_dpdee/api');
59: $api->setStore($storeId);
60: $api->setCode($code);
61: $this->_apis[$code][$storeId] = $api;
62: return $this->_apis[$code][$storeId];
63: }
64:
65:
66: 67: 68: 69:
70: public function isShippingMethodApplicable(Mage_Sales_Model_Order $order) {
71: return strpos($order->getShippingMethod(), 'eabidpdee') === 0;
72: }
73:
74:
75:
76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
87: public function getOpeningsDescriptionFromTerminal($dpdOpeningDescription, $locale = null) {
88: $openingTimeFormat = 'H:m';
89: $displayTimeFormat = 'H:mm';
90:
91: if (!$locale) {
92: $locale = Mage::app()->getLocale()->getLocaleCode();
93: }
94:
95:
96: $passThruOrder = array('2', '3', '4', '5', '6', '7', '1');
97:
98: 99: 100:
101: $openingDescriptions = array();
102:
103:
104: $startTime = new Zend_Date(0, Zend_Date::TIMESTAMP);
105: $endTime = new Zend_Date(0, Zend_Date::TIMESTAMP);
106:
107:
108: $openings = explode(',', $dpdOpeningDescription);
109: 110: 111: 112: 113: 114: 115: 116: 117:
118: foreach ($openings as $opening) {
119: $openTimePartials = explode(':', $opening);
120: $startTime->set($openTimePartials[1].':'.$openTimePartials[2], $openingTimeFormat);
121: $endTime->set($openTimePartials[3].':'.$openTimePartials[4], $openingTimeFormat);
122:
123: if (!isset($openingDescriptions[(string)$openTimePartials[0]])) {
124: $openingDescriptions[(string)$openTimePartials[0]] = array();
125: }
126: $openingDescriptions[(string)$openTimePartials[0]][] = str_replace(':00', '', $startTime->get($displayTimeFormat)) .'-'. str_replace(':00', '', $endTime->get($displayTimeFormat));
127:
128: }
129:
130:
131: 132: 133: 134: 135:
136: $finalOpeningDescriptions = array();
137: $previusOpeningStatement = false;
138: $previusWeekdayName = false;
139: $firstElement = false;
140:
141:
142: foreach ($passThruOrder as $dayOfWeekDigit) {
143: $startTime->set($dayOfWeekDigit - 1, Zend_Date::WEEKDAY_DIGIT);
144:
145: $weekDayName = $startTime->get(Zend_Date::WEEKDAY_NARROW, $locale);
146: if ($firstElement === false) {
147: $firstElement = $previusWeekdayName;
148: }
149: if (isset($openingDescriptions[$dayOfWeekDigit])) {
150:
151: $openingStatement = str_replace('0-0', '0-24', implode(',', $openingDescriptions[$dayOfWeekDigit]));
152: } else {
153: $openingStatement = '';
154: }
155:
156: if ($previusOpeningStatement !== false && $previusOpeningStatement != $openingStatement) {
157:
158: if ($firstElement != $previusWeekdayName) {
159: $finalOpeningDescriptions[] = $firstElement.'-'.$previusWeekdayName.' '.$previusOpeningStatement;
160: } else {
161: $finalOpeningDescriptions[] = $previusWeekdayName.' '.$previusOpeningStatement;
162: }
163:
164:
165: $firstElement = false;
166: }
167: $previusOpeningStatement = $openingStatement;
168: $previusWeekdayName = $weekDayName;
169:
170: }
171: if ($previusOpeningStatement !== false) {
172: if ($previusOpeningStatement !== '') {
173:
174: if (!$firstElement) {
175: $finalOpeningDescriptions[] = $previusWeekdayName . ' ' . $previusOpeningStatement;
176: } else {
177: $finalOpeningDescriptions[] = $firstElement . '-' . $previusWeekdayName . ' ' . $previusOpeningStatement;
178: }
179: }
180: }
181:
182: if (count($finalOpeningDescriptions)) {
183: return '('.implode('; ', $finalOpeningDescriptions).')';
184: }
185: return '';
186: }
187:
188:
189: }
190:
191: