如果满足 X,则增加购物车成本

发布于 2024-11-05 03:15:42 字数 414 浏览 5 评论 0原文

因此,我们在使用基于愚蠢的物品/产品的运输时遇到了问题,又名 用户将产品添加到购物车 (FedEx/USPS) 并添加费用 到运输。如果购物车中有 X 件商品,则费率会增加 通过信封运送的产品 通过盒子运送。这 需额外支付 20 美元服务费。我想附加一个额外的 如果满足 X 件商品,购物车费用为 20 美元,但添加此商品时遇到问题 到会话信息(并保留它)。使用这段代码,我可以添加 额外的运费:

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

这不会反映在我当前的购物车模块/侧栏中 不过价格。帮助将不胜感激!

So we have an issue with using a silly item/product based shipping, aka
the user adds a product to the cart (FedEx/USPS) and the cost is added
to shipping. If X amount of items are in teh cart, the rate increases due
to products being shipped via envelope to being shipped via box. This
incurs an additional 20$ service charge. I would like to append an additional
20$ to cart costs if X items are met, but am having an issue with adding this
to the session information (and having it stick). Using this code, I can add
an additional cost to shipping:

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

This does not reflect in my shopping cart module/sidebar with he current
price though. Help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-11-12 03:15:42

在这些行之前的脚本中是否有“session_start()”?

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

另外,您可能不想将其正确计入总数。我将其放入与运输相关的变量中,并将其添加到运行总计中。这样,如果您已经添加过一次,就可以确保不会再次添加!喜欢:

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

另外... # 已弃用,请使用 // 或 /* !

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 /* !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文