The little project is to export all items (sku and quantity) of an order using the Magento (1.9.3.2) events.
My NvM2MfExport.xml in /app/etc/modules:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<NvM2MfExport>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Checkout />
</depends>
</NvM2MfExport>
</modules>
</config>
My config.xml in /app/code/community/NV/M2MfExport/etc:
<?xml version="1.0"?>
<config>
<modules>
<NvM2MfExport>
<version>1.0.0</version>
</NvM2MfExport>
</modules>
<global>
<models>
<nvm2mfexport>
<class>Nv_Export_Model</class>
</nvm2mfexport>
</models>
<events>
<checkout_cart_save_after>
<observers>
<nvm2mfexport>
<class>nvm2mfexport/observer</class>
<method>orderExport</method>
</nvm2mfexport>
</observers>
</checkout_cart_save_after>
</events>
</global>
</config>
My Observer.php in /app/code/community/Nv/M2MfExport/Model:
<?php
class Nv_Export_Model_Observer
{
public function orderExport($observer)
{
//require_once '../app/Mage.php';
//Mage::app();
// Übergebenes Quote und Order Objekt holen
$order = $observer->getEvent()->getOrder();
$quote = $observer->getEvent()->getQuote();
// Nur schicken wenn tatsächlich eine Adresse zugewiesen wurde
if ($quote->getDistributorEmail())
{
// Lieferadresse als Text formatiert holen
$shipTo = $order->getShippingAddress()->format('text');
$itemsTxt = "Items\n-----------------------\n";
foreach ($order->getAllVisibleItems() as $item)
$itemsTxt .= 'SKU: ' . $item->getSku() . ' QTY: ' . $item->getQtyOrdered() . "\n";
$mail = Mage::getModel('core/email')
->setFromEmail('~@~.de')
->setSubject('Neue Bestellung')
->setToEmail('~@~.de')
->setBody("Lieferadresse:\n\n" . $shipTo . "\n" . $itemsTxt)
->send();
}
/*$myfile = fopen("/var/www/magento-1.9.3.2/newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);*/
}
}
The module is shown in the admin and enabled.
After a successfully order submit inside the backend (admin) I expected getting an email with some information. But nothing - not even a system log entry (logging is set on).
I also changed something in my php file that should result in throwing an error and another log entry. But nothing too. That's why I suggest that my Observer.php will not be called.