Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <sales_order_invoice_save_before>
- <observers>
- <training_orderIntegrationClient>
- <type>singleton</type>
- <class>training_orderIntegrationClient/observer</class>
- <method>salesOrderInvoiceSaveBefore</method>
- </training_orderIntegrationClient>
- </observers>
- </sales_order_invoice_save_before>
- <sales_order_invoice_save_commit_after>
- <observers>
- <training_orderIntegrationClient>
- <type>singleton</type>
- <class>training_orderIntegrationClient/observer</class>
- <method>salesOrderInvoiceSaveCommitAfter</method>
- </training_orderIntegrationClient>
- </observers>
- </sales_order_invoice_save_commit_after>
- ---------------------------- Observer.php -------------------------------------------------------
- public function salesOrderInvoiceSaveBefore(Varien_Event_Observer $args)
- {
- /** @var Mage_Sales_Model_Order_Invoice $invoice */
- $invoice = $args->getInvoice();
- if ($invoice->isObjectNew()) {
- $order = $invoice->getOrder();
- if (! $this->_getClient()->canInvoice($order)) {
- Mage::throwException("Synchronization Error: invoice capability not available for order {$order->getId()}");
- }
- }
- }
- public function salesOrderInvoiceSaveCommitAfter(Varien_Event_Observer $args)
- {
- /** @var Mage_Sales_Model_Order_Invoice $invoice */
- $invoice = $args->getInvoice();
- $order = $invoice->getOrder();
- if ($invoice->isObjectNew()) {
- if (! $this->_getClient()->invoice($order)) {
- Mage::throwException("Synchronization Error: unable to synchronize invoice for order {$order->getId()}");
- }
- } else {
- $this->_getClient()->push($order);
- }
- }
- ------------------------------------------------ Client.php -----------------------------------------------
- public function canInvoice(Mage_Sales_Model_Order $order)
- {
- if (! $order->getId()) {
- Mage::throwException("Unable to check capability for unsaved order model\n");
- }
- return '1' === $this->_send("availability {$order->getId()} invoice");
- }
- public function invoice(Mage_Sales_Model_Order $order)
- {
- if (! $order->getId()) {
- Mage::throwException("Unable to invoice unsaved order model\n");
- }
- $this->_send("sync off");
- //$result = '1' === $this->_send("invoice {$order->getId()}");
- $result = '1' === $this->_send("pull {$order->getId()}");
- $this->_send("sync on");
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement