Jump to content

Render carrier list and binding with order for custom shipping on prestashop 1.7


M. Rahi

Recommended Posts

In prestashop 1.7 i have used an API (freightquote) to fetch the available carrier/shipping providers. On CheckoutDeliveryStep.php class i have

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

And rendered in this 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()

            )
        );
    }

It is showing the list of carriers at order controller page. But selecting the item doesn't update or being selected as the carrier. The carrier added from prestashop admin back-end is working fine here in the list of carriers. How can i enable the custom carriers? Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...