1

I’m working on a custom Magento extension that performs mass updates on order status, however it is not sending the customer an email when their order is updated.

enter image description here

Config

<?xml version="1.0"?>
<config>
    <modules>
        <VivasIndustries_MassCustomStatusses>
            <version>0.1.0</version>
        </VivasIndustries_MassCustomStatusses>
    </modules>
    <admin>
        <routers>
            <masscustomstatusses>
                <use>admin</use>
                <args>
                    <module>VivasIndustries_MassCustomStatusses</module>
                    <frontName>masscustomstatusses</frontName>
                </args>
            </masscustomstatusses>
        </routers>
    </admin>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order>VivasIndustries_MassCustomStatusses_Model_Order</order>
                </rewrite>
            </sales>
        </models>   
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>VivasIndustries_MassCustomStatusses_Block_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>
        <sales> 
            <order> 
                <states>
                    <masscustom1 translate="label">
                        <label>Mass Custom Action 1</label>
                        <statuses>
                            <masscustom1 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom1>
                    <masscustom2 translate="label">
                        <label>Mass Custom Action 2</label>
                        <statuses>
                            <masscustom2 default="2"/>
                        </statuses>
                        <visible_on_front>2</visible_on_front>
                    </masscustom2>
                    <masscustom3 translate="label">
                        <label>Mass Custom Action 3</label>
                        <statuses>
                            <masscustom3 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom3>
                    <masscustom4 translate="label">
                        <label>Mass Custom Action 4</label>
                        <statuses>
                            <masscustom4 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom4>
                    <masscustom5 translate="label">
                        <label>Mass Custom Action 5</label>
                        <statuses>
                            <masscustom5 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom5>
                    <masscustom6 translate="label">
                        <label>Mass Custom Action 6</label>
                        <statuses>
                            <masscustom6 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom6>
                    <masscustom7 translate="label">
                        <label>Mass Custom Action 7</label>
                        <statuses>
                            <masscustom7 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom7>
                    <masscustom8 translate="label">
                        <label>Mass Custom Action 8</label>
                        <statuses>
                            <masscustom8 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom8>
                    <masscustom9 translate="label">
                        <label>Mass Custom Action 9</label>
                        <statuses>
                            <masscustom9 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom9>
                    <masscustom10 translate="label">
                        <label>Mass Custom Action 10</label>
                        <statuses>
                            <masscustom10 default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </masscustom10>         
                </states>
            </order>
        </sales>    
    </global>
</config>

Controller

Here’s the method of the controller for mass order status changes:

public function NewMass1Action()
{
    $orderIds = $this->getRequest()->getPost('order_ids', array());
    $countHoldOrder = 0;

    foreach ($orderIds as $orderId) {
        $order = Mage::getModel('sales/order')->load($orderId);
        if ($order->canHold()) {
            $order->masscustom1()->save();
            $countHoldOrder++;
        }
    }

    if ($countHoldOrder) {
        $this->_getSession()->addSuccess($this->__('%s order(s) have changed status.', $countHoldOrder));
    }

    $this->_redirectUrl(Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/index'));
}

Model

Here is the method it calls for updating the order status:

public function masscustom1()
{
    $this->setMasscustom1BeforeState($this->getState());
    $this->setMasscustom1BeforeStatus($this->getStatus());
    $this->setState(self::STATE_MASSCUSTOM1, true);
    $orderId = isset($_POST['orderid']) ? $_POST['orderid'] : null;
    $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
    $comment = '';
    $order->sendOrderUpdateEmail(true, $comment);
    return $this;
}

Here is what happens when I view an order whose status I changed by this method:

enter image description here

So, can you guys help me fix the problem and make this method send emails for the order status changes?

1 Answer 1

2

You do not need to load the order again inside of masscustom1() since it is a method of the VivasIndustries_MassCustomStatusses_Model_Order class that is extending Mage_Sales_Model_Order. That means you are already working with an order object instance and that its methods should be invoked using $this.

You can just remove this part:

$orderId = isset($_POST['orderid']) ? $_POST['orderid'] : null;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);

And call the method on $this instead:

$comment = 'testing';
$this->sendOrderUpdateEmail(true, $comment)
2
  • I did what you recommend and now it says - Customer Notified instead of Customer Notification Not Applicable but it is not sending any emails again. So i still have the same problem. Also i you are right about the Mage_Sales_Model_Order. Any other advice? Commented Mar 22, 2015 at 21:41
  • Fantastico! It is working! Commented Mar 22, 2015 at 22:56

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.