2

I want to get on event sales_order_invoice_save_after customer data / products to put on external billing sistem:

    public function factura(Varien_Event_Observer $observer){
    $order = $observer->getEvent()->getOrder();
    $incrementId = $order->getIncrementId();
    $custName    = $order->getCustomerFirstname();
    $orderPrice  = $order->getGrandTotal();
    $orderId     = $order->getId();
   foreach ($order->getAllItems() as $item) {
        $items[] = array(
            'id'            => $order->getIncrementId(),
            'name'          => $item->getName(),
            'sku'           => $item->getSku(),
            'Price'         => $item->getPrice(),
            'Ordered Qty'   => $item->getQtyOrdered(),


        );
    }
    $arrOrder = array(
        'id'            => $order->getIncrementId(),
        'store'         => 'magento',
        'status'        => $order->getStatus(),
        'name'          => $order->getCustomerName(),
        'email'         => $order->getCustomerEmail(),
        'telephone'     => $order->getShippingAddress()->getTelephone(),
        'street'        => $order->getShippingAddress()->getStreet(),
        'pincode'       => $order->getShippingAddress()->getPostcode(),
        'city'          => $order->getShippingAddress()->getCity(),
        'weight'        => $order->getWeight(),
        'items'        => $items,
    );

    Mage::print_a($arrOrder);
    die();
}

all i recive is:

   PHP Fatal error:  Uncaught Error: Call to a member function getIncrementId() on null in /home/anystore/app/code/community/GSMBoutique/Fgoro/Model/Observer.php:8
Stack trace:
#0 /home/anystore/app/code/core/Mage/Core/Model/App.php(1358): GSMBoutique_Fgoro_Model_Observer->factura(Object(Varien_Event_Observer))
#1 /home/anystore/app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(GSMBoutique_Fgoro_Model_Observer), 'factura', Object(Varien_Event_Observer))
#2 /home/anystore/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_inv...', Array)
#3 /home/anystore/app/code/core/Mage/Core/Model/Abstract.php(466): Mage::dispatchEvent('sales_order_inv...', Array)
#4 /home/anystore/app/code/core/Mage/Sales/Model/Order/Invoice.php(996): Mage_Core_Model_Abstract->_afterSave()
#5 /home/anystore/app/code/core/Mage/Core/Model/Abstract.php(319): Mage_Sales_Model_Order_Invoice->_afterSave()
#6 /home/anystore/app/code/core/Mage/Core/Model/Resource/Transaction.php(151): Mage_Core_Model_Abstract in /home/anystore/app/code/community/GSMBoutique/Fgoro/Model/Observer.php on line 8
  • Please check my answer and let me know if your question not solve. – Rohan Hapani Oct 19 '18 at 6:58
  • @GSM Boutique can you let me know what will be the issue you are still facing ? – Hassan Ali Shahzad Oct 19 '18 at 11:59
  • Is it working for you or not? – Rohan Hapani Oct 19 '18 at 13:06
0

Man (in M1) you are capturing invoice event and getting order from it :P

If you want to get order do the following:

$event = $observer->getEvent();
$invoice = $event->getInvoice();
$orderData = $invoice->getOrder();
$orderId = $orderData->getId();
// If you want more information for order which is not present in $orderData load order object
$order = Mage::getModel ('sales/order')->load($orderId);

Now get what you want from $order.

0

Try to use this below code :

public function execute(\Magento\Framework\Event\Observer $observer)
{
 $order = $observer->getEvent()->getOrder(); //For get order details
 $order_id = $order->getIncrementId(); //Get order id
 $product_ids = [];
 $product_name = []
 foreach($order->getAllItems() as $item) {
    $product_ids[]  = $item->getProductId(); //product id
    $product_name[] = $item->getName(); // product name
 }
 $shippingAddress = $order->getShippingAddress(); // shipping address
 $customer = $order->getCustomerId(); // For get customer id
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.