1

I'm trying to get the subtotal and Grandtotal from an order but the result is always NULL.

I have try a lot of solutions that i found online but nothing works.. The event that i wait is: sales_order_place_after

This is the code:

    class MyCompany_MyObserver_Model_Observer {
public function send_email($observer) {

    $customer = Mage::getSingleton('customer/session')->getCustomer();
    //Get name and email of customer
    $email = $customer->getEmail();
    $fullname = $customer->getName();
    //Get the customer group and check that if Trade customer group a email gets sent
    $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

All the code so far works as it should.I can take the name and the email and the groupID The code below keeps break no matter what! //I have tried all the solutions i could find.I'm trying with var_dump to see the value..

$session= Mage::getSingleton('checkout/session');
    //Get totals
    $number =  Mage::getModel('checkout/cart')->getQuote()->getTotals();
    $subtotal = number_format($number,2);
    $discount = $totals['discount']->getValue();
    $shippingtotal = $totals['shipping']->getValue();
    var_dump($grandtotal);
    //die();

    $grand_total = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();

    $shippingMethod = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();

    $paymentMethod = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getTitle();

    //Get billing and shipping address

    $billingaddress = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress();

    $billingStreet = $billingaddress->getData('street');
    $billingPostcode = $billingaddress->getData("postcode");
    $billingCity = $billingaddress->getData("city");
    $billingRegion = $billingaddress->getRegionCode();
    $billingCountry = $billingaddress->getCountryModel()->getName();

    $shippingAddress = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();

    $shippingName = $shippingAddress->getName();
    $shippingCompany = $shippingAddress->getData("company");
    $shippingStreet = $shippingAddress->getData("street");
    $shippingPostcode = $shippingAddress->getData("postcode");
    $shippingCity = $shippingAddress->getData("city");
    $shippingRegion = $shippingAddress->getRegion();
    $shippingCountry = $shippingAddress->getCountryModel()->getName();

My config file looks something like this: Am i catching the right event? The only things i can get are: Order Id Customer Name and Email.

<events>
  <checkout_onepage_controller_success_action>
    <observers>
      <sales_order_place_after>
        <type>singleton</type>
        <class>MyCompany_MyObserver_Model_Observer</class>
        <method>send_email</method>
      </sales_order_place_after>
    </observers>
  </checkout_onepage_controller_success_action>     
</events>

closed as off-topic by Marius, David Manners, Keyul Shah, davidalger, Matthias Zeis Mar 18 '14 at 18:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Marius, David Manners, Keyul Shah, davidalger, Matthias Zeis
If this question can be reworded to fit the rules in the help center, please edit the question.