【问题标题】:Magento Display Shopping Cart Price Rules on Product PageMagento 在产品页面上显示购物车价格规则
【发布时间】:2016-03-03 09:51:53
【问题描述】:

在将产品添加到购物车之前,我需要能够将“购物车价格规则”应用于产品页面上的价格。不使用“目录价格规则”的原因是它没有提供足够的功能。有问题的产品在同一页面上有关联产品,如果满足条件,例如添加 x 数量的关联产品,则提供折扣。我需要向用户显示此价格变化。

我无法找到 Magento 在购物车中应用这些规则的位置,因此无法开始尝试将它们添加到产品页面。非常感谢任何有助于此运行的反馈。

谢谢你:)

【问题讨论】:

    标签: php magento shopping-cart


    【解决方案1】:

    您可以通过以下功能在产品页面上获取应用的购物车价格规则

    public function getShoppingCartRules($product) {
        $now = Mage::getModel('core/date')->date('Y-m-d');
        $productData = new Varien_Object();
        $data = array(
            'product' => $product,
            'qty' => 1,
            'price' => $product->getFinalPrice(),
            'base_row_total' => $product->getFinalPrice()
        );
        $productData->setData($data);
        $allItems = new Varien_Object();
        $allItems->setAllItems(array($productData));
        $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    
        $ruleCollection = Mage::getResourceModel('salesrule/rule_collection')
                ->addFieldToFilter('discount_amount', array("gt" => '0'))
                ->addFieldToFilter('coupon_type', array(1,2,3))
                ->setOrder('sort_order', 'DESC')
                ->addWebsiteGroupDateFilter(Mage::app()->getStore()->getWebsiteId(), $customerGroupId);
        $ruleCollection->getSelect()
                ->where('from_date is null or from_date <= ?', $now)
                ->where('to_date is null or to_date >= ?', $now);
    
        if ($ruleCollection->count()) {
                if ($rule->getActions()->validate($productData) && $rule->validate($allItems)) {
                    $shoppingCartRules[] = $rule;
                }
            }
            return $shoppingCartRules;
        }
        return null;
    }
    

    其中 $product 是产品对象已存在于产品页面上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-18
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多