Prestashop 订单结帐送货国家 ID

Prestashop order-checkout shipping country id

我的网店使用的是 Prestashop 1.6。我开始进行一些升级。 现在我在获取客户送货地址的国家/地区名称时遇到了问题。

有人知道我在第 4 步 ("Shipping") 时如何从订单结帐的第 3 步(地址)获取国家/地区名称吗?

这种信息放在什么变量($cart ->…)中?

我开始改单-carrier.tpl加 <input type="hidden" value="{$cart->id_address_delivery}"/> 结果是我得到了一些数字。我没有找到这个数字指向什么的信息。

<div class="delivery_option_price">
<input type="hidden" value="{$cart->id_address_delivery}"/>
{if $option.total_price_with_tax && !$option.is_free && (!isset($free_shipping) || (isset($free_shipping) && !$free_shipping))}
    {if $use_taxes == 1}
        {if $priceDisplay == 1}
            {convertPrice price=$option.total_price_without_tax}{if $display_tax_label} {l s='(tax excl.)'}{/if}
        {else}
            {convertPrice price=$option.total_price_with_tax}{if $display_tax_label} {l s='(tax incl.)'}{/if}
        {/if}
    {else}
        {convertPrice price=$option.total_price_without_tax}
    {/if}
{else}
    {l s='Free'}

谢谢

默认情况下,出于性能目的,Prestashop 不会在会话中保留整个客户地址,但它会使用 $cart->id_address_delivery 和 $cart->id_address_invoice 属性保留引用。 这两个属性将具有保存在 ps_address table,所以如果你想检索一个地址的所有信息,你所要做的就是用给定的 id 创建一个 new Address() 对象。 我们应该在 Controller 中执行此操作,准确地说是执行结帐功能的 ParentOrderController,我们正在寻找的函数应该是 _assignCarrier()。 (Please remember to extend the controller functionality with the override feature Prestashop offers, to avoid un-upgradable code.)

在 _assignCarrier() 函数中,我们将创建我们的地址对象,然后通过以下方式获取国家/地区名称:

//create an address object by retrieving the id from the current cart.
$address = new Address($this->context->cart->id_address_delivery);
//now the country name will now be in the "$address->country" field so if you want to pass it to your smarty template use:
$this->context->smarty->assign('country_name', $address->country);

我们终于让我们的国家名称可用于我们的模板,所以我们只需要显示它,您在模板中的代码变为:

<div class="delivery_option_price">
<input type="hidden" value="{$country_name}"/>