After some research I managed to find some code which helped, which is below:
$cartItems = Mage::getSingleton('checkout/session')
->getQuote()
->getAllItems();
foreach ($cartItems as $item) {
$ean = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getEan();
echo $ean;
}
Where getEan is the name of my attribute with the first character as a capital letter.
Thank you all for the suggestions.
Before 1.8.1
I'm not aware of any ways to make this work, you have to either override the abstract core class in the local code pool or rewrite every single child class (ugly, I know).
From 1.8.1
on, they introduced the event customer_address_validation_after
. I got rid of the validation by using reflexion, even if I'm not too proud of it. Might not solve your problem, but I thought I'd post it anyway.
/**
* Validate address ignoring phone-related errors
*
* Internally uses reflexion. Maybe not the most
* efficient or clean implementation, but allows
* this functionality to be implemented without
* the need to rewrite 3 core classes.
*
* Listens to:
* - customer_address_validation_after
*
* @param Varien_Event_Observer $observer Event observer
*/
public function validateAddress(Varien_Event_Observer $observer)
{
/* @var $address Mage_Customer_Model_Address_Abstract */
$address = $observer->getAddress();
if (!$address) {
return;
}
$prop = new ReflectionProperty('Mage_Customer_Model_Address_Abstract', '_errors');
if (!$prop) {
return;
}
$prop->setAccessible(true);
$errors = $prop->getValue($address);
$prop->setValue($address, array());
$errorMessage = $this->getErrorMessage();
foreach ($errors as $error) {
if ($error !== $errorMessage) {
$address->addError($error);
}
}
}
/**
* Get standard error message
*
* @return string
*/
protected function getErrorMessage()
{
return Mage::helper('customer')->__('Please enter the telephone number.');
}
I also wrote an update script to define the filed as not required, and edited all forms to remove the frontend validation. Like I said, it might not be the best solution, but it's better than rewriting 3-4 classes IMHO.
UPDATE
The core team wrapped the event customer_address_validation_after
in a conditional starting from 1.9.0
through 1.9.1.1
(I really wonder why, makes no sense to me...) so my solution won't work for these versions, unfortunately. The conditional was luckily removed in 1.9.2
.
Best Answer
You can try this module