【问题标题】:Magento:Getting selected attribute value of product in Checkout Shipping moduleMagento:在结帐运输模块中获取产品的选定属性值
【发布时间】:2010-02-02 07:56:54
【问题描述】:

在我的网站上,有些产品不在加利福尼亚销售。在用户结账时,我必须进行验证,例如购物车是否有在加利福尼亚州不出售的商品并且用户的送货地址在加利福尼亚州,阻止用户结账。

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”值。

此代码在本地//Checkout/Block/Onepage/Shipping.php 中

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

提前致谢。

【问题讨论】:

    标签: magento attributes


    【解决方案1】:

    要在结帐时获取产品的属性,最简单的方法是完全加载产品:

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

    加载产品当然会产生开销,但这是从购物车项目中获取属性值的最快方法。

    【讨论】:

    • 正是克里斯,非常感谢!!
    【解决方案2】:
    <?php $_item = $this->getItem()?>
    <?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId())?>
    <?php echo $_product->getResource()->getAttribute('attribute_code')
          ->getFrontend()->getValue($_product); ?>
    

    app/design/frontend/your_default/your_default/template/checkout/cart/item/defaul‌​t.phtml

    【讨论】:

      猜你喜欢
      • 2017-10-13
      • 2016-07-16
      • 2018-03-27
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      相关资源
      最近更新 更多