I am making an extension that filters each order and send out an e-mail to each drop shipper in order.
Example
Order with 3 products. 2 products from drop shippers A and 1 product from drop shipper B.
Dropshipper A with should receive email containing only their 2 products and drop shipper B should receive email containing just their 1 product.
I want to maintain default Magento e-mail template functionality, so email is easy to update.
This is what i have so far.
Observer model that listen for <sales_order_place_after>
<events>
<sales_order_place_after>
<observers>
<sales_order_place_after_handler>
<type>model</type>
<class>dropshipperemail/observer</class>
<method>sendEmail</method>
</sales_order_place_after_handler>
</observers>
</sales_order_place_after>
</events>
A method in observer that filter products and build array containing correct data.
public function sendEmail(Varien_Event_Observer $observer)
{
$order = $observer->getOrder();
$orderItems = $order->getAllVisibleItems();
foreach($orderItems as $item):
$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($item->getProductId());
if($dropshipper = $product->getAttributeText('dropshipper')):
$list[$dropshipper][$product->getSku()] = array(
'name' => $product->getName(),
'sku' => $product->getSku(),
'qty' => $item->getData('qty_ordered'),
'price' => $item->getPrice()
);
endif;
endforeach;
}
I can pass variables to transactional email and send fine.
But what i would like to do and i think is more elegant solution is to somehow rewrite queueNewOrderEmail and pass params with it (recipient email and product attribute to filter) like queueNewOrderEmail(false, $dropshipper, $recipient)
. Then i can do the actual filtering in render file
/app/design/frontend/base/default/template/email/order/items/order/default.phtml
Will this be working solution or am i missing something important?