Recent Topics

Create Custom Shipping Method - Not Showing in Admin Dashboard



  • Hello,

    So I have created the custom shipping method using Bagisto Package Generator with command "php artisan package:make-shipping-method ACME/DHL"

    also have done this command "php artisan package:make-shipping-method ACME/DHL --force"

    I can see files are generated under packages/ACME folder.
    I have done clear config, cache and dump-autoload too.

    But I still cannot see the shipping method in the Admin dashboard. Anything I missed out?

    Thanks!



  • How about this? do you have any idea what is happening? @Vaishali-Agarwal



  • Hi @rudiculous,

    Did you register your custom provider in the config/app.php andcomposer.json file?



  • Thanks @devansh-webkul for the response.
    I have resolved this issue. But I have one more question to ask.

    So in my custom shipping method file /packages/ACME/DHL/src/Carriers/DHL.php

    public function calculate()
        {
            if (! $this->isAvailable()) {
                return false;
            }
            //I want to calculate the shipping fee here by calling some of my api provider
            //how I can get the current address from the form that the customer filled up, so I can get the city, postal code, etc?
            //I also need the total weigh of the cart, how to get that from this function?
            // so eventually i can override the object price before return $object->price
    
            $object = new CartShippingRate;
            $object->carrier = 'dhl';
            $object->carrier_title = $this->getConfigData('title');
            $object->method = 'dhl_dhl';
            $object->method_title = $this->getConfigData('title');
            $object->method_description = $this->getConfigData('description');
            $object->price = 0;
            $object->base_price = 0;
    
            return $object;
        }
    


  • Customer address will save in the cart. You can fetch from it.



  • @devansh-webkul how to fetch? what function or variable I can use to fetch it?



  • Grab the cart based on the customer. You can use the Cart facade or helper. Fore e.g.,
    Cart::getCart() or cart()->getCart()

    This will give you the current customer's cart. Now from here rest is mattered the relationships. Just go thorught your cart model and check the relationshiop.



  • @devansh-webkul Okay thank you. I will try with this.


Log in to reply