1

Synopsis

I have been building an abandoned cart e-mail, which is almost working. I have been struggling with the transaction e-mails and blocks.

I have a table that will be populated with prospects whom abandon their basket which after 7 days will be contacted. A cron will run every day and send the e-mails.

Observer and E-mail Template

The observer I have:

/**
 * Aggregate abandoned carts and e-mail them.
 *
 * @param Varien_Event_Observer $observer
 * @return void
 */
public function emailAbandonedCartCustomers($observer)
{
    $collection = Mage::getResourceModel('cartabandonment/email_queue_collection')
        ->addFieldToFilter('status', Example_CartAbandonment_Model_Email_Queue::STATUS_PEND);

    foreach ($collection as $customerQuote) {
        $quote = Mage::getModel('sales/quote')->loadByIdWithoutStore(
            $customerQuote->getQuoteEntityId()
        );

        $data = new Varien_Object();
        $data->setData(array(
            'quote' => $quote->getData(),
            //'items' => $quote->getItemsCollection(),
            'items' => $quote->getItemsCollection()->toArray(),
        ));

        //Zend_Debug::dump($data);
        //Zend_Debug::dump(get_class_methods($quote));
        //Zend_Debug::dump($data->getData('items'));

        $emailTemplate = Mage::getModel('core/email_template');

        $emailTemplate->setDesignConfig(array('area' => 'frontend'))
            ->setReplyTo($this->_getHelper()->getSender())
            ->addBcc($this->_getHelper()->getBcc())
            ->sendTransactional(
                $this->_getHelper()->getEmailTemplate(),
                $this->_getHelper()->getSender(),
                $customerQuote->getEmailAddress(),
                null,
                array('data' => $data)
            );


        die('Testing Process');

        if ( ! $emailTemplate->getSentSuccess()) {
            Mage::throwException($this->_getHelper()->__('E-mail was not sent.'));
        }
    }
}

The transaction e-mail has been loaded and configured in the admin console:

Hi {{var quote.customer_firstname}},

You have not completed your purchase, would you like to checkout now?

{{block type='core/template' template='email/example/abandoned_items.phtml' products=$items}}

The contents of email/example/abandoned_items.phtml are:

<? print_r($products) ?>

1 Answer 1

0

I solved this using Mage::register and Mage::registry.

$quote = Mage::getModel('sales/quote')->loadByIdWithoutStore(
    $customerQuote->getQuoteEntityId()
);

$data = new Varien_Object();
$data->setData(array(
    'quote' => $quote->getData(),
));

Mage::register('abandoned_cart', $quote);

$emailTemplate = Mage::getModel('core/email_template');

Inside the E-mail template you would need to collect this object:

<?php
$_quote = Mage::registry('abandoned_cart');
$_collection = $_quote->getItemsCollection()->toArray();
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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