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_Sort
 14:  */
 15: class IllApps_Shipsync_Model_Shipping_Package_Sort
 16: {
 17:     
 18:     protected $_key;
 19:     
 20:     
 21:     /**
 22:      * sortByKey
 23:      *
 24:      * @param array $items
 25:      * @return array
 26:      */
 27:     public function sortByKey($key, $array)
 28:     {
 29:         $this->_key = $key;
 30:         
 31:         uasort($array, array(
 32:             $this,
 33:             '_sortByKey'
 34:         ));
 35:         
 36:         return $array;
 37:     }
 38:     
 39:     
 40:     
 41:     
 42:     
 43:     /**
 44:      * _sortByKey
 45:      *
 46:      * @param array $a
 47:      * @param array $b
 48:      * @return array
 49:      */
 50:     protected function _sortByKey($a, $b)
 51:     {
 52:         $key = $this->_key;
 53:         
 54:         $a_key = (is_array($a) && isset($a[$key])) ? $a[$key] : 0;
 55:         $b_key = (is_array($b) && isset($b[$key])) ? $b[$key] : 0;
 56:         
 57:         if ($a_key == $b_key) {
 58:             return 0;
 59:         }
 60:         
 61:         return ($a_key > $b_key) ? -1 : 1;
 62:     }
 63:     
 64:     
 65:     
 66:     /**
 67:      * Find Best Fit
 68:      *
 69:      * Finds package in which item fits with least amount of remaining space
 70:      *
 71:      * @param array $packages
 72:      * @param array $item
 73:      *
 74:      * @return index
 75:      */
 76:     public function findBestFit($packages, $item)
 77:     {
 78:         foreach ($packages as $key => $package) {
 79:             if ($this->findFit($package, $item)) {
 80:                 $free_weights[$key] = $package['free_weight'];
 81:                 $free_volumes[$key] = $package['free_volume'];
 82:             }
 83:         }
 84:         
 85:         return (isset($free_weights) && isset($free_volumes) ? $this->minKey($free_weights, $free_volumes) : null);
 86:     }
 87:     
 88:     
 89:     
 90:     /**
 91:      * Min Key
 92:      *
 93:      * Compares two arrays, and returns the key where boths arrays have a minimum value, otherwise returns null
 94:      *
 95:      * @param array $array
 96:      * @param array $cmpArray
 97:      *
 98:      * @return index
 99:      */
100:     public function minKey($array, $cmpArray)
101:     {
102:         foreach ($array as $key => $val) {
103:             if ($val == min($array) && $cmpArray[$key] == min($cmpArray)) {
104:                 return $key;
105:             } else {
106:                 return null;
107:             }
108:         }
109:     }
110:     
111:     
112:     
113:     /**
114:      * Find Fit
115:      *
116:      * Finds if item fits in package, handles items with dimension and without
117:      *
118:      * @param array $package
119:      * @param array $item
120:      *
121:      * @return bool
122:      */
123:     public function findFit($package, $item)
124:     {
125:         if ($item['dimensions']) {
126:             if (($this->findFitWeight($package, $item)) && ($this->findFitVolume($package, $item)) && ($this->itemFits($package, $item))) {
127:                 return true;
128:             }
129:             return false;
130:         } else {
131:             return $this->findFitWeight($package, $item);
132:         }
133:     }
134:     
135:     
136:     
137:     /**
138:      * Find Fit Volume
139:      *
140:      * Determines if item with dimension fits in package
141:      *
142:      * @param array $item
143:      * @param array $package
144:      * @return bool
145:      */
146:     public function findFitVolume($package, $item)
147:     {
148:         if ($item['volume'] <= $package['free_volume']) {
149:             return true;
150:         } else {
151:             return false;
152:         }
153:     }
154:     
155:     
156:     
157:     /**
158:      * Find Fit Weight
159:      *
160:      * Determines if item with weight fits in package
161:      *
162:      * @param array $item
163:      * @param array $package
164:      * @return bool
165:      */
166:     public function findFitWeight($package, $item)
167:     {
168:         if ($item['weight'] <= $package['free_weight']) {
169:             return true;
170:         } else {
171:             return false;
172:         }
173:     }
174:     
175:     /**
176:      * Item Fits
177:      * 
178:      * Test if item fits in the package if it were empty.
179:      * Simply tests the length of each side to see if some element is too long.
180:      * 
181:      * @param array $package
182:      * @param array $item
183:      * @return bool 
184:      * 
185:      */
186:     public function itemFits($package, $item)
187:     {
188:         $arr = array(
189:             $package['length'],
190:             $package['width'],
191:             $package['height']
192:         );
193:         $cmp = array(
194:             $item['length'],
195:             $item['width'],
196:             $item['height']
197:         );
198:         
199:         sort($arr);
200:         sort($cmp);
201:         
202:         return $this->dimensionCheck($arr, $cmp);
203:     }
204:     
205:     public function getPackageLongestSide($package)
206:     {
207:         $arr = array(
208:             $package['length'],
209:             $package['width'],
210:             $package['height']
211:         );
212:         sort($arr);
213:         return $arr;
214:     }
215:     
216:     public function getItemLongestSide($items)
217:     {
218:         foreach ($items as $item) {
219:             $longest_l[] = ($item['dimensions']) ? $item['length'] : 0;
220:             $longest_w[] = ($item['dimensions']) ? $item['width'] : 0;
221:             $longest_h[] = ($item['dimensions']) ? $item['height'] : 0;
222:         }
223:         $arr = array(
224:             max($longest_l),
225:             max($longest_w),
226:             max($longest_h)
227:         );
228:         sort($arr);
229:         return $arr;
230:     }
231:     
232:     public function dimensionCheck($arr, $cmp)
233:     {
234:         foreach ($arr as $key => $el) {
235:             if ($cmp[$key] > $el) {
236:                 return false;
237:             }
238:         }
239:         return true;
240:     }
241: }
242: 
shipsync-community API documentation generated by ApiGen 2.8.0