Public Member Functions | |
__construct () | |
items ($filters=null) | |
info ($shipmentIncrementId) | |
create ($orderIncrementId, $itemsQty=array(), $comment=null, $email=false, $includeComment=false) | |
addTrack ($shipmentIncrementId, $carrier, $title, $trackNumber) | |
removeTrack ($shipmentIncrementId, $trackId) | |
infoTrack ($shipmentIncrementId, $trackId) | |
addComment ($shipmentIncrementId, $comment, $email=false, $includeInEmail=false) | |
getCarriers ($orderIncrementId) | |
Protected Member Functions | |
_getCarriers ($object) |
Definition at line 34 of file Api.php.
__construct | ( | ) |
Definition at line 36 of file Api.php.
00037 { 00038 $this->_attributesMap['shipment'] = array('shipment_id' => 'entity_id'); 00039 00040 $this->_attributesMap['shipment_item'] = array('item_id' => 'entity_id'); 00041 00042 $this->_attributesMap['shipment_comment'] = array('comment_id' => 'entity_id'); 00043 00044 $this->_attributesMap['shipment_track'] = array('track_id' => 'entity_id'); 00045 }
_getCarriers | ( | $ | object | ) | [protected] |
Retrieve shipping carriers for specified order
Mage_Eav_Model_Entity_Abstract | $object |
Definition at line 360 of file Api.php.
00361 { 00362 $carriers = array(); 00363 $carrierInstances = Mage::getSingleton('shipping/config')->getAllCarriers( 00364 $object->getStoreId() 00365 ); 00366 00367 $carriers['custom'] = Mage::helper('sales')->__('Custom Value'); 00368 foreach ($carrierInstances as $code => $carrier) { 00369 if ($carrier->isTrackingAvailable()) { 00370 $carriers[$code] = $carrier->getConfigData('title'); 00371 } 00372 } 00373 00374 return $carriers; 00375 }
addComment | ( | $ | shipmentIncrementId, | |
$ | comment, | |||
$ | email = false , |
|||
$ | includeInEmail = false | |||
) |
Add comment to shipment
string | $shipmentIncrementId | |
string | $comment | |
boolean | ||
boolean | $includeInEmail |
Definition at line 312 of file Api.php.
00313 { 00314 $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); 00315 00316 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00317 00318 if (!$shipment->getId()) { 00319 $this->_fault('not_exists'); 00320 } 00321 00322 00323 try { 00324 $shipment->addComment($comment, $email); 00325 $shipment->sendUpdateEmail($email, ($includeInEmail ? $comment : '')); 00326 $shipment->save(); 00327 } catch (Mage_Core_Exception $e) { 00328 $this->_fault('data_invalid', $e->getMessage()); 00329 } 00330 00331 return true; 00332 }
addTrack | ( | $ | shipmentIncrementId, | |
$ | carrier, | |||
$ | title, | |||
$ | trackNumber | |||
) |
Add tracking number to order
string | $shipmentIncrementId | |
string | $carrier | |
string | $title | |
string | $trackNumber |
Definition at line 210 of file Api.php.
00211 { 00212 $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); 00213 00214 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00215 00216 if (!$shipment->getId()) { 00217 $this->_fault('not_exists'); 00218 } 00219 00220 $carriers = $this->_getCarriers($shipment); 00221 00222 if (!isset($carriers[$carrier])) { 00223 $this->_fault('data_invalid', Mage::helper('sales')->__('Invalid carrier specified.')); 00224 } 00225 00226 $track = Mage::getModel('sales/order_shipment_track') 00227 ->setNumber($trackNumber) 00228 ->setCarrierCode($carrier) 00229 ->setTitle($title); 00230 00231 $shipment->addTrack($track); 00232 00233 try { 00234 $shipment->save(); 00235 } catch (Mage_Core_Exception $e) { 00236 $this->_fault('data_invalid', $e->getMessage()); 00237 } 00238 00239 return $track->getId(); 00240 }
create | ( | $ | orderIncrementId, | |
$ | itemsQty = array() , |
|||
$ | comment = null , |
|||
$ | email = false , |
|||
$ | includeComment = false | |||
) |
Create new shipment for order
string | $orderIncrementId | |
array | $itemsQty | |
string | $comment | |
booleam | ||
boolean | $includeComment |
Check order existing
Check shipment create availability
Reimplemented in Mage_Sales_Model_Order_Shipment_Api_V2.
Definition at line 134 of file Api.php.
00135 { 00136 $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); 00137 00138 /** 00139 * Check order existing 00140 */ 00141 if (!$order->getId()) { 00142 $this->_fault('order_not_exists'); 00143 } 00144 00145 /** 00146 * Check shipment create availability 00147 */ 00148 if (!$order->canShip()) { 00149 $this->_fault('data_invalid', Mage::helper('sales')->__('Can not do shipment for order.')); 00150 } 00151 00152 $convertor = Mage::getModel('sales/convert_order'); 00153 $shipment = $convertor->toShipment($order); 00154 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00155 00156 foreach ($order->getAllItems() as $orderItem) { 00157 if (!$orderItem->getQtyToShip()) { 00158 continue; 00159 } 00160 if ($orderItem->getIsVirtual()) { 00161 continue; 00162 } 00163 00164 if ((!isset($itemsQty[$orderItem->getId()])) && (count($itemsQty))) { 00165 continue; 00166 } 00167 00168 $item = $convertor->itemToShipmentItem($orderItem); 00169 if (isset($itemsQty[$orderItem->getId()])) { 00170 $qty = $itemsQty[$orderItem->getId()]; 00171 } 00172 else { 00173 $qty = $orderItem->getQtyToShip(); 00174 } 00175 $item->setQty($qty); 00176 $shipment->addItem($item); 00177 } 00178 $shipment->register(); 00179 $shipment->addComment($comment, $email && $includeComment); 00180 00181 if ($email) { 00182 $shipment->setEmailSent(true); 00183 } 00184 00185 $shipment->getOrder()->setIsInProcess(true); 00186 00187 try { 00188 $transactionSave = Mage::getModel('core/resource_transaction') 00189 ->addObject($shipment) 00190 ->addObject($shipment->getOrder()) 00191 ->save(); 00192 00193 $shipment->sendEmail($email, ($includeComment ? $comment : '')); 00194 } catch (Mage_Core_Exception $e) { 00195 $this->_fault('data_invalid', $e->getMessage()); 00196 } 00197 00198 return $shipment->getIncrementId(); 00199 }
getCarriers | ( | $ | orderIncrementId | ) |
Retrieve allowed shipping carriers for specified order
string | $orderIncrementId |
Check order existing
Reimplemented in Mage_Sales_Model_Order_Shipment_Api_V2.
Definition at line 340 of file Api.php.
00341 { 00342 $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); 00343 00344 /** 00345 * Check order existing 00346 */ 00347 if (!$order->getId()) { 00348 $this->_fault('order_not_exists'); 00349 } 00350 00351 return $this->_getCarriers($order); 00352 }
info | ( | $ | shipmentIncrementId | ) |
Retrieve shipment information
string | $shipmentIncrementId |
Definition at line 94 of file Api.php.
00095 { 00096 $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); 00097 00098 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00099 00100 if (!$shipment->getId()) { 00101 $this->_fault('not_exists'); 00102 } 00103 00104 $result = $this->_getAttributes($shipment, 'shipment'); 00105 00106 $result['items'] = array(); 00107 foreach ($shipment->getAllItems() as $item) { 00108 $result['items'][] = $this->_getAttributes($item, 'shipment_item'); 00109 } 00110 00111 $result['tracks'] = array(); 00112 foreach ($shipment->getAllTracks() as $track) { 00113 $result['tracks'][] = $this->_getAttributes($track, 'shipment_track'); 00114 } 00115 00116 $result['comments'] = array(); 00117 foreach ($shipment->getCommentsCollection() as $comment) { 00118 $result['comments'][] = $this->_getAttributes($comment, 'shipment_comment'); 00119 } 00120 00121 return $result; 00122 }
infoTrack | ( | $ | shipmentIncrementId, | |
$ | trackId | |||
) |
Retrieve tracking number info
string | $shipmentIncrementId | |
int | $trackId |
Definition at line 279 of file Api.php.
00280 { 00281 $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); 00282 00283 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00284 00285 if (!$shipment->getId()) { 00286 $this->_fault('not_exists'); 00287 } 00288 00289 if(!$track = $shipment->getTrackById($trackId)) { 00290 $this->_fault('track_not_exists'); 00291 } 00292 00293 /* @var $track Mage_Sales_Model_Order_Shipment_Track */ 00294 $info = $track->getNumberDetail(); 00295 00296 if (is_object($info)) { 00297 $info = $info->toArray(); 00298 } 00299 00300 return $info; 00301 }
items | ( | $ | filters = null |
) |
Retrive shipments by filters
array | $filters |
Reimplemented in Mage_Sales_Model_Order_Shipment_Api_V2.
Definition at line 53 of file Api.php.
00054 { 00055 //TODO: add full name logic 00056 $collection = Mage::getResourceModel('sales/order_shipment_collection') 00057 ->addAttributeToSelect('increment_id') 00058 ->addAttributeToSelect('created_at') 00059 ->addAttributeToSelect('total_qty') 00060 ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left') 00061 ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left') 00062 ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left') 00063 ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left'); 00064 00065 if (is_array($filters)) { 00066 try { 00067 foreach ($filters as $field => $value) { 00068 if (isset($this->_attributesMap['shipment'][$field])) { 00069 $field = $this->_attributesMap['shipment'][$field]; 00070 } 00071 00072 $collection->addFieldToFilter($field, $value); 00073 } 00074 } catch (Mage_Core_Exception $e) { 00075 $this->_fault('filters_invalid', $e->getMessage()); 00076 } 00077 } 00078 00079 $result = array(); 00080 00081 foreach ($collection as $shipment) { 00082 $result[] = $this->_getAttributes($shipment, 'shipment'); 00083 } 00084 00085 return $result; 00086 }
removeTrack | ( | $ | shipmentIncrementId, | |
$ | trackId | |||
) |
Remove tracking number
string | $shipmentIncrementId | |
int | $trackId |
Definition at line 249 of file Api.php.
00250 { 00251 $shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId); 00252 00253 /* @var $shipment Mage_Sales_Model_Order_Shipment */ 00254 00255 if (!$shipment->getId()) { 00256 $this->_fault('not_exists'); 00257 } 00258 00259 if(!$track = $shipment->getTrackById($trackId)) { 00260 $this->_fault('track_not_exists'); 00261 } 00262 00263 try { 00264 $track->delete(); 00265 } catch (Mage_Core_Exception $e) { 00266 $this->_fault('track_not_deleted', $e->getMessage()); 00267 } 00268 00269 return true; 00270 }