2

I am using magento 1.9.1.0. Checkout as guest login using checkout. After payment method proceed to checkout it shows error "Call to a member function getTelephone()" /app/code/core/Mage/Sales/Model/Order.php on line 1293. But Register and checkout option working fine. Any idea about in this scenario?

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);

    $_customer = Mage::helper('customer')->getCustomer();
    $_customerData = $_customer->getData();
    $_customerPhone = $_customer->getPrimaryBillingAddress()->getTelephone();//error occured
    try {
        // Retrieve specified view block from appropriate design package (depends on emulated store)
        $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
            ->setIsSecureMode(true);
        $paymentBlock->getMethod()->setStore($storeId);
        $paymentBlockHtml = $paymentBlock->toHtml();
    } catch (Exception $exception) {
        // Stop store emulation process
        $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
        throw $exception;
    }

    // Stop store emulation process
    $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

    // 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) {
            $emailInfo->addBcc($email);
        }
    }
    $mailer->addEmailInfo($emailInfo);

    // 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');
            $emailInfo->addTo($email);
            $mailer->addEmailInfo($emailInfo);
        }
    }


    // Set all required params and send emails
    $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
    $mailer->setStoreId($storeId);
    $mailer->setTemplateId($templateId);
    $mailer->setTemplateParams(array(
        'order'        => $this,
        'billing'      => $this->getBillingAddress(),
    'custom_email' => $_customerData['email'],
    'custom_phone' => $_customerPhone,
        'payment_html' => $paymentBlockHtml
    ));

    /** @var $emailQueue Mage_Core_Model_Email_Queue */
    $emailQueue = Mage::getModel('core/email_queue');
    $emailQueue->setEntityId($this->getId())
        ->setEntityType(self::ENTITY)
        ->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
        ->setIsForceCheck(!$forceMode);

    $mailer->setQueue($emailQueue)->send();

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

    return $this;
}

$_customer = Mage::helper('customer')->getCustomer(); $_customerData = $_customer->getData(); $_customerPhone = $_customer->getPrimaryBillingAddress()->getTelephone();//error occured

5
  • I think you are using some extension for checkout as magento 1.x doesn't have any method calling getTelephone on that file. Or you have modified that file. Try to rename that file and use the default one and test. Jun 14, 2018 at 11:39
  • I am not yet any changes on this file (Order.php) $_customer = Mage::helper('customer')->getCustomer(); $_customerData = $_customer->getData(); $_customerPhone = $_customer->getPrimaryBillingAddress()->getTelephone(); error occur in this function.how to get guest billing address. $_customerData show empty for guest user. Here, what should I do for guest user? Jun 14, 2018 at 12:02
  • On which function you have added these line? Can you post you Order.php file on your question? Jun 14, 2018 at 12:13
  • $_customer->getPrimaryBillingAddress()->getTelephone(); this function not working for guest user only. Register user & register and checkout are working fine. Jun 14, 2018 at 13:05
  • I am posting you the solution. Wait for 5 mins. Jun 14, 2018 at 13:07

1 Answer 1

2

Try the below code:

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);

    $_customer = Mage::helper('customer')->getCustomer();
    $_customerData = $_customer->getData();
    try {
        // Retrieve specified view block from appropriate design package (depends on emulated store)
        $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
            ->setIsSecureMode(true);
        $paymentBlock->getMethod()->setStore($storeId);
        $paymentBlockHtml = $paymentBlock->toHtml();
    } catch (Exception $exception) {
        // Stop store emulation process
        $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
        throw $exception;
    }

    // Stop store emulation process
    $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

    // 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();
        $_customerPhone = $this->getBillingAddress()->getTelephone();

    } else {
        $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
        $customerName = $this->getCustomerName();
        $_customerPhone = $_customer->getPrimaryBillingAddress()->getTelephone();
    }

    /** @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) {
            $emailInfo->addBcc($email);
        }
    }
    $mailer->addEmailInfo($emailInfo);

    // 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');
            $emailInfo->addTo($email);
            $mailer->addEmailInfo($emailInfo);
        }
    }


    // Set all required params and send emails
    $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
    $mailer->setStoreId($storeId);
    $mailer->setTemplateId($templateId);
    $mailer->setTemplateParams(array(
        'order'        => $this,
        'billing'      => $this->getBillingAddress(),
    'custom_email' => $this->getCustomerEmail(),
    'custom_phone' => $_customerPhone,
        'payment_html' => $paymentBlockHtml
    ));

    /** @var $emailQueue Mage_Core_Model_Email_Queue */
    $emailQueue = Mage::getModel('core/email_queue');
    $emailQueue->setEntityId($this->getId())
        ->setEntityType(self::ENTITY)
        ->setEventType(self::EMAIL_EVENT_NAME_NEW_ORDER)
        ->setIsForceCheck(!$forceMode);

    $mailer->setQueue($emailQueue)->send();

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

    return $this;
}
4
  • Thanks a lot. Working fine. But, Guest user email id getting empty. 'custom_email' => $_customerData['email']. Jun 14, 2018 at 13:21
  • I am updating wait. Jun 14, 2018 at 13:22
  • Check the updated answer. Jun 14, 2018 at 13:24
  • Happy to Help! Upvote please. Jun 14, 2018 at 13:34

Your Answer

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

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