1

Hi I am editing the way the email for the Invoice on my store works and I need to get the customer collection for the order the invoice is being sent to so I can grab some customer info.

My code for the email is below, what is the best method of getting the customers First Name? I tried using $customer but it is not set as an object. I also currently am trying to load a customer entity by using their email address which I do have access to but I get an empty variable in my log.

It is also worth noting I am issuing invoices from the backend when testing and I am not sure if this changes how I need to get the customers collection.

public function send()
{
    $emailTemplate = Mage::getModel('core/email_template');
    // Send all emails from corresponding list
    while (!empty($this->_emailInfos)) {
        $emailInfo = array_pop($this->_emailInfos);

        Mage::app();
        $customeremail = $emailInfo->getToEmails();
        $customeremail = $customeremail[0];
        $customer = Mage::getModel("customer/customer");
        $customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
        $customer->loadByEmail($customeremail);
        $test = $customer->getId();
        Mage::log($test, null, 'logfile.log');
        $customerAttr = $customer->getMaconomy();
        // Handle "Bcc" recepients of the current email
        $emailTemplate->addBcc($emailInfo->getBccEmails());
        // Set required design parameters and delegate email sending to Mage_Core_Model_Email_Template
        if (!empty($this->_afile)) {
            $emailTemplate->setEmAttachments($this->_afile); //(by dw)
        }
        $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))->addBCC($customerAttr)
            ->sendTransactional(
                $this->getTemplateId(),
                $this->getSender(),
                $emailInfo->getToEmails(),
                $emailInfo->getToNames(),
                $this->getTemplateParams(),
                $this->getStoreId()
            );
    }
    return $this;
}

EDIT:

When I print_r $customer I get a lot of protected items, how can I resolve this??

2016-04-14T12:30:03+01:00 DEBUG (7): EH_CustomerApprove_Model_Customer Object
(
    [_customAttributes:protected] => Array
        (
        )

    [_fileAttributes:protected] => Array
        (
        )

    [_savedFileNames:protected] => Array
        (
        )

    [_eventPrefix:protected] => customer
    [_eventObject:protected] => customer
    [_errors:protected] => Array
        (
        )

    [_attributes:protected] => 
    [_addresses:protected] => 
    [_addressesCollection:protected] => 
    [_isDeleteable:protected] => 1
    [_isReadonly:protected] => 
    [_cacheTag:protected] => customer
    [_resourceName:protected] => customer/customer
    [_resource:protected] => 
    [_resourceCollectionName:protected] => customer/customer_collection
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
        )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => 
    [_idFieldName:protected] => entity_id
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array
        (
        )

    [_syncFieldsMap:protected] => Array
        (
        )

)
  • what do you get when you var_dump $customer? is the website ID correct? – Robin Apr 14 '16 at 10:35
  • I tried to dump to the log with the following: Mage::log($customer->debug(), null, 'logfile.log'); and got the following in the log "2016-04-14T12:28:22+01:00 DEBUG (7): Array ( )" – KiwisTasteGood Apr 14 '16 at 11:29
  • However, when I print_r I get a different output (updated answer) – KiwisTasteGood Apr 14 '16 at 11:30
  • ok but what does it show when you var_dump($customer) (maybe die; after so it stops executing code)? with var_dump it should show all the elements and their values in the $customer object – Robin Apr 14 '16 at 11:53
  • I get the same as the print_r - This Mailer.php is inside a invoice plugin so it possible it doesn't have the permission to access this stuff? – KiwisTasteGood Apr 14 '16 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.