在 prestashop 1.7 中,我使用了 API(freightquote)来获取可用的承运人/运输提供商。在CheckoutDeliveryStep.php
课堂上我写了以下内容
$carrierOptionsArr = array( );
if(!($xml===false) && $xml->children("soap" , true)->count() ){
$GetRatingEngineQuoteResponse = $xml->children("soap" , true)->Body->children()->GetRatingEngineQuoteResponse;
$errorsList = $GetRatingEngineQuoteResponse->children()->GetRatingEngineQuoteResult->children()->ValidationErrors->children();
foreach ($errorsList->B2BError as $key => $value) {
# code...
echo "".$value->children()->ErrorMessage."<br>";
}
$carrierOptions = $GetRatingEngineQuoteResponse->children()->GetRatingEngineQuoteResult->children()->QuoteCarrierOptions;
foreach ($carrierOptions->children() as $key => $value) {
//Carrier option id
$carrier = array();
$carrier["id"] = "".$value->children()->CarrierOptionId;
//CArrier Name
$carrier["name"] = "".$value->children()->CarrierName;
//Quote Amount
$carrier["amount"] = "".$value->children()->QuoteAmount;
$carrierOptionsArr[] = $carrier;
}
}
return $carrierOptionsArr;
并在这个函数中渲染
public function render(array $extraParams = array())
{
return $this->renderTemplate(
$this->getTemplate(),
$extraParams,
array(
'hookDisplayBeforeCarrier' => Hook::exec('displayBeforeCarrier', array('cart' => $this->getCheckoutSession()->getCart())),
'hookDisplayAfterCarrier' => Hook::exec('displayAfterCarrier', array('cart' => $this->getCheckoutSession()->getCart())),
'id_address' => $this->getCheckoutSession()->getIdAddressDelivery(),
'delivery_options' => $this->getCheckoutSession()->getDeliveryOptions(),
'delivery_option' => $this->getCheckoutSession()->getSelectedDeliveryOption(),
'recyclable' => $this->getCheckoutSession()->isRecyclable(),
'recyclablePackAllowed' => $this->isRecyclablePackAllowed(),
'delivery_message' => $this->getCheckoutSession()->getMessage(),
'gift' => array(
'allowed' => $this->isGiftAllowed(),
'isGift' => $this->getCheckoutSession()->getGift()['isGift'],
'label' => $this->getTranslator()->trans(
'I would like my order to be gift wrapped %cost%',
array('%cost%' => $this->getGiftCostForLabel()),
'Shop.Theme.Checkout'
),
'message' => $this->getCheckoutSession()->getGift()['message']
),
'options' => $this->getCarriers()
)
);
}
它在订单控制器页面上显示承运人列表。但是选择该项目不会更新或被选为承运人。从 prestashop 管理后端添加的运营商在运营商列表中运行良好。如何将自定义承运人绑定到购物车订单作为常规结账流程?谢谢