views:

265

answers:

1

Hi all, In my website, some products are not for sale in California. While the user checkouts, I have to do a validation like if the cart has items not for sale in California and user's shipping address is in CAlifornia, prevent user from checking out.

The sale in CA is set from admin side using an 'avl' attribute.

here is the code I use to iterate through the cart and check for the attribute


.....................
 $cart = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
       foreach ($cart as $_item){

           $_product = $_item->getProduct();
           //If atleast one product has availability status set to California, then set the flag and break.
           if($_product->getResource()->getAttribute('avl')->getFrontend()->getValue($_product) == 'NC'){
               $flag = true;
               break;
           }
......................

Well, now the problem is I'm not able to get the 'avl' value as set from the Admin side.

This code is in local//Checkout/Block/Onepage/Shipping.php

Any idea about how to retrieve the attribute value?

Thanks in advance.

+1  A: 

To get a product's attributes during checkout, the easiest way is to just completely load the product:

$_product = Mage::getModel('catalog/product')->load($_item->getProduct());
$_avl = $_product->getAvl();

There are of course overheads with loading a product but this is the fastest way to get an attribute value from a cart item.

Chris Norton
Exactly Chris, Thanks a lot!!
Sreejith