Mage_Sales_Model_Order_Api Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Api:

Mage_Sales_Model_Api_Resource Mage_Api_Model_Resource_Abstract Mage_Sales_Model_Order_Api_V2

List of all members.

Public Member Functions

 __construct ()
 items ($filters=null)
 info ($orderIncrementId)
 addComment ($orderIncrementId, $status, $comment=null, $notify=false)
 hold ($orderIncrementId)
 unhold ($orderIncrementId)
 cancel ($orderIncrementId)

Protected Member Functions

 _initOrder ($orderIncrementId)


Detailed Description

Definition at line 34 of file Api.php.


Constructor & Destructor Documentation

__construct (  ) 

Definition at line 36 of file Api.php.

00037     {
00038         $this->_attributesMap['order']         = array('order_id' => 'entity_id');
00039         $this->_attributesMap['order_address'] = array('address_id' => 'entity_id');
00040         $this->_attributesMap['order_payment'] = array('payment_id' => 'entity_id');
00041 
00042     }


Member Function Documentation

_initOrder ( orderIncrementId  )  [protected]

Initialize basic order model

Parameters:
mixed $orderIncrementId
Returns:
Mage_Sales_Model_Order

Definition at line 50 of file Api.php.

00051     {
00052         $order = Mage::getModel('sales/order');
00053 
00054         /* @var $order Mage_Sales_Model_Order */
00055 
00056         $order->loadByIncrementId($orderIncrementId);
00057 
00058         if (!$order->getId()) {
00059             $this->_fault('not_exists');
00060         }
00061 
00062         return $order;
00063     }

addComment ( orderIncrementId,
status,
comment = null,
notify = false 
)

Add comment to order

Parameters:
string $orderIncrementId
string $status
string $comment
boolean $notify
Returns:
boolean

Definition at line 151 of file Api.php.

00152     {
00153         $order = $this->_initOrder($orderIncrementId);
00154 
00155         $order->addStatusToHistory($status, $comment, $notify);
00156 
00157 
00158         try {
00159             if ($notify && $comment) {
00160                 $oldStore = Mage::getDesign()->getStore();
00161                 $oldArea = Mage::getDesign()->getArea();
00162                 Mage::getDesign()->setStore($order->getStoreId());
00163                 Mage::getDesign()->setArea('frontend');
00164             }
00165 
00166             $order->sendOrderUpdateEmail($notify, $comment);
00167             $order->save();
00168             if ($notify && $comment) {
00169                 Mage::getDesign()->setStore($oldStore);
00170                 Mage::getDesign()->setArea($oldArea);
00171             }
00172 
00173         } catch (Mage_Core_Exception $e) {
00174             $this->_fault('status_not_changed', $e->getMessage());
00175         }
00176 
00177         return true;
00178     }

cancel ( orderIncrementId  ) 

Cancel order

Parameters:
string $orderIncrementId
Returns:
boolean

Definition at line 226 of file Api.php.

00227     {
00228         $order = $this->_initOrder($orderIncrementId);
00229 
00230         try {
00231             $order->cancel();
00232             $order->save();
00233         } catch (Mage_Core_Exception $e) {
00234             $this->_fault('status_not_changed', $e->getMessage());
00235         }
00236 
00237         return true;
00238     }

hold ( orderIncrementId  ) 

Hold order

Parameters:
string $orderIncrementId
Returns:
boolean

Definition at line 186 of file Api.php.

00187     {
00188         $order = $this->_initOrder($orderIncrementId);
00189 
00190         try {
00191             $order->hold();
00192             $order->save();
00193         } catch (Mage_Core_Exception $e) {
00194             $this->_fault('status_not_changed', $e->getMessage());
00195         }
00196 
00197         return true;
00198     }

info ( orderIncrementId  ) 

Retrieve full order information

Parameters:
string $orderIncrementId
Returns:
array

Definition at line 117 of file Api.php.

00118     {
00119         $order = $this->_initOrder($orderIncrementId);
00120 
00121         $result = $this->_getAttributes($order, 'order');
00122 
00123         $result['shipping_address'] = $this->_getAttributes($order->getShippingAddress(), 'order_address');
00124         $result['billing_address']  = $this->_getAttributes($order->getBillingAddress(), 'order_address');
00125         $result['items'] = array();
00126 
00127         foreach ($order->getAllItems() as $item) {
00128             $result['items'][] = $this->_getAttributes($item, 'order_item');
00129         }
00130 
00131         $result['payment'] = $this->_getAttributes($order->getPayment(), 'order_payment');
00132 
00133         $result['status_history'] = array();
00134 
00135         foreach ($order->getAllStatusHistory() as $history) {
00136             $result['status_history'][] = $this->_getAttributes($history, 'order_status_history');
00137         }
00138 
00139         return $result;
00140     }

items ( filters = null  ) 

Retrieve list of orders by filters

Parameters:
array $filters
Returns:
array

Reimplemented in Mage_Sales_Model_Order_Api_V2.

Definition at line 71 of file Api.php.

00072     {
00073         //TODO: add full name logic
00074         $collection = Mage::getResourceModel('sales/order_collection')
00075             ->addAttributeToSelect('*')
00076             ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
00077             ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
00078             ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
00079             ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
00080             ->addExpressionAttributeToSelect('billing_name',
00081                 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
00082                 array('billing_firstname', 'billing_lastname'))
00083             ->addExpressionAttributeToSelect('shipping_name',
00084                 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
00085                 array('shipping_firstname', 'shipping_lastname'));
00086 
00087 
00088         if (is_array($filters)) {
00089             try {
00090                 foreach ($filters as $field => $value) {
00091                     if (isset($this->_attributesMap['order'][$field])) {
00092                         $field = $this->_attributesMap['order'][$field];
00093                     }
00094 
00095                     $collection->addFieldToFilter($field, $value);
00096                 }
00097             } catch (Mage_Core_Exception $e) {
00098                 $this->_fault('filters_invalid', $e->getMessage());
00099             }
00100         }
00101 
00102         $result = array();
00103 
00104         foreach ($collection as $order) {
00105             $result[] = $this->_getAttributes($order, 'order');
00106         }
00107 
00108         return $result;
00109     }

unhold ( orderIncrementId  ) 

Unhold order

Parameters:
string $orderIncrementId
Returns:
boolean

Definition at line 206 of file Api.php.

00207     {
00208         $order = $this->_initOrder($orderIncrementId);
00209 
00210         try {
00211             $order->unhold();
00212             $order->save();
00213         } catch (Mage_Core_Exception $e) {
00214             $this->_fault('status_not_changed', $e->getMessage());
00215         }
00216 
00217         return true;
00218     }


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

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