1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14:
15: class IllApps_Shipsync_Model_Shipping_Package_Item
16: {
17:
18:
19: 20: 21: 22: 23: 24: 25:
26: public function getParsedItems($items, $toShip = false)
27: {
28: $i = 0;
29:
30: $packageSort = Mage::getModel('shipsync/shipping_package_sort');
31:
32: if (Mage::getModel('shipsync/shipping_carrier_fedex')->getWeightUnits() == 'G') {
33: $weightCoef = 0.001;
34: }
35: else {
36: $weightCoef = 1.0;
37: }
38:
39: foreach ($items as $item) {
40:
41: if ($item->getParentItem() && !$item->isShipSeparately()) {
42: continue;
43: }
44: if ($item->getHasChildren() && $item->isShipSeparately()) {
45: continue;
46: }
47: if ($item->getIsVirtual()) {
48: continue;
49: }
50:
51: $product = Mage::getModel('catalog/product')->load($item->getProductId());
52:
53: if ($item->getIsQtyDecimal()) {
54: $itemQty = 1;
55: } elseif ($toShip) {
56: $itemQty = $item->getQtyToShip();
57: } else {
58: $itemQty = $item->getQty() > 0 ? $item->getQty() : 1;
59: }
60:
61: while ($itemQty > 0) {
62:
63: $itemWeight = round($item->getWeight() * $weightCoef, 2) > 0 ? round($item->getWeight() * $weightCoef, 2) : 0.1;
64:
65: if ($toShip) {
66:
67: $_items[$i]['status'] = $item->getStatus();
68: $_items[$i]['sku'] = $item->getSku();
69: $_items[$i]['weight'] = $itemWeight;
70: $_items[$i]['dangerous'] = $product->getDangerousGoods();
71: }
72:
73: $_items[$i]['id'] = $item->getItemId();
74: $_items[$i]['product_id'] = $item->getProductId();
75: $_items[$i]['name'] = $item->getName();
76: $_items[$i]['weight'] = $item->getIsQtyDecimal() ? $item->getQtyOrdered() * $itemWeight : $itemWeight;
77: $_items[$i]['qty'] = $item->getQtyOrdered();
78: $_items[$i]['value'] = $product->getPrice();
79: $_items[$i]['special'] = $product->getSpecialPackaging();
80: $_items[$i]['free_shipping'] = $product->getFreeShipping();
81: $_items[$i]['alt_origin'] = 0;
82: $_items[$i]['is_decimal_qty'] = $item->getIsQtyDecimal();
83:
84: if (Mage::getStoreConfig('carriers/fedex/enable_dimensions') && $product->getWidth() && $product->getHeight() && $product->getLength()) {
85: $_items[$i]['dimensions'] = true;
86:
87: if ($toShip) {
88: $itemLength = round($product->getLength(), 2) > 0 ? round($product->getLength(), 2) : 1;
89: $itemWidth = round($product->getWidth(), 2) > 0 ? round($product->getWidth(), 2) : 1;
90: $itemHeight = round($product->getHeight(), 2) > 0 ? round($product->getHeight(), 2) : 1;
91:
92: $itemVolume = round($itemLength * $itemWidth * $itemHeight);
93: } else {
94: $itemLength = $product->getLength();
95: $itemWidth = $product->getWidth();
96: $itemHeight = $product->getHeight();
97:
98: $itemVolume = $itemLength * $itemWidth * $itemHeight;
99: }
100:
101: $_items[$i]['length'] = $itemLength;
102: $_items[$i]['width'] = $itemWidth;
103: $_items[$i]['height'] = $itemHeight;
104: $_items[$i]['volume'] = $itemVolume;
105: } else {
106: $_items[$i]['dimensions'] = false;
107:
108: $_items[$i]['length'] = null;
109: $_items[$i]['width'] = null;
110: $_items[$i]['height'] = null;
111: $_items[$i]['volume'] = null;
112: }
113:
114: $itemQty--;
115:
116: $i++;
117: }
118: }
119:
120: if (!isset($_items) || !is_array($_items)) {
121: return false;
122: }
123:
124: if ($toShip) {
125: foreach ($_items as $item) {
126: $quantity_count[$item['product_id']][] = $item;
127: }
128:
129: $quantity_count = $packageSort->sortByKey('weight', $quantity_count);
130:
131: unset($_items);
132:
133: foreach ($quantity_count as $items) {
134: foreach ($items as $item) {
135: $_items[] = $item;
136: }
137: }
138: } else {
139: $_items = $packageSort->sortByKey('weight', $_items);
140: }
141:
142: return $_items;
143: }
144:
145:
146: 147: 148: 149: 150: 151: 152: 153:
154: public function byOrigin($items)
155: {
156: foreach ($items as $item) {
157: $_items[(int) $item['alt_origin']][] = $item;
158: }
159: return $_items;
160: }
161:
162: 163: 164: 165: 166: 167:
168: public function getOrigin($id)
169: {
170: $origRegionCode = Mage::getModel('directory/region')->load(Mage::getStoreConfig('shipping/origin/region_id'))->getCode();
171:
172: $origin['country'] = Mage::getStoreConfig('shipping/origin/country_id');
173: $origin['regionId'] = Mage::getStoreConfig('shipping/origin/region_id');
174: $origin['regionCode'] = (strlen($origRegionCode) > 2) ? '' : $origRegionCode;
175: $origin['postcode'] = Mage::getStoreConfig('shipping/origin/postcode');
176: $origin['city'] = Mage::getStoreConfig('shipping/origin/city');
177:
178: $shipperStreetLines = array(
179: Mage::getStoreConfig('shipping/origin/street_line1')
180: );
181: if (Mage::getStoreConfig('shipping/origin/street_line2') != '') {
182: $shipperStreetLines[] = Mage::getStoreConfig('shipping/origin/street_line2');
183: }
184: if (Mage::getStoreConfig('shipping/origin/street_line3') != '') {
185: $shipperStreetLines[] = Mage::getStoreConfig('shipping/origin/street_line3');
186: }
187: $origin['street'] = $shipperStreetLines;
188:
189: return $origin;
190: }
191: }
192: