Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I finally got it figured out. For reasons I cannot begin to fathom, the documentation completely omits the information I wanted to know.</p> <p>At any rate, in order to make an observer module that will send an email when a certain product is purchased and invoiced, you need the following:</p> <p>/app/etc/modules/Electricjesus_Notifyowner.xml</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;Electricjesus_Notifyowner&gt; &lt;active&gt;true&lt;/active&gt; &lt;codePool&gt;local&lt;/codePool&gt; &lt;/Electricjesus_Notifyowner&gt; &lt;/modules&gt; &lt;/config&gt; </code></pre> <p>/app/code/local/Electricjesus/Notifyowner/etc/config.xml</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;Electricjesus_Notifyowner&gt; &lt;version&gt;0.1.0&lt;/version&gt; &lt;/Electricjesus_Notifyowner&gt; &lt;/modules&gt; &lt;global&gt; &lt;models&gt; &lt;notifyowner&gt; &lt;class&gt;Electricjesus_Notifyowner_Model&lt;/class&gt; &lt;/notifyowner&gt; &lt;/models&gt; &lt;events&gt; &lt;sales_order_invoice_pay&gt; &lt;observers&gt; &lt;notifyOwnerEvent&gt; &lt;class&gt;notifyowner/observer&lt;/class&gt; &lt;method&gt;notifyOwnerEvent&lt;/method&gt; &lt;/notifyOwnerEvent&gt; &lt;/observers&gt; &lt;/sales_order_invoice_pay&gt; &lt;/events&gt; &lt;/global&gt; &lt;/config&gt; </code></pre> <p>and finally, /app/code/local/Electricjesus/Notifyowner/Model/Observer.php</p> <pre><code>&lt;?php class Electricjesus_Notifyowner_Model_Observer { public function notifyOwnerEvent($observer) { $invoice = $observer-&gt;getInvoice(); // derivative data $order = $invoice-&gt;getOrder(); // Mage_Sales_Model_Order $items = $order-&gt;getAllItems(); $i = 0; foreach($items as $item) { $str .= $item-&gt;getSku() . "/n"; $skus[$i] = $item-&gt;getSku(); $i++; } $shipAddr = $order-&gt;getBillingAddress(); $billAddr = $order-&gt;getShippingAddress(); $custName = $order-&gt;getCustomerName(); $email = array( 'to' =&gt; 'myname@maydomain.com', 'subject' =&gt; 'Confirmed Purchase', 'message' =&gt; ' &lt;html&gt; &lt;body&gt; '. $custName .' has ordered and paid for the following products. &lt;table&gt; &lt;th&gt; &lt;td&gt; Items Ordered &lt;/td&gt; &lt;td&gt; Shipping Address &lt;/td&gt; &lt;td&gt; Billing Address &lt;/td&gt; &lt;/th&gt; &lt;tr&gt; &lt;td&gt; '. $str .' &lt;/td&gt; &lt;td&gt; '. $shipAddr .' &lt;/td&gt; &lt;td&gt; '. $billAddr .' &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;', 'headers' =&gt; 'From: My Store' ); $needle = 'mysku-01'; if( in_array( $needle, $skus ) ) { mail($email['to'], $email['subject'], $email['message'], $email['headers']); } return $this; // always return $this. } } </code></pre> <p>Note that the product being detected is specified via <code>$needle = 'mysku-01';</code> and the email itself is built via the <code>$email[]</code> array.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload