Mohd Nizam Mohd Nizam - 5 months ago 240x
PHP Question

Extend Mage_Sales_Model_Order

how do i start ? hrmmmm.
ok , right now Im trying to extend the mage_sales_mode_order . but this error appear.
Fatal error: Call to a member function load() on a non-object in /app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php on line 74

i don't know what is the problem because i already try using the same code extend different magento site but is working.
but below is what that i do and thanks in advance.


class MageCustom_Sales_Model_Order extends Mage_Sales_Model_Order

public function queueNewOrderEmail($forceMode = false)
$storeId = $this->getStore()->getId();

if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
return $this;

// Get the destination email addresses to send copies to
$copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
$copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);

// Start store emulation process
/** @var $appEmulation Mage_Core_Model_App_Emulation */
$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

try {
// Retrieve specified view block from appropriate design package (depends on emulated store)
$paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
$paymentBlockHtml = $paymentBlock->toHtml();
} catch (Exception $exception) {
// Stop store emulation process
throw $exception;

// Stop store emulation process

// Retrieve corresponding email template id and customer name
if ($this->getCustomerIsGuest()) {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
$customerName = $this->getBillingAddress()->getName();
} else {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
$customerName = $this->getCustomerName();

/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
/** @var $emailInfo Mage_Core_Model_Email_Info */
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getCustomerEmail(), $customerName);
if ($copyTo && $copyMethod == 'bcc') {
// Add bcc to customer email
foreach ($copyTo as $email) {

// Email copies are sent as separated emails if their copy method is 'copy'
if ($copyTo && $copyMethod == 'copy') {
foreach ($copyTo as $email) {
$emailInfo = Mage::getModel('core/email_info');

// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml

/** @var $emailQueue Mage_Core_Model_Email_Queue */
$emailQueue = Mage::getModel('core/email_queue');

Mage::log('new order trigger email', null, 'email.log');

$this->_getResource()->saveAttribute($this, 'email_sent');

return $this;




<?xml version="1.0" encoding="UTF-8"?>



Your class and configuration are all correct assuming they exist in app/code/local, except for the active setting in MageCustom_Sales.xml:


Turn it on, clear your cache and try again :)


> With Magerun

If you've got magerun, you can use it to test your rewrite:

n98-magerun.phar dev:class:lookup model sales/order
# Model sales/order resolves to MageCustom_Sales_Model_Order

If you don't see the above resolution, you may have conflicts with the rewrite, but it's more likely that your rewrite configuration is wrong.

If you don't have Magerun - get it! You won't regret it.

> Without Magerun

You can drop a custom script into the root directory of your Magento project just to test the class alias:

include 'app/Mage.php';

Run it from command line via php myTestFile.php, or from browser via http://magento.local/myTestFile.php.

If it works, you should see string(28) "MageCustom_Sales_Model_Order". If it doesn't you'll see bool(false).

Hope this helps.