I want to make sure a customer cannot set a Quantity other than "1" for some special products. These products all have a special attribute set.
I tried to observe sales_quote_item_qty_set_after
and manually set the quantity:
public function enforceQty (Varien_Event_Observer $observer)
{
$_item = $observer->getEvent()->getItem();
// ...
if ($_item->getQty() > 1)
{
$_item->setQty(1);
}
}
which works perfectly fine, except that when I try to get the value of said attribute, to identify my special products, I do not get the correct value:
$_product = $_item->getProduct();
$_productId = $_product->getId();
$_storeId = Mage::app()->getStore()->getId();
$val = Mage::getResourceModel('catalog/product')
->getAttributeRawValue($productId, 'special_attr', $storeId);
special_attr
is a boolean attribute. In the HTML output of the product, it shows the correct value Yes
. In the code above, $val
gets set to false
for some reason.
I tried several different ways to get the value of special_attr
, all of them return false
instead of true
.
Any Idea?
Edit 1:
I just found a method returning the correct value. Sadly the value returned is language dependent.
$val = Mage::getModel('catalog/product')
->load($_product->getId())
->getAttributeText('special_attr');
Can somebody explain why this method returns the correct value, and the other does not?
Edit 2:
After crawling through the sources for getAttributeText, I found that I can get the value I'm looking for like this:
$val = Mage::getModel('catalog/product')
->load($_product->getId())
->getData('special_attr') == "1"
In addition to Question 1: Is there a way to get the actual boolean value, instead of a string value?