Public Member Functions | |
__construct () | |
items ($filters=null) | |
info ($invoiceIncrementId) | |
create ($orderIncrementId, $itemsQty, $comment=null, $email=false, $includeComment=false) | |
addComment ($invoiceIncrementId, $comment, $email=false, $includeComment=false) | |
capture ($invoiceIncrementId) | |
void ($invoiceIncrementId) | |
cancel ($invoiceIncrementId) |
Definition at line 34 of file Api.php.
__construct | ( | ) |
Definition at line 36 of file Api.php.
00037 { 00038 $this->_attributesMap['invoice'] = array( 00039 'invoice_id' => 'entity_id' 00040 ); 00041 00042 $this->_attributesMap['invoice_item'] = array( 00043 'item_id' => 'entity_id' 00044 ); 00045 00046 $this->_attributesMap['invoice_comment'] = array( 00047 'comment_id' => 'entity_id' 00048 ); 00049 }
addComment | ( | $ | invoiceIncrementId, | |
$ | comment, | |||
$ | email = false , |
|||
$ | includeComment = false | |||
) |
Add comment to invoice
string | $invoiceIncrementId | |
string | $comment | |
boolean | ||
boolean | $includeComment |
Definition at line 192 of file Api.php.
00193 { 00194 $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId); 00195 00196 /* @var $invoice Mage_Sales_Model_Order_Invoice */ 00197 00198 if (!$invoice->getId()) { 00199 $this->_fault('not_exists'); 00200 } 00201 00202 00203 try { 00204 $invoice->addComment($comment, $email); 00205 $invoice->sendUpdateEmail($email, ($includeInEmail ? $comment : '')); 00206 $invoice->save(); 00207 } catch (Mage_Core_Exception $e) { 00208 $this->_fault('data_invalid', $e->getMessage()); 00209 } 00210 00211 return true; 00212 }
cancel | ( | $ | invoiceIncrementId | ) |
Cancel invoice
string | $invoiceIncrementId |
Definition at line 292 of file Api.php.
00293 { 00294 $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId); 00295 00296 /* @var $invoice Mage_Sales_Model_Order_Invoice */ 00297 00298 if (!$invoice->getId()) { 00299 $this->_fault('not_exists'); 00300 } 00301 00302 if (!$invoice->canCancel()) { 00303 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice can not be canceled')); 00304 } 00305 00306 try { 00307 $invoice->cancel(); 00308 $invoice->getOrder()->setIsInProcess(true); 00309 $transactionSave = Mage::getModel('core/resource_transaction') 00310 ->addObject($invoice) 00311 ->addObject($invoice->getOrder()) 00312 ->save(); 00313 } catch (Mage_Core_Exception $e) { 00314 $this->_fault('status_not_changed', $e->getMessage()); 00315 } catch (Exception $e) { 00316 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice cancel problem')); 00317 } 00318 00319 return true; 00320 }
capture | ( | $ | invoiceIncrementId | ) |
Capture invoice
string | $invoiceIncrementId |
Definition at line 220 of file Api.php.
00221 { 00222 $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId); 00223 00224 /* @var $invoice Mage_Sales_Model_Order_Invoice */ 00225 00226 if (!$invoice->getId()) { 00227 $this->_fault('not_exists'); 00228 } 00229 00230 if (!$invoice->canCapture()) { 00231 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice can not be captured')); 00232 } 00233 00234 try { 00235 $invoice->capture(); 00236 $invoice->getOrder()->setIsInProcess(true); 00237 $transactionSave = Mage::getModel('core/resource_transaction') 00238 ->addObject($invoice) 00239 ->addObject($invoice->getOrder()) 00240 ->save(); 00241 } catch (Mage_Core_Exception $e) { 00242 $this->_fault('status_not_changed', $e->getMessage()); 00243 } catch (Exception $e) { 00244 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice capture problem')); 00245 } 00246 00247 return true; 00248 }
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 in Mage_Sales_Model_Order_Invoice_Api_V2.
Definition at line 136 of file Api.php.
00137 { 00138 $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId); 00139 00140 /* @var $order Mage_Sales_Model_Order */ 00141 /** 00142 * Check order existing 00143 */ 00144 if (!$order->getId()) { 00145 $this->_fault('order_not_exists'); 00146 } 00147 00148 /** 00149 * Check invoice create availability 00150 */ 00151 if (!$order->canInvoice()) { 00152 $this->_fault('data_invalid', Mage::helper('sales')->__('Can not do invoice for order.')); 00153 } 00154 00155 $invoice = $order->prepareInvoice($itemsQty); 00156 00157 $invoice->register(); 00158 00159 if ($comment !== null) { 00160 $invoice->addComment($comment, $email); 00161 } 00162 00163 if ($email) { 00164 $invoice->setEmailSent(true); 00165 } 00166 00167 $invoice->getOrder()->setIsInProcess(true); 00168 00169 try { 00170 $transactionSave = Mage::getModel('core/resource_transaction') 00171 ->addObject($invoice) 00172 ->addObject($invoice->getOrder()) 00173 ->save(); 00174 00175 $invoice->sendEmail($email, ($includeComment ? $comment : '')); 00176 } catch (Mage_Core_Exception $e) { 00177 $this->_fault('data_invalid', $e->getMessage()); 00178 } 00179 00180 return $invoice->getIncrementId(); 00181 }
info | ( | $ | invoiceIncrementId | ) |
Retrieve invoice information
string | $invoiceIncrementId |
Definition at line 101 of file Api.php.
00102 { 00103 $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId); 00104 00105 /* @var $invoice Mage_Sales_Model_Order_Invoice */ 00106 00107 if (!$invoice->getId()) { 00108 $this->_fault('not_exists'); 00109 } 00110 00111 $result = $this->_getAttributes($invoice, 'invoice'); 00112 00113 $result['items'] = array(); 00114 foreach ($invoice->getAllItems() as $item) { 00115 $result['items'][] = $this->_getAttributes($item, 'invoice_item'); 00116 } 00117 00118 $result['comments'] = array(); 00119 foreach ($invoice->getCommentsCollection() as $comment) { 00120 $result['comments'][] = $this->_getAttributes($comment, 'invoice_comment'); 00121 } 00122 00123 return $result; 00124 }
items | ( | $ | filters = null |
) |
Retrive invoices by filters
array | $filters |
Reimplemented in Mage_Sales_Model_Order_Invoice_Api_V2.
Definition at line 57 of file Api.php.
00058 { 00059 //TODO: add full name logic 00060 $collection = Mage::getResourceModel('sales/order_invoice_collection') 00061 ->addAttributeToSelect('order_id') 00062 ->addAttributeToSelect('increment_id') 00063 ->addAttributeToSelect('created_at') 00064 ->addAttributeToSelect('state') 00065 ->addAttributeToSelect('grand_total') 00066 ->addAttributeToSelect('order_currency_code') 00067 ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left') 00068 ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left') 00069 ->joinAttribute('order_increment_id', 'order/increment_id', 'order_id', null, 'left') 00070 ->joinAttribute('order_created_at', 'order/created_at', 'order_id', null, 'left'); 00071 00072 if (is_array($filters)) { 00073 try { 00074 foreach ($filters 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 }
void | ( | $ | invoiceIncrementId | ) |
Void invoice
unknown_type | $invoiceIncrementId |
Definition at line 256 of file Api.php.
00257 { 00258 $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceIncrementId); 00259 00260 /* @var $invoice Mage_Sales_Model_Order_Invoice */ 00261 00262 if (!$invoice->getId()) { 00263 $this->_fault('not_exists'); 00264 } 00265 00266 if (!$invoice->canVoid()) { 00267 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice can not be void')); 00268 } 00269 00270 try { 00271 $invoice->void(); 00272 $invoice->getOrder()->setIsInProcess(true); 00273 $transactionSave = Mage::getModel('core/resource_transaction') 00274 ->addObject($invoice) 00275 ->addObject($invoice->getOrder()) 00276 ->save(); 00277 } catch (Mage_Core_Exception $e) { 00278 $this->_fault('status_not_changed', $e->getMessage()); 00279 } catch (Exception $e) { 00280 $this->_fault('status_not_changed', Mage::helper('sales')->__('Invoice void problem')); 00281 } 00282 00283 return true; 00284 }