1

I have a customer attribute "maconomy" that the user will enter an email address into on signup.

I am trying to Bcc this email address into the invoice emails.

I have successfully hard coded a Bcc in for testing which works great, however I am stuck in trying to retrieve this customer attribute to put into the Bcc!

My code for this sending section is below:

public function send()
{
    $emailTemplate = Mage::getModel('core/email_template');
    // Send all emails from corresponding list
    while (!empty($this->_emailInfos)) {
        $emailInfo = array_pop($this->_emailInfos);
        $erroremails = var_dump($emailInfo);
        $customer = Mage::getModel('customer/customer')->load($customerId);
        $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: Tried to get the customer ID as below but the log returns a blank variable.

$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerId = $customer->getId();
Mage::log($customerId, null, 'mylog.log');
1

In my opinion, you should call the addBcc method once, so basically instead of this part of your code:

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

I would try:

        $bccs = $emailInfo->getBccEmails();
        $customerAttr = $customer->getMaconomy();
        $bccs[] = $customerAttr;
        // Handle "Bcc" recepients of the current email
        $emailTemplate->addBcc($bccs);
        // 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()))
  • Hi thanks this may be better for my Bcc but my issue is that I cannot pull in the "maconomy" customer attribute into the Bcc it returns blank – KiwisTasteGood Apr 14 '16 at 8:03
  • Oh yeah ok, where do you defined the $customerId variable ? – Raphael at Digital Pianism Apr 14 '16 at 8:13
  • I found this in a tutorial for adding one into an email so I haven't actually set it! What is the best way of getting the current customer ID inside this email file? – KiwisTasteGood Apr 14 '16 at 8:16
  • So you haven't checked if you are getting a valid customer object? If $customer->getId() returns null, then your customer model is not loaded, and of course you cannot get any attributes on it. – Petar Dzhambazov Apr 14 '16 at 8:26
  • You are correct customer is not an object I just tried and got an error. How can I load the current customers object? I tried the edit above with no luck my log shows an empty variable – KiwisTasteGood Apr 14 '16 at 8:46

Your Answer

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

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