Overview

Packages

  • IllApps
    • Shipsync
  • PHP

Classes

  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Abstract
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Form
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Items
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Package
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_View
  • IllApps_Shipsync_Block_Adminhtml_Shipsync
  • IllApps_Shipsync_Block_Adminhtml_Shipsync_Option
  • IllApps_Shipsync_Helper_Data
  • IllApps_Shipsync_IndexController
  • IllApps_Shipsync_Model_Mysql4_Setup
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package_Collection
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package_Item
  • IllApps_Shipsync_Model_Sales_Quote_Address
  • IllApps_Shipsync_Model_Shipment_Abstract
  • IllApps_Shipsync_Model_Shipment_Package
  • IllApps_Shipsync_Model_Shipment_Request
  • IllApps_Shipsync_Model_Shipment_Response
  • IllApps_Shipsync_Model_Shipment_Result
  • IllApps_Shipsync_Model_Shipping_Carrier_Abstract
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Address
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Package
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Ship
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_B13afilingoption
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Freemethod
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Image
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Orientation
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Stock
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Method
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Packaging
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Ratediscount
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Residencedelivery
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Signature
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Endorsement
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Indicia
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Unitofmeasure
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Track
  • IllApps_Shipsync_Model_Shipping_Package
  • IllApps_Shipsync_Model_Shipping_Package_Item
  • IllApps_Shipsync_Model_Shipping_Package_Origins
  • IllApps_Shipsync_Model_Shipping_Package_Sort
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * ShipSync
  5:  *
  6:  * @category   IllApps
  7:  * @package    IllApps_Shipsync
  8:  * @copyright  Copyright (c) 2014 EcoMATICS, Inc. DBA IllApps (http://www.illapps.com)
  9:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 10:  */
 11: 
 12: /**
 13:  * IllApps_Shipsync_Model_Shipping_Package_Item
 14:  */
 15: class IllApps_Shipsync_Model_Shipping_Package_Item
 16: {
 17:     
 18:     
 19:     /**
 20:      * getParsedItems
 21:      *
 22:      * @param object $items
 23:      * @param bool $toShip
 24:      * @return array $_items
 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; //(int) $product->getProductOrigin();
 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:      * By Origin
148:      * 
149:      * Sorts items by origin
150:      * 
151:      * @param array $items
152:      * @return array $items
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:      * Get Origin
164:      * 
165:      * @param int $id
166:      * @return array $origin
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: 
shipsync-community API documentation generated by ApiGen 2.8.0