2014-12-19 2 views
0

SimpleCartjs의 장바구니에서 모든 데이터를 전자 메일로 보내려고합니다. 기본적으로 나는 그의 주문을 확인하기 위해 고객의 이메일에 그것을 보내는 것을 선호합니다. 그래서 지금은 제대로 작동하고 있지만, grandTotal은 모든 것을 합한 것입니다 (비용 + 세금 + 배송비). 나는 그것을 화면에 표시 할 수 있지만 우편으로 보내면 grandTotal은 보내지 않을 것입니다. 어떤 아이디어? 지금까지 제 코드가 있습니다. 몸 필드의 끝에서 grandTotal는있다, 그러나 나는 그 값을 얻는 방법을 잘 모릅니다 :simpleCartjs에서 grandTotal 값을 보내는 방법

$send = $_GET['send']; 
$to = '[email protected]'; 
$subject = 'Your Tea shopping Cart'; 
$content = $_POST; 
$body = ''; 

for($i=1; $i < $content['itemCount'] + 1; $i++) { 
    $name = 'item_name_'.$i; 
    $quantity = 'item_quantity_'.$i; 
    $price = 'item_price_'.$i; 
    $tax = $_POST['taxRate']; 
    $ship = $_POST['shipping']; 
    $total = $content[$quantity]*$content[$price]; 
    $iva = $content[$price]*$tax; 
    $subtotal = $total + $ship + $iva; 

    $body .= 'item #'.$i.':'; 
    $body .= $content[$name].'<br>'; 
    $body .= $content[$quantity].'Un.: '.$content[$price].'Euros<br>'; 
    $body .= 'IVA : '.$content[$price]*$tax.'Euros<br>'; 
    $body .= 'Shipping: '. $ship.'Euros<br>'; 
    $body .= 'Total: '.$subtotal.'Euros<br>'; 
    $body .= '------------------------------------<br>';  
}; 
$body .= 'Total: '.$grandTotal; 

$headers = 'From: [email protected]' . "\r\n" . 
      'Reply-To: [email protected]' . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

mail($to, $subject, $body, $headers); 
+0

세금 계산이 잘못되었습니다. 그것은 TAX = PRICE * QUANTITY * TAXRATE 여야합니다. TAX가 아닌 PRICE * TAXRATE. – swbandit

+0

'$ grandTotal'은 어디에서 초기화 되었습니까? 아니면'$ content [ 'grandTotal]'을 의미합니까? –

답변

0

먼저가에 대한 루프 전에 $grandTotal = 0;를 초기화합니다. 그런 다음 for-loop 내부에서 부분합을 계산 한 후 다음을 추가하십시오. $grandTotal = $grandTotal + $subTotal;