Friends,
i have read a lot about this part. Lots of people want to have some custom attributes in the PDF invoices and on the adminHtml part.
I am not able to get it work on the PDF. it works on the Cart, Checkout, adminHtml but not on the pdf.
I modify (rewrite): app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php different ways.
The attribute i try to call is "vpe" and is located after // custom options All I get is an empty value. By the way: the attribute must be called from the correct shop. In shop A i do not use this VPE. The invoice is from shop B and VPE is used on all products (its visible on the AdminHtml page) These ways did not work:
1)
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('vpe'));
if ($product) {
$lines[][] = array(
'text' => 'vpe:'.$product->getData('vpe'),
'feed' => 34
);
}
2)
$_item = $this->getItem();
$_item->setStoreId($_item->getInvoice()->getStoreId());
$storeId = $_item->getStoreId();
$productId = $_item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$_vpe = $product->getData('vpe');
$attributes = $product->getAttributes();
$dispAttribs = array('vpe');
foreach ($attributes as $attribute) {...
$attributeCode = $attribute->getAttributeCode();
if(!in_array($attributeCode, $dispAttribs)) continue;
$label = $attribute->getFrontend()->getLabel($product);
$value = $attribute->getFrontend()->getValue($product);
$_vpe = $value;
}
$lines[][] = array(
'text' => Mage::helper('core')->__('vpe: ') . $_vpe,
'feed' => 34
);
Using Magento 1.7.0.1
EDIT:
I found another way to try:
$product = Mage::getModel('catalog/product')->setStoreId($item->getStoreId())->loadByAttribute('sku', $this->getSku($item));
$attribute = $product->getResource()->getAttribute('vpe');
if ($attribute)
{
$_vpe = $attribute ->getFrontend()->getValue($product);
}
$lines[][] = array(
'text' => 'vpe:'.$_vpe,
'feed' => 34
);
After inserting this i get some VPE but from the wrong shop. any ideas?