Shipping method not appear in admin page
-
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/RajaOngkirHowever, the shipping method does not appear in the configure tab.
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
-
sorry wrong link
the documentation that i use is
https://devdocs.bagisto.com/2.3/advanced/create-shipping-method.html#introductioni 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
-
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" } }
- more square brackets covering the return value in Config/system.php