Advertisement
Guest User

step 2

a guest
Apr 16th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1.           <sales_order_invoice_save_before>
  2.             <observers>
  3.               <training_orderIntegrationClient>
  4.                 <type>singleton</type>
  5.                 <class>training_orderIntegrationClient/observer</class>
  6.                 <method>salesOrderInvoiceSaveBefore</method>
  7.               </training_orderIntegrationClient>
  8.             </observers>
  9.           </sales_order_invoice_save_before>
  10.           <sales_order_invoice_save_commit_after>
  11.             <observers>
  12.               <training_orderIntegrationClient>
  13.                 <type>singleton</type>
  14.                 <class>training_orderIntegrationClient/observer</class>
  15.                 <method>salesOrderInvoiceSaveCommitAfter</method>
  16.               </training_orderIntegrationClient>
  17.             </observers>
  18.           </sales_order_invoice_save_commit_after>
  19.  
  20. ---------------------------- Observer.php -------------------------------------------------------
  21.  
  22.     public function salesOrderInvoiceSaveBefore(Varien_Event_Observer $args)
  23.     {
  24.         /** @var Mage_Sales_Model_Order_Invoice $invoice */
  25.         $invoice = $args->getInvoice();
  26.         if ($invoice->isObjectNew()) {
  27.             $order = $invoice->getOrder();     
  28.             if (! $this->_getClient()->canInvoice($order)) {
  29.                  Mage::throwException("Synchronization Error: invoice capability not available for order {$order->getId()}");
  30.             }
  31.         }      
  32.     }
  33.  
  34.     public function salesOrderInvoiceSaveCommitAfter(Varien_Event_Observer $args)
  35.     {
  36.         /** @var Mage_Sales_Model_Order_Invoice $invoice */
  37.         $invoice = $args->getInvoice();
  38.         $order = $invoice->getOrder();
  39.         if ($invoice->isObjectNew()) {
  40.             if (! $this->_getClient()->invoice($order)) {
  41.                 Mage::throwException("Synchronization Error: unable to synchronize invoice for order {$order->getId()}");
  42.             }
  43.         } else {
  44.             $this->_getClient()->push($order);
  45.         }
  46.     }  
  47.  
  48. ------------------------------------------------ Client.php -----------------------------------------------
  49.    
  50.     public function canInvoice(Mage_Sales_Model_Order $order)
  51.     {
  52.         if (! $order->getId()) {
  53.             Mage::throwException("Unable to check capability for unsaved order model\n");
  54.         }
  55.         return '1' === $this->_send("availability {$order->getId()} invoice");
  56.     }
  57.  
  58.     public function invoice(Mage_Sales_Model_Order $order)
  59.     {
  60.         if (! $order->getId()) {
  61.             Mage::throwException("Unable to invoice unsaved order model\n");
  62.         }
  63.         $this->_send("sync off");
  64.         //$result = '1' === $this->_send("invoice {$order->getId()}");
  65.         $result = '1' === $this->_send("pull {$order->getId()}");
  66.         $this->_send("sync on");
  67.         return $result;
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement