1

I want to export some orders from Magento 1.7, but I'm stuck on 1 thing. I have an attribute in Magento, named 'eancode'. I want to put the eancode from every product in the export, but it shows a blank field. I checked that the attribute contains some numbers for the exported products.

In csv.php I have:

/**
 * Returns the item specific values.
 * 
 * @param Mage_Sales_Model_Order_Item $item The item to get values from
 * @param Mage_Sales_Model_Order $order The order the item belongs to
 * @return Array The array containing the item specific values
 */
protected function getOrderItemValues($item, $order, $itemInc=1) 
{
    return array(
        $itemInc,
        $this->geteancode($item),
        $item->getName(),
    );
}

}

In abstractcsv.php I have:

/**
 * EAN code output
 *
 * @param Mage_Sales_Model_Order_Item $item The item to return info from
 * @return String The ean
 */
protected function geteancode($item)
{
$eancode = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->geteancode();
return $item->geteancode();
}

Can you see what's going wrong? I've been troubleshooting and Googling for hours now, but I can't find the problem.

Thank you!

1
  • Change this return $item->geteancode(); to this return $eancode.
    – Marius
    Dec 12, 2013 at 14:18

2 Answers 2

1

I can see two issues with your code:

  1. Even though you may have named the attribute in lower case, you will still need to refer to it in your get method using CamelCase, for example:

    $eancode = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->geteancode();
    
  2. In the first line of protected function geteancode($item) function, you retrieve the ean value, and then you return the geteancode() function again on the following line which would return an empty String.

Your method should read:

  protected function geteancode($item)
 {
     return Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getEancode();
 }
1
  • Thank you so much! This works great! Again something learned about PHP. :) I can't give you points now, because I don't have 15 reputation, but I will do if I have!
    – DutchTech
    Dec 12, 2013 at 14:28
0

In the Abstractcsv.php the following line should be corrected

$eancode = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->geteancode();

should be

$eancode = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getEancode();

Also I think it should return the $eancode variable and not the $item-geteancode().

2
  • Thank you for your fast answer! I can't give you points now, because I don't have 15 reputation, but I will do if I have!
    – DutchTech
    Dec 12, 2013 at 14:29
  • No problem, glad to have helped :) Dec 12, 2013 at 14:29

Your Answer

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

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