2

Hooking into the event/observer methods already created I could build an email that would send when the status was update to 'status' => 2 correct? After the event has taken place.

I believe I would use this event?

<catalog_product_status_update>
    <observers>
        <sales_quote>
            <class>sales/observer</class>
            <method>catalogProductStatusUpdate</method>
        </sales_quote>
    </observers>
</catalog_product_status_update>

My observer:

class Namespace_Custmail_Model_Observer
{
    public function invoicedStatusChange($event)
    {
        $order = $event->getOrder();
        $orderStatus = $order->getStatus();
        if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED)
            $this->_sendStatusMail($order);
    }

    private  function _sendStatusMail($order)
    {
        $emailTemplate  = Mage::getModel('core/email_template');

        $emailTemplate->loadDefault('custom_order_tpl');
        $emailTemplate->setTemplateSubject('Your order was holded');

        // Get General email address (Admin->Configuration->General->Store Email Addresses)
        $salesData['email'] = Mage::getStoreConfig('trans_email/ident_general/email');
        $salesData['name'] = Mage::getStoreConfig('trans_email/ident_general/name');

        $emailTemplate->setSenderName($salesData['name']);
        $emailTemplate->setSenderEmail($salesData['email']);

        $emailTemplateVariables['username']  = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname();
        $emailTemplateVariables['order_id'] = $order->getIncrementId();
        $emailTemplateVariables['store_name'] = $order->getStoreName();
        $emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
        $emailTemplate->send($order->getCustomerEmail(), $order->getStoreName(), $emailTemplateVariables);
    }
}

Basically, anytime a product is disabled send an email. Any help would be greatly appreciated. Thank you.

1 Answer 1

1

You're right on the event catalog_product_status_update here's how you could do create a new method in your observer to implement the email notification system:

public function catalogProductStatusUpdate(Varien_Event_Observer $observer)
{
    $status = $observer->getEvent()->getStatus();
    if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
        return $this;
    }
    $productId  = $observer->getEvent()->getProductId();
    $storeId  = $observer->getEvent()->getStoreId();
    $this->_sendProductStatusMail($productId, $storeId);
}

private  function _sendProductStatusMail($productId, $storeId)
{
    $emailTemplate  = Mage::getModel('core/email_template');

    $emailTemplate->loadDefault('custom_product_tpl');
    $emailTemplate->setTemplateSubject('The product was disabled');

    // Get General email address (Admin->Configuration->General->Store Email Addresses)
    $salesData['email'] = Mage::getStoreConfig('trans_email/ident_general/email');
    $salesData['name'] = Mage::getStoreConfig('trans_email/ident_general/name');

    $emailTemplate->setSenderName($salesData['name']);
    $emailTemplate->setSenderEmail($salesData['email']);

    $emailTemplateVariables['product_id'] = $productId;
    $emailTemplateVariables['store_id'] = $storeId;
    $emailTemplate->send($salesData['email'], $salesData['name'], $emailTemplateVariables);
}

Please note that you will have to create a custom_product_tpl email template and probably modify the _sendProductStatusMail method to fit your needs.

Your Answer

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

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