doucheng1063 2014-12-19 13:36 采纳率: 100%
浏览 46

如何在simpleCart js中邮寄grand total值

I'm trying to send all data from the shopping cart in SimpleCartjs to an email. Basically I prefer to send it to a clients email for confirmation of his order. So for now I got it working, but I cannot seem to send the grandTotal, which is the sum of everything (cost + Tax + Shipping). I am able to echo it to the screen, but when mailing it the grandTotal will not send. Any ideas? here is my code so far. The grandTotal in the end of the body field is just there, But I dont know how to get its value:

 $send = $_GET['send'];
 $to = 'name@myname.com';
 $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: name@myname.com' . "
" .
            'Reply-To: name@myname.com' . "
" .
            'X-Mailer: PHP/' . phpversion();
 $headers .= "MIME-Version: 1.0
";
 $headers .= "Content-Type: text/html; charset=ISO-8859-1
";

 mail($to, $subject, $body, $headers);
  • 写回答

1条回答 默认 最新

  • doujing2017 2014-12-20 01:54
    关注

    First initialize $grandTotal = 0; before the for-loop. Then, inside the for-loop, after calculating the subtotal, add $grandTotal = $grandTotal + $subTotal;

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测