Public Member Functions | |
items ($filters=null) | |
create ($orderIncrementId, $itemsQty=array(), $comment=null, $email=false, $includeComment=false) | |
getCarriers ($orderIncrementId) | |
Protected Member Functions | |
_prepareItemQtyData ($data) |
Definition at line 34 of file V2.php.
_prepareItemQtyData | ( | $ | data | ) | [protected] |
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 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
string | $orderIncrementId |
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
array | $filters |
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 }