1

I have create a custom attribute call manufacturer_email from the backend and assign the values for the products.

The main reason for this is i need to fire an email to its manufacturer when an customer place a order through the web site. I found the observe for this and also how to fire the email.

The problem is the custom attribute returns an empty result without the email address. can anyone tell me how to get the value for this attribute???

Backend Code

public function logUpdate(Varien_Event_Observer $observer)
{        
  $order = $observer->getOrder();

  $email_stacks = array();
  foreach ($order->getAllItems() as $item)
  {
     // only add simple products to email, not a configurable product for example
     if ($item->getData('product_type')!=Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
        continue;

     $manufacturer = $item->getData('manufacturer_email');
     $sku = $item->getData('sku');
     Mage::log(" {$manufacturer} and {$sku} updated", null, 'manufacturer-email.log');

Result

2014-09-08T12:35:32+00:00 DEBUG (7):   and SKU5001 updated

Attribute and inputs

enter image description here

enter image description here

1

Instead of $item->getData('manufacturer_email');

Do: $item->getProduct()->getData('manufacturer_email');

The reason for this is that when you add a product to cart only some of it's attributes are transferred to the quote item object, sku being one of them. By default Magento behavior, custom attributes like manufacturer_email would not be added to the quote item object/table. So you need to retrieve the value from the product object.

  • Be careful, I doubt that data will get pulled across into the item product model. – Dave Sep 8 '14 at 12:48
  • What do you mean exactly? – Paras Sood Sep 8 '14 at 12:55
  • Still no luck :( $manufacturer = $item->getProduct()->getData('manufacturer_email'); $sku = $item->getData('sku'); Mage::log(" {$manufacturer} and {$sku} updated", null, 'manufacturer-email.log'); 2014-09-08T12:35:32+00:00 DEBUG (7): and SKU5001 updated 2014-09-08T12:55:18+00:00 DEBUG (7): and SKU5001 updated – Niranga Jayakody Sep 8 '14 at 12:56
  • You should log: $item->getProduct()->getData() and see it's content. Your custom attribute should be there. – Paras Sood Sep 8 '14 at 12:56
  • 2014-09-08T12:58:31+00:00 DEBUG (7): Array and SKU5001 updated – Niranga Jayakody Sep 8 '14 at 12:59
1

After going through so many codes i found ANSWER

$manufacturer= Mage::getModel('catalog/product')->load($item->getProductId())->getData('manufacturer_email');

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.