Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Shipping method not appear in admin page

    General Discussion
    1
    3
    35
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      beabay last edited by beabay

      I have added the shipping method as described in this documentation:
      https://devdocs.bagisto.com/12.x/advanced/create-shipping-method.html
      this folder is generated after I use:
      php artisan package:make-shipping-method Webkul/RajaOngkir

      Screenshot_8.png

      However, the shipping method does not appear in the configure tab.

      Screenshot_9.png

      This is the code that was automatically generated from the documentation.

      // Carriers/RajaOngkir.php
      <?php
      
      namespace Webkul\RajaOngkir\Carriers;
      
      use Webkul\Shipping\Carriers\AbstractShipping;
      use Webkul\Checkout\Models\CartShippingRate;
      
      class RajaOngkir extends AbstractShipping
      {
          /**
           * Shipping method code
           *
           * @var string
           */
          protected $code  = 'rajaongkir';
      
          /**
           * Returns rate for shipping method
           *
           * @return CartShippingRate|false
           */
          public function calculate()
          {
              if (! $this->isAvailable()) {
                  return false;
              }
      
              $object = new CartShippingRate;
      
              $object->carrier = 'rajaongkir';
              $object->carrier_title = $this->getConfigData('title');
              $object->method = 'rajaongkir_rajaongkir';
              $object->method_title = $this->getConfigData('title');
              $object->method_description = $this->getConfigData('description');
              $object->price = 0;
              $object->base_price = 0;
      
              return $object;
          }
      }
      
      // Config/carriers.php
      <?php
      
      return [
          'rajaongkir' => [
              'code'         => 'rajaongkir',
              'title'        => 'RajaOngkir',
              'description'  => 'RajaOngkir',
              'active'       => true,
              'default_rate' => '10',
              'type'         => 'per_unit',
              'class'        => 'Webkul\RajaOngkir\Carriers\RajaOngkir',
          ],
      ];
      
      // Config/system.php
      <?php
      
      return [
          [
              'key'    => 'sales.carriers.rajaongkir',
              'name'   => 'RajaOngkir',
              'sort'   => 1,
              'fields' => [
                  [
                      'name'          => 'title',
                      'title'         => 'admin::app.admin.system.title',
                      'type'          => 'text',
                      'validation'    => 'required',
                      'channel_based' => false,
                      'locale_based'  => true,
                  ], [
                      'name'          => 'description',
                      'title'         => 'admin::app.admin.system.description',
                      'type'          => 'textarea',
                      'channel_based' => false,
                      'locale_based'  => true,
                  ], [
                      'name'          => 'active',
                      'title'         => 'admin::app.admin.system.status',
                      'type'          => 'boolean',
                      'validation'    => 'required',
                      'channel_based' => false,
                      'locale_based'  => true,
                  ]
              ]
          ]
      ];
      
      // RajaOngkirServiceProviders.php
      <?php
      
      namespace Webkul\RajaOngkir\Providers;
      
      use Illuminate\Support\ServiceProvider;
      
      class RajaOngkirServiceProvider extends ServiceProvider
      {
          /**
           * Bootstrap services.
           *
           * @return void
           */
          public function boot()
          {
          }
      
          /**
           * Register services.
           *
           * @return void
           */
          public function register()
          {
              $this->registerConfig();
          }
          
          /**
           * Register package config.
           *
           * @return void
           */
          protected function registerConfig()
          {
              $this->mergeConfigFrom(
                  dirname(__DIR__) . '/Config/carriers.php', 'carriers'
              );
      
              $this->mergeConfigFrom(
                  dirname(__DIR__) . '/Config/system.php', 'core'
              );
          }
      }
      
      

      i already add namespace in composer.json and register the service provider in Config\app.php

      1 Reply Last reply Reply Quote 0
      • B
        beabay last edited by beabay

        sorry wrong link
        the documentation that i use is
        https://devdocs.bagisto.com/2.3/advanced/create-shipping-method.html#introduction

        i tried to redo with the manual step and now i got this error

        Cannot access offset of type string on string
        

        i don't know where is it from

        1 Reply Last reply Reply Quote 0
        • B
          beabay last edited by

          i already solve it!

          If you want the code to work, you have to add

          • more square brackets covering the return value in Config/system.php
            before :
          return 
          [
              'key'=>'blablabla'
              // other keys => values
          ]
          

          after

          return 
          [
               [
                'key'=>'blablabla'
                 // other keys => values
               ]
          ]
          
          • 'info' key in Config/system.php
            before :
          'key'    => 'sales.carriers.raja_ongkir',
          'name'   => 'admin::app.configuration.index.sales.shipping-methods.raja-ongkir-shipping.page-title',
          'sort'   => 2,
          'fields' => [
          // field keys => values
          ]
          

          after

          'key'    => 'sales.carriers.raja_ongkir',
          'name'   => 'admin::app.configuration.index.sales.shipping-methods.raja-ongkir-shipping.page-title',
          'info'   => 'admin::app.configuration.index.sales.shipping-methods.raja-ongkir-shipping.title-info',
          'sort'   => 2,
          'fields' => [
          

          and dont forget to add the service provider in providers.php and add the namespaces to composer.json (from documentation)

          "autoload": {
              ...
              "psr-4": {
                  // Other PSR-4 namespaces
                  "Webkul\\CustomShippingMethod\\": "packages/Webkul/CustomShippingMethod/src"
              }
          }
          
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post