1

I'm creating an event that will log information from this page, however, i'm not entirely sure how to log the information contained within this form upon checkout. So, I plan to dispatch an event that an observer will listen for. This observer will create an entry in a log file. Currently I have something that looks like this:

<?php
Mage::dispatchEvent(
    'no_quotes_available',
    array(
        'address' => $address,
        'products' => $products
    )
);
?>

And within the observer is:

    public function log_shipping_error($observer){
        $event = $observer->getEvent();
        $date = Mage::getModel(‘core/date’)->date(‘Y-m-d H:i:s’);
        $products = $event->getProducts();
        $address = $event->getAddress();
        Mage::log('date: '.$date, null, 'noShipLog.log');
        Mage::log('products: '.$products, null, 'noShipLog.log');
        Mage::log('address: '.$address, null, 'noShipLog.log');
        return;
    }
}

My question can be condensed to: How do I get information relating shipping information from the checkout page to my observer?

What would be the best way to get:

$products

and

$address

from checkout?

  • I could also send only the information from the checkout form to server via the observer and just fetch the cart on my own. Is this possible? – hownowbrowncow Oct 22 '14 at 19:59
3

I think you can send the full quote to the observer and get the data from quote in there

<?php
Mage::dispatchEvent(
    'no_quotes_available',
    array(
        'quote' => Mage::getSingleton('checkout/session')->getQuote(),
    )
);
?>

You can retrieve the quote in your observer like this:

public function doSomething($observer)
{
    $quote = $observer->getEvent()->getQuote();
    $items = $quote->getAllItems();
    $billingAddress = $quote->getBillingAddress();
    $shippingAddress = $quote->getShippingAddress();
    ....
}

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.