2014-06-06 2 views
0

저는 ZenCart 1.5.1 및 "TaxCloud"라고하는 사용자 지정 모드로 작업하고 있습니다.ZenCart에서 진행중인 주문의 총 할인을 검색합니다.

모듈 ot_coupon.php에 의해 계산중인 활성, 공정 오더의 할인 합계를 검색하는 방법이 있는지 알고 싶습니다. (아직 완료되지 않았지만 완료되는 순서대로)

값이 $od_amount['total']이라는 변수에 저장되어 있다는 것을 알고 있습니다. 또한 checkout_paymentcheckout_confirmation 페이지에 표시됩니다.

하지만 그 값을 여기에

참조 할 필요는 ZenCart 1.5.1의 ot_coupon.php에서 관련 코드입니다. PHP 클래스의 일부입니다. 정확히 같은 일을하려고하는 것은 아니지만

function calculate_deductions($order_total) { 
global $db, $order, $messageStack, $currencies; 
$currencyDecimalPlaces = $currencies->get_decimal_places($_SESSION['currency']); 
$od_amount = array('tax'=>0, 'total'=>0); 
if ($_SESSION['cc_id']) 
{ 
    $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'"); 
    $this->coupon_code = $coupon->fields['coupon_code']; 
    $orderTotalDetails = $this->get_order_total($_SESSION['cc_id']); 
    if ($coupon->RecordCount() > 0 && $orderTotalDetails['orderTotal'] != 0) 
    { 
    if (strval($orderTotalDetails['orderTotal']) >= $coupon->fields['coupon_minimum_order']) 
    { 
     switch($coupon->fields['coupon_type']) 
     { 
     case 'S': 
      $od_amount['total'] = $orderTotalDetails['shipping']; 
      $od_amount['type'] = 'S'; 
      $od_amount['tax'] = ($this->calculate_tax == 'Standard') ? $orderTotalDetails['shippingTax'] : 0; 
      if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') { 
      $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax']; 
      } 
      return $od_amount; 
      break; 
     case 'P': 
      $od_amount['total'] = zen_round($orderTotalDetails['orderTotal']*($coupon->fields['coupon_amount']/100), $currencyDecimalPlaces); 
      $od_amount['type'] = $coupon->fields['coupon_type']; 
      $ratio = $od_amount['total']/$orderTotalDetails['orderTotal']; 
      break; 
     case 'F': 
      $od_amount['total'] = zen_round($coupon->fields['coupon_amount'] * ($orderTotalDetails['orderTotal']>0), $currencyDecimalPlaces); 
      $od_amount['type'] = $coupon->fields['coupon_type']; // amount off 'F' or amount off and free shipping 'O' 
      $ratio = $od_amount['total']/$orderTotalDetails['orderTotal']; 
      break; 
     } 
     switch ($this->calculate_tax) 
     { 
     case 'None': 
      break; 
     case 'Standard': 
      if ($od_amount['total'] >= $orderTotalDetails['orderTotal']) $ratio = 1; 
      foreach ($orderTotalDetails['orderTaxGroups'] as $key=>$value) 
      { 
      $od_amount['tax_groups'][$key] = zen_round($orderTotalDetails['orderTaxGroups'][$key] * $ratio, $currencyDecimalPlaces); 
      $od_amount['tax'] += $od_amount['tax_groups'][$key]; 
      if ($od_amount['tax_groups'][$key] == 0) unset($od_amount['tax_groups'][$key]); 
      } 
      if (DISPLAY_PRICE_WITH_TAX == 'true' && $coupon->fields['coupon_type'] == 'F') $od_amount['total'] = $od_amount['total'] + $od_amount['tax']; 
      break; 
     case 'Credit Note': 
      $tax_rate = zen_get_tax_rate($this->tax_class); 
      $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate); 
      $tax_description = zen_get_tax_description($this->tax_class); 
      $od_amount['tax_groups'][$tax_description] = $od_amount['tax']; 
     } 
    } 
    } 
} 


    return $od_amount; 
} 

답변

1

, 내가 계산하고 후에 카트 전체에 무료 배송베이스에 freeoptions 운송 모듈을 조정하다, 할 수 있기를 원하는 것을 충분히 유사하다 할인은 적용되지 않고 적용됩니다.

이렇게하려면 할인 모듈 (ot_coupon.php) 당 금액과 내가 설치 한 추가 모듈 플러그인 (ot_newsletter_discount.php)을 얻는 방법을 알아야했습니다. includes/modules/order_total 디렉토리에 있습니다.

다른 할인 판매점도 여기에 있어야합니다. 할인이 유효한지 여부를 결정하는 가장 좋은 방법은 무엇인지 파악해야합니다. 그래서 IF - ELSE 문을 가지고 있습니다.

아래 코드를 이해하면 설명 할 필요가 없습니다. 그것은 작동합니다. 당신은 그것을 어디에 넣을 지 알아 내고 그것을 당신의 목적을 위해 사용해야합니다. 나는 계획이 빡빡 해 시간이 더있을 때 더 확장 할 수 있습니다. 아니, 롤.

// added this for calculating Adjusted Total AFTER Discounts to base free shipping on, 
// instead of free shipping based on total BEFORE discounts! 

if (isset($_SESSION['cc_id'])) { 
    $coupon_total = $ot_coupon->calculate_deductions($_SESSION['cart']->show_total()); 
} else { $coupon_total['total'] = 0; } 

if ($ot_newsletter_discount->is_subscriber()) { 
    $nwsltr_total = $ot_newsletter_discount->calculate_deductions(); 
} else { $nwsltr_total['total'] = 0; } 

$total_discounts = $coupon_total['total'] + $nwsltr_total['total']; 
$adjusted_total = $_SESSION['cart']->show_total() - $total_discounts; 

// echo 'Total Discounts = ' . $currencies->format($total_discounts) . '<br>'; 
// echo 'Adjusted Total = ' . $currencies->format($adjusted_total); 

희망이 있습니다. 내가이 그렇게 어려운 이유는 확실하지 않다

1

...

내가 위의 코드를 볼 수있는 문제는, 주문 합계에 계산 공제 기능은 계정 제품/카테고리 제한을 고려하지 않는다는 점입니다 쿠폰에 대해 존재할 수 있습니다.

내가 로컬 세금에 추가 할이 사용하고 그리고 난 공제 마련하기 위해 다음 코드를 사용 :

require_once(DIR_WS_MODULES . '/order_total/ot_coupon.php'); 
       $ot_coupon = new ot_coupon; 
       if (isset($order->info['coupon_code'])) { 
        $tax_rate = $taxrec['tax']; //used for coupon removal.... 
        $coupon_total = $ot_coupon->calculate_deductions($_SESSION['cart']->show_total()); 
        $deduction_amount = ($ot_coupon->get_order_total())/(1+($coupon_total['tax']/$coupon_total['total'])); 
        $coupon_tot = $ot_coupon->calculate_deductions($deduction_amount); 
        $tax_reduction_coupon = ($coupon_tot['total'] + $coupon_tot['tax']) * $tax_rate *.01; 
        $tax_total_for_class -= $tax_reduction_coupon; 
        $order->info['tax'] -= $tax_reduction_coupon; 
        $order->info['total'] -= $tax_reduction_coupon; 
       } 

내가 두 번 계산 공제 기능을 사용했다; 멀리 원래의 포스터 질문; 난 대답은 생각 :

($의 coupon_tot [ '총'] + $ coupon_tot [ '세금'])

물론

, 이것은 당신이 모듈 옵션에 대한 설정 플래그를이 방법에 따라 변경 될 수 있습니다 귀하의 상점을위한 구성 ...

희망하는 데 도움이됩니다.

전체 ot_coupon 계산을 다시 수행 할 수 있습니다.이 제안은 제안 된 솔루션보다 훨씬 덜 우아 해 보였습니다.