簡體   English   中英

在 prestashop 1.7 上呈現承運人/運輸清單並與訂單綁定以進行定制運輸

[英]Render carrier/shipping list and binding with order for custom shipping on prestashop 1.7

在 prestashop 1.7 中,我使用了 API (freightquote) 來獲取可用的承運人/運輸提供商。 CheckoutDeliveryStep.php class 我寫了以下

$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;

並在此 function 中渲染

 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()

            )
        );
    }

它顯示了訂單 controller 頁面上的運營商列表。 但是選擇該項目不會更新或被選為承運人。 從 prestashop 管理后端添加的運營商在運營商列表中運行良好。 如何將自定義承運人綁定到購物車訂單作為常規結賬流程? 謝謝

您應該創建自己的模塊,該模塊將擴展CarrierModule並使用您的自定義邏輯在其中實現方法getOrderShippingCostgetOrderShippingCostExternal 你可以在這里閱讀更多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM