Prestashop 运费取决于国家

Prestashop shipping cost depending of country

我正在努力升级我在 Prestashop 上的电子商店。 我想根据要发送的国家/地区编辑运费(承运人)。理论上我想在后台设置 delivery = 1 的价格,然后在代码中根据 country/weight 或其他选项编辑它。

我想我找到了获取运费的功能。这是 getTotalShippingCost 或者这是 getOrderTotal 如果我错了请告诉我。

此时如何在 getOrderTotal 中获取交货的国家/地区名称?

if ($type == Cart::ONLY_SHIPPING)
return $shipping_fees;

或者如果在这个订单上没有地址是不能得到的,请告诉这是在哪里做的。在 ParentOrderController.php 或 PaymentModule.php 或其他地方?

如何管理 shipping/carriers 您可以在 Prestashop documentation 中阅读,并在不使用外部模块的情况下获取每个国家/地区的运费(默认使用 Presta 'zones'),您可以创建为每个国家/地区设置区域,并为每个新区域设置运费。所有这些操作都可以从后台完成,无需核心更改。

但是如果您决定在代码中这样做,请记住直接更改核心文件被认为是不好的做法;最好使用 built-in capabilities.

$shippingCostTaxExc can be found in _assignSummaryInformations method in /controllers/front/ParentOrderController.php file. 

$option array in /classes/Cart.php

更新: 您可以从任何 model/controllers 类、using Context object 访问一些常见对象,如货币、Cookie 等和国家/地区,因此在您的情况下,如果您需要国家/地区名称,它看起来像这样:

$context = Context::getContext();
$context->country->name[1]; // for language with id=1
$context->language->id; // if you need to get actual customer language