2016-07-13 4 views
0
public function coupon($data) { 
     $couponCode = $data['couponcode']; 
     if (!Zend_Validate::is(trim($couponCode), 'NotEmpty')) { 
      throw new Exception($this->__('coupon code cannot be empty.')); 
     } 
     $oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code'); 
     $data = $oCoupon->getData(); 
     if (empty($data)) { 
      throw new Exception($this->__('coupon code did not match.')); 
     }  
     $quote = Mage::getModel('checkout/session')->getQuote(); 
     $quote->setCouponCode($couponCode); 
     $quote->save(); 
     $quoteData = Mage::getModel('checkout/cart')->getQuote(); 
     $subTotal = $quoteData['subtotal']; 
     $subtotal_with_discount = $quoteData['subtotal_with_discount']; 
     $grandTotal = $quoteData['grand_total']; 
     $discountTotal = ($subTotal - $subtotal_with_discount); 
     $discount = number_format($discountTotal, 4, null, ''); 
     return $discount; 
    } 

쿠폰 코드를 적용하고 보여주는하지만 인쇄 할 때 quoteData-> GetData의() 후 할인이 오지 않아, 나는 새로 고침 카트 페이지를 업데이트 할 때 다음 할인추가 할인 프로그래밍

오고있다

답변

2

나는 해결책을 가지고

public function coupon($data) { 
     $couponCode = $data['couponcode']; 
     if (!Zend_Validate::is(trim($couponCode), 'NotEmpty')) { 
      throw new Exception($this->__('coupon code cannot be empty.')); 
     } 
     $oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code'); 
     $data = $oCoupon->getData(); 
     if (empty($data)) { 
      throw new Exception($this->__('coupon code did not match.')); 
     } 
     Mage::getSingleton('checkout/cart')->getQuote()->getShippingAddress() 
       ->setCollectShippingRates(true); 
     Mage::getSingleton('checkout/cart')->getQuote() 
       ->setCouponCode($couponCode)->collectTotals()->save(); 
     $quoteData = Mage::getModel('checkout/cart')->getQuote(); 
     $subTotal = $quoteData['subtotal']; 
     $subtotal_with_discount = $quoteData['subtotal_with_discount']; 
     $grandTotal = $quoteData['grand_total']; 
     $discountTotal = ($subTotal - $subtotal_with_discount); 
     $discount = number_format($discountTotal, 4, null, ''); 

     return $discount; 
    }