2010-02-02 41 views
1

在我的网站中,有些产品不在加利福尼亚州销售。在用户结帐时,我必须进行验证,例如购物车中的商品不在加州销售,用户的送货地址在加利福尼亚州,防止用户退房。Magento:在Checkout Shipping模块中获取产品的选定属性值

在CA中的销售是从管理员端使用'avl'属性设置的。

这里是我使用过的车进行迭代并检查属性


..................... 
$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; 
      } 
...................... 

那么,现在的问题是,我不能够得到“AVL”值由管理员设置代码侧。

此代码是在本地//结帐/座/ Onepage/Shipping.php

有关如何检索属性值的任何想法?

在此先感谢。

回答

2

在结帐过程中获得产品的属性,最简单的方法是只完全加载产品:

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

当然也有开销与加载产品,但这是为了得到一个属性值的最快方法从购物车项目。

+0

正是克里斯,非常感谢! – Sreejith 2010-02-08 04:23:46

0
<?php $_item = $this->getItem()?> 
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId())?> 
<?php echo $_product->getResource()->getAttribute('attribute_code') 
     ->getFrontend()->getValue($_product); ?> 

应用程序/设计/前端/ your_default/your_default /模板/结帐/车/项目/ defaul t.phtml