0

因此,我们在使用基于愚蠢商品/产品的运输时遇到了问题,即用户将产品添加到购物车 (FedEx/USPS) 并将成本添加到运输中。如果购物车中有 X 数量的物品,由于产品是通过信封运输到通过盒子运输,因此费率会增加。这会产生额外的 20 美元服务费。如果满足 X 个项目,我想在购物车成本中追加 20 美元,但在将其添加到会话信息(并坚持下去)时遇到问题。使用此代码,我可以增加运费:

    # %install_dir%/catalog/checkout_shipping.php
    $_SESSION['cart']->total = $_SESSION['cart']->total + 20;
    var_export($cart);

不过,这并没有反映在我的购物车模块/侧边栏中,但他目前的价格。帮助将不胜感激!

4

1 回答 1

1

Is there a "session_start()" somewhere in this script prior to these lines?

session_start();
$_SESSION['cart']->total += 20;

Also, you might not want to put it right in the total. I'd put it in a shipping related variable, as well as add it to the running total. That way you can make sure you don't add it again if you've already done it once! Like:

session_start();
if (!$_SESSION['cart']->shipping_extra) {
  $_SESSION['cart']->shipping_extra = true;
  $_SESSION['cart']->total += 20;
}

Also... # is deprecated, use // or /* !

于 2011-05-04T20:03:04.483 回答