2016-03-03 137 views
0

我需要能夠將產品頁面上的「購物車價格規則」應用於產品頁面上的價格,然後才能將產品添加到購物車。不使用'目錄價格規則'的原因是它沒有提供足夠的功能。有問題的產品在同一頁面上有相關產品,如果符合條件(例如添加了相關產品的數量x),則提供折扣。我需要將此價格更改顯示給用戶。Magento顯示購物車產品頁面上的價格規則

我一直無法找到Magento在購物車中應用這些規則的位置,因此無法開始嘗試將它們添加到產品頁面。任何反饋,以幫助得到這個運行非常感謝。

謝謝:)

回答

0

你可以得到應用的產品頁面上的購物車價格規則,下面的功能

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

其中$產品是產品對象產品頁面上已經存在。

相關問題