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