Mage_Sales_Model_Order_Invoice_Api_V2 Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Invoice_Api_V2:

Mage_Sales_Model_Order_Invoice_Api Mage_Sales_Model_Api_Resource Mage_Api_Model_Resource_Abstract

List of all members.

Public Member Functions

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

Protected Member Functions

 _prepareItemQtyData ($data)


Detailed Description

Definition at line 34 of file V2.php.


Member Function Documentation

_prepareItemQtyData ( data  )  [protected]

Definition at line 95 of file V2.php.

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

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

Create new invoice for order

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

Check order existing

Check invoice create availability

Reimplemented from Mage_Sales_Model_Order_Invoice_Api.

Definition at line 116 of file V2.php.

00117     {
00118         $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
00119         $itemsQty = $this->_prepareItemQtyData($itemsQty);
00120         /* @var $order Mage_Sales_Model_Order */
00121         /**
00122           * Check order existing
00123           */
00124         if (!$order->getId()) {
00125              $this->_fault('order_not_exists');
00126         }
00127 
00128         /**
00129          * Check invoice create availability
00130          */
00131         if (!$order->canInvoice()) {
00132              $this->_fault('data_invalid', Mage::helper('sales')->__('Can not do invoice for order.'));
00133         }
00134 
00135         $invoice = $order->prepareInvoice($itemsQty);
00136 
00137         $invoice->register();
00138 
00139         if ($comment !== null) {
00140             $invoice->addComment($comment, $email);
00141         }
00142 
00143         if ($email) {
00144             $invoice->setEmailSent(true);
00145         }
00146 
00147         $invoice->getOrder()->setIsInProcess(true);
00148 
00149         try {
00150             $transactionSave = Mage::getModel('core/resource_transaction')
00151                 ->addObject($invoice)
00152                 ->addObject($invoice->getOrder())
00153                 ->save();
00154 
00155             $invoice->sendEmail($email, ($includeComment ? $comment : ''));
00156         } catch (Mage_Core_Exception $e) {
00157             $this->_fault('data_invalid', $e->getMessage());
00158         }
00159 
00160         return $invoice->getIncrementId();
00161     }

items ( filters = null  ) 

Retrive invoices by filters

Parameters:
array $filters
Returns:
array

Reimplemented from Mage_Sales_Model_Order_Invoice_Api.

Definition at line 42 of file V2.php.

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


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

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