1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14:
15: class IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Package
16: {
17:
18: protected $_fedexPackages;
19:
20:
21: 22: 23:
24: public function __construct()
25: {
26:
27: $this->_fedexPackages = array
28: (
29: 'FEDEX_ENVELOPE' => array
30: (
31: 'label' => Mage::helper('usa')->__('FedEx Envelope'),
32: 'length' => 13.2,
33: 'width' => 9.25,
34: 'height' => 0.1,
35: 'baseline' => 0.1125,
36: 'max_weight' => 1.1
37: ),
38: 'FEDEX_PAK' => array
39: (
40: 'label' => Mage::helper('usa')->__('FedEx Pak'),
41: 'length' => 15.5,
42: 'width' => 12.0,
43: 'height' => 0.1,
44: 'baseline' => 0.0625,
45: 'max_weight' => 5.5
46: ),
47: 'FEDEX_TUBE' => array
48: (
49: 'label' => Mage::helper('usa')->__('FedEx Tube'),
50: 'length' => 38,
51: 'width' => 3.95,
52: 'height' => 3.95,
53: 'baseline' => 0.0,
54: 'max_weight' => 20.0
55: ),
56: 'FEDEX_10KG_BOX' => array
57: (
58: 'label' => Mage::helper('usa')->__('FedEx 10kg Box'),
59: 'length' => 15.81,
60: 'width' => 12.94,
61: 'height' => 10.19,
62: 'baseline' => 0.0,
63: 'max_weight' => 22.0
64: ),
65: 'FEDEX_25KG_BOX' => array
66: (
67: 'label' => Mage::helper('usa')->__('FedEx 25kg Box'),
68: 'length' => 21.56,
69: 'width' => 16.56,
70: 'height' => 13.19,
71: 'baseline' => 0.0,
72: 'max_weight' => 55.0
73: ),
74: 'YOUR_PACKAGING' => array
75: (
76: 'label' => Mage::helper('usa')->__('Your Packaging'),
77: 'length' => null,
78: 'width' => null,
79: 'height' => null,
80: 'baseline' => null,
81: 'max_weight' => Mage::getStoreConfig('usa/shipping_carriers_fedex/max_package_weight')
82: )
83: );
84:
85:
86: if ($this->getDimensionUnits() == 'CM')
87: {
88: foreach($this->_fedexPackages as &$package)
89: {
90: $this->toCM($package['length']);
91: $this->toCM($package['width']);
92: $this->toCM($package['height']);
93: }
94: }
95:
96:
97: if ($this->getWeightUnits() == 'KG')
98: {
99: foreach($this->_fedexPackages as &$package)
100: {
101: $this->toKG($package['max_weight']);
102: $this->toKG($package['baseline']);
103: }
104: }
105:
106:
107: if ($this->getWeightUnits() == 'G')
108: {
109: foreach($this->_fedexPackages as &$package)
110: {
111: $this->toG($package['max_weight']);
112: $this->toG($package['baseline']);
113: }
114: }
115:
116:
117: $this->setVolume();
118: }
119:
120:
121: 122: 123: 124: 125:
126: public function getFedexPackages()
127: {
128: return $this->_fedexPackages;
129: }
130:
131:
132: 133: 134: 135: 136:
137: public function getPackages()
138: {
139: $packages = array();
140:
141: if ($_fedexPackages = explode(',', Mage::getStoreConfig('carriers/fedex/packaging'))) {
142: foreach ($this->getFedexPackages() as $key => $value) {
143: foreach ($_fedexPackages as $_fedexPackage) {
144: if ($_fedexPackage == $key) {
145: $packages[$key] = $value;
146: }
147: }
148: }
149: }
150:
151: if (is_array($packages)) {
152: return $packages;
153: }
154:
155: return false;
156: }
157:
158:
159: 160: 161: 162: 163:
164: public function getDimensionUnits()
165: {
166: return Mage::getSingleton('usa/shipping_carrier_fedex')->getDimensionUnits();
167: }
168:
169:
170:
171: 172: 173: 174: 175:
176: public function getWeightUnits()
177: {
178: return Mage::getSingleton('usa/shipping_carrier_fedex')->getWeightUnits();
179: }
180:
181:
182:
183: 184: 185:
186: public function setVolume()
187: {
188: foreach ($this->_fedexPackages as $key => &$package) {
189: $this->_fedexPackages[$key]['max_volume'] = round($package['width'] * $package['height'] * $package['length'], 2);
190: }
191: }
192:
193:
194:
195: 196: 197: 198: 199:
200: public function toCM(&$val)
201: {
202: $val = round($val * 2.54, 1);
203: }
204:
205:
206:
207: 208: 209: 210: 211:
212: public function toG(&$val)
213: {
214: $val = round($val * 453.59237, 1);
215: }
216:
217:
218:
219: 220: 221: 222: 223:
224: public function toKG(&$val)
225: {
226: $val = round($val * 0.45359237, 1);
227: }
228:
229:
230:
231: 232: 233: 234: 235: 236:
237: public function getPackageMaxWeight($value)
238: {
239: return $this->_fedexPackages[$value]['max_weight'];
240: }
241:
242:
243:
244: 245: 246: 247: 248: 249:
250: public function getPackageLength($value)
251: {
252: return $this->_fedexPackages[$value]['length'];
253: }
254:
255:
256:
257: 258: 259: 260: 261: 262:
263: public function getPackageWidth($alue)
264: {
265: return $this->_fedexPackages[$value]['width'];
266: }
267:
268:
269:
270: 271: 272: 273: 274: 275:
276: public function getPackageHeight($value)
277: {
278: return $this->_fedexPackages[$value]['height'];
279: }
280:
281:
282:
283: 284: 285: 286: 287: 288:
289: public function getPackageBaseline($value)
290: {
291: return $this->_fedexPackages[$value]['baseline'];
292: }
293:
294: 295: 296: 297: 298: 299:
300: public function getPackageLabel($value)
301: {
302: return $this->_fedexPackages[$value]['label'];
303: }
304:
305: 306: 307: 308: 309: 310:
311: public function asArray($test = null)
312: {
313: if (!isset($test)) {
314: return $this->_fedexPackages;
315: }
316:
317: else {
318: $test = explode(',', $test);
319:
320: foreach ($this->_fedexPackages as $package) {
321: if (in_array($package['label'], $test)) {
322: $packages[] = $package;
323: }
324: }
325:
326: return (isset($packages) ? $packages : false);
327: }
328: }
329:
330:
331:
332: 333: 334: 335: 336: 337:
338: public function isFedexPackage($packageCode)
339: {
340: foreach ($this->_fedexPackages as $key => $value) {
341: if ($packageCode == $key) {
342: return true;
343: }
344: }
345: return false;
346: }
347:
348:
349:
350: 351: 352: 353: 354:
355: public function getPackageCodes()
356: {
357: foreach ($this->_fedexPackages as $key => $value) {
358: $var[] = $key;
359: }
360:
361: return $var;
362: }
363:
364:
365:
366: 367: 368: 369: 370: 371:
372: public function getPackageName($value)
373: {
374: foreach ($this->_fedexPackages as $key => $value) {
375: if ($value == $key) {
376: return $value['label'];
377: }
378: }
379: }
380:
381: }
382: