Mage_Sales_Model_Order_Shipment_Api_V2 Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Shipment_Api_V2:

Mage_Sales_Model_Order_Shipment_Api Mage_Sales_Model_Api_Resource Mage_Api_Model_Resource_Abstract

List of all members.

Public Member Functions

 items ($filters=null)
 create ($orderIncrementId, $itemsQty=array(), $comment=null, $email=false, $includeComment=false)
 getCarriers ($orderIncrementId)

Protected Member Functions

 _prepareItemQtyData ($data)


Detailed Description

Definition at line 34 of file V2.php.


Member Function Documentation

_prepareItemQtyData ( data  )  [protected]

Definition at line 92 of file V2.php.

00093     {
00094         $_data = array();
00095         foreach ($data as $item) {
00096             if (isset($item->order_item_id) && isset($item->qty)) {
00097                 $_data[$item->order_item_id] = $item->qty;
00098             }
00099         }
00100         return $_data;
00101     }

create ( orderIncrementId,
itemsQty = array(),
comment = null,
email = false,
includeComment = false 
)

Create new shipment for order

Parameters:
string $orderIncrementId
array $itemsQty
string $comment
booleam $email
boolean $includeComment
Returns:
string

Check order existing

Check shipment create availability

Reimplemented from Mage_Sales_Model_Order_Shipment_Api.

Definition at line 113 of file V2.php.

00114     {
00115         $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
00116         $itemsQty = $this->_prepareItemQtyData($itemsQty);
00117         /**
00118           * Check order existing
00119           */
00120         if (!$order->getId()) {
00121              $this->_fault('order_not_exists');
00122         }
00123 
00124         /**
00125          * Check shipment create availability
00126          */
00127         if (!$order->canShip()) {
00128              $this->_fault('data_invalid', Mage::helper('sales')->__('Can not do shipment for order.'));
00129         }
00130 
00131         $convertor   = Mage::getModel('sales/convert_order');
00132         $shipment    = $convertor->toShipment($order);
00133          /* @var $shipment Mage_Sales_Model_Order_Shipment */
00134 
00135         foreach ($order->getAllItems() as $orderItem) {
00136             if (!$orderItem->getQtyToShip()) {
00137                 continue;
00138             }
00139             if ($orderItem->getIsVirtual()) {
00140                 continue;
00141             }
00142             $item = $convertor->itemToShipmentItem($orderItem);
00143             if (isset($itemsQty[$orderItem->getId()])) {
00144                 $qty = $itemsQty[$orderItem->getId()];
00145             }
00146             else {
00147                 $qty = $orderItem->getQtyToShip();
00148             }
00149             $item->setQty($qty);
00150             $shipment->addItem($item);
00151         }
00152         $shipment->register();
00153         $shipment->addComment($comment, $email && $includeComment);
00154 
00155         if ($email) {
00156             $shipment->setEmailSent(true);
00157         }
00158 
00159         $shipment->getOrder()->setIsInProcess(true);
00160 
00161         try {
00162             $transactionSave = Mage::getModel('core/resource_transaction')
00163                 ->addObject($shipment)
00164                 ->addObject($shipment->getOrder())
00165                 ->save();
00166 
00167             $shipment->sendEmail($email, ($includeComment ? $comment : ''));
00168         } catch (Mage_Core_Exception $e) {
00169             $this->_fault('data_invalid', $e->getMessage());
00170         }
00171 
00172         return $shipment->getIncrementId();
00173     }

getCarriers ( orderIncrementId  ) 

Retrieve allowed shipping carriers for specified order

Parameters:
string $orderIncrementId
Returns:
array

Check order existing

Reimplemented from Mage_Sales_Model_Order_Shipment_Api.

Definition at line 181 of file V2.php.

00182     {
00183         $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
00184 
00185         /**
00186           * Check order existing
00187           */
00188         if (!$order->getId()) {
00189             $this->_fault('order_not_exists');
00190         }
00191         $carriers = array();
00192         foreach ($this->_getCarriers($order) as $key => $value) {
00193             $carriers[] = array('key' => $key, 'value' => $value);
00194         }
00195 
00196         return $carriers;
00197     }

items ( filters = null  ) 

Retrive shipments by filters

Parameters:
array $filters
Returns:
array

Reimplemented from Mage_Sales_Model_Order_Shipment_Api.

Definition at line 42 of file V2.php.

00043     {
00044         //TODO: add full name logic
00045         $collection = Mage::getResourceModel('sales/order_shipment_collection')
00046             ->addAttributeToSelect('increment_id')
00047             ->addAttributeToSelect('created_at')
00048             ->addAttributeToSelect('total_qty')
00049             ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
00050             ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
00051             ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left')
00052             ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left');
00053 
00054         $preparedFilters = array();
00055         if (isset($filters->filter)) {
00056             foreach ($filters->filter as $_filter) {
00057                 $preparedFilters[$_filter->key] = $_filter->value;
00058             }
00059         }
00060         if (isset($filters->complex_filter)) {
00061             foreach ($filters->complex_filter as $_filter) {
00062                 $_value = $_filter->value;
00063                 $preparedFilters[$_filter->key] = array(
00064                     $_value->key => $_value->value
00065                 );
00066             }
00067         }
00068 
00069         if (!empty($preparedFilters)) {
00070             try {
00071                 foreach ($preparedFilters as $field => $value) {
00072                     if (isset($this->_attributesMap['shipment'][$field])) {
00073                         $field = $this->_attributesMap['shipment'][$field];
00074                     }
00075 
00076                     $collection->addFieldToFilter($field, $value);
00077                 }
00078             } catch (Mage_Core_Exception $e) {
00079                 $this->_fault('filters_invalid', $e->getMessage());
00080             }
00081         }
00082 
00083         $result = array();
00084 
00085         foreach ($collection as $shipment) {
00086             $result[] = $this->_getAttributes($shipment, 'shipment');
00087         }
00088 
00089         return $result;
00090     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:48 2009 for Magento by  doxygen 1.5.8