2014-12-25 4 views
3

전 매장 제품의 특별 가격이 원래 가격과 다른 (낮아진) 프로젝트를 진행 중입니다.Magento - 장바구니 수정 규칙 제품 가격 할인 대신 원래 가격의 백분율로 할인 적용 기능

장바구니 할인을 적용 할 수 있기를 원합니다. 카탈로그 할인 가격 규칙과 마찬가지로 원래 가격의 백분율을 적용하고 싶습니다.

바로 지금 쇼핑 카트 "제품 가격 할인율"규칙을 적용하면 원래 가격 대신 특별 가격에 할인이 적용됩니다.

장바구니 규칙 기능은 어디에 있습니까? 원래 가격에 할인을 적용하기 위해 수정에 대한 자세한 내용은 인정 될 것입니다.

답변

0

나는 최근에 같은 문제를 해결해야했습니다. Thesetwo 블로그 가이드는 내 최종 솔루션을 만드는 데 큰 도움이되었습니다.

salesrule_validator_process 이벤트에 내 사용자 정의 관찰자는 다음과 같습니다 제대로 확장을

class My_SalesRule_Model_Observer 
{ 
    // New SalesRule type 
    const TO_ORIGINAL_PRICE = 'to_original_price'; 

    /** 
    * Add the new SalesRule type to the admin form. 
    * @param Varien_Event_Observer $obs 
    */ 
    public function adminhtmlBlockSalesruleActionsPrepareform($obs) 
    { 
     $field = $obs->getForm()->getElement('simple_action'); 
     $options = $field->getValues(); 
     $options[] = array(
      'value' => self::TO_ORIGINAL_PRICE, 
      'label' => Mage::helper('salesrule')->__('Percent of original product price discount') 
     ); 
     $field->setValues($options); 
    } 

    /** 
    * Apply the new SalesRule type to eligible cart items. 
    * @param Varien_Event_Observer $obs 
    */ 
    public function salesruleValidatorProcess($obs) 
    { 
     /* @var Mage_SalesRule_Model_Rule $rule */ 
     $rule = $obs->getRule(); 
     if ($rule->getSimpleAction() == self::TO_ORIGINAL_PRICE) { 
      /* @var Mage_Sales_Model_Quote_Item $item */ 
      $item = $obs->getItem(); 
      // Apply rule qty cap if it exists. 
      $qty = $rule->getDiscountQty()? min($obs->getQty(), $rule->getDiscountQty()) : $obs->getQty(); 
      // Apply rule stepping if specified. 
      $step = $rule->getDiscountStep(); 
      if ($step) { 
       $qty = floor($qty/$step) * $step; 
      } 

      // Rule discount amount (assumes %). 
      $ruleDiscountPercent = $rule->getDiscountAmount(); 
      /* @see My_Catalog_Model_Product::getDiscountPercent */ 
      $productDiscountPercent = $item->getProduct()->getDiscountPercent(); 

      // Ensure that the rule does not clobber a larger discount already present on the $cartItem. 
      // Do not apply the rule if the discount would be less than the price they were already quoted 
      // from the catalog (i.e. special_price or Catalog Price Rules). 
      if ($ruleDiscountPercent > $productDiscountPercent) { 
       // Reduce $ruleDiscountPercent to just the gap required to reach target pct of original price. 
       // In this way we add the coupon discount to the existing catalog discount (if any). 
       $ruleDiscountPercent -= $productDiscountPercent; 

       $pct = $ruleDiscountPercent/100; 
       // Apply the discount to the product original price, not the current quote item price. 
       $discountAmount = ($item->getProduct()->getPrice() * $pct) * $qty; 

       $item->setDiscountPercent($ruleDiscountPercent); 
       $obs->getResult() 
        ->setDiscountAmount($discountAmount) 
        ->setBaseDiscountAmount($discountAmount); 
      } 
     } 
    } 
} 

을 설정 한 경우, 새 규칙 유형을 볼 나타납니다 미만 :

프로모션 -> 장바구니 가격 규칙 -> '새 규칙'-> 작업 -> 다음 정보를 사용하여 가격을 업데이트하십시오. [원래 제품 가격 할인율] 적용

경고 : 나는 이것을 사용하여 백분율 g 카탈로그 할인 가격을 계산하기 위해 제품 모델에 메소드를 생성하는 것. 특별 가격 및 카탈로그 수준에서 적용되는 기타 할인). 만약 당신이 이것을 원한다면 구현할 필요가있을 것입니다. 아니면 $item->getProduct()->getPrice()을 대신하여 당신의 시나리오에 맞게이 로직을 업데이트하십시오.