drq231358 2016-03-03 09:51
浏览 28

产品页面上的Magento显示购物车价格规则

I need to be able to apply 'Shopping Cart Price Rules' to the price on the product page, prior to the product being added to the shopping cart. The reason for not using 'Catalog Price Rules' is that it doesn't offer enough functionality. The product(s) in question have associated products on the same page, if a condition is met, such as x amount of associated products being added, then a discount is provided. I need this price change to be displayed to the user.

I have not been able to find where Magento applies these rules in the shopping cart, so have been unable to start trying to add them to the product page. Any feedback to help get this running is greatly appreciated.

Thank you :)

  • 写回答

1条回答 默认 最新

  • dppi5167 2016-08-31 09:53
    关注

    you can get applied shopping cart price rules on product page with below function

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

    where $product is product object already exist on product page.

    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码