Configuration file to load custom classes cannot be loaded
-
Thank you very much for your help
I assume this would load a configuration file to load a custom class and method to format the “increment_id” of the “orders” table to be unique, is this correct?
Webkul/Sales/src/Generators/OrderSequencer.php
$this->generatorClass = core()->getConfigData('sales.order_settings.order_number.order_number_generator');
If I create config/sales.php as per this path, it doesn't seem to load.
The cause seems to be “array_shift($fields);” here, is this intended?
bagisto/packages/Webkul/Core/src/Core.php
/** * Get default config. * * @param string $field * @return mixed */ protected function getDefaultConfig($field) { $configFieldInfo = $this->getConfigField($field); $fields = explode('.' , $field); array_shift($fields); $field = implode('.' , $fields); $field = implode('. return Config::get($field, $configFieldInfo['default'] ? null); }
If I remove “array_shift($fields);”, the configuration file is loaded correctly!
Is this safe?Sorry if I'm wrong, it's difficult.
-
Hello @tmss
Kindly let us know which Bagisto you are using right now?
Also, it seems the coding structure you are loading a configuration is not correct kindly provide the configuration file regarding the same.
Thanks & Regards
-
Thank you for confirming.
Related information.Version
Bagisto:v2.1.2
Configuration file
bagisto/config/sales.php
did not exist, so I created it myself
<?php //sales.order_settings.order_number.order_number_generator return [ 'order_settings' => [ 'order_number' => [ 'order_number_generator' => \ApplicationGenerators\CustomOrderNumberGenerator::class, // custom generator class 'order_number_prefix' => 'prefix', // order number prefix 'order_number_length' => 10, // order number length 'order_number_suffix' => '', // order number suffix ], ], ];
Note that it seems to be possible to refer to the configuration file with either of the following.
-
directly using the config() method
-
create bagisto/config/order_settings.php and place it
(Create the file under the assumption that “salse.” will be removed from the path)
<?php //sales.order_settings.order_number.order_number_generator return [ 'order_number' => [ 'order_number_generator' => \ApplicationGenerators\CustomOrderNumberGenerator::class, // custom generator class 'order_number_prefix' => 'prefix', // order number prefix 'order_number_length' => 10, // order number length 'order_number_suffix' => '', // order number suffix ], ];
By the way
Once we confirm that it can be loaded in the main package, we want to create a "Config" folder under the original package and place the configuration file "sales.php" under "Config" in the service provider, changing it to be loaded from there.protected function registerConfig() { $this->mergeConfigFrom( dirname(__DIR__) . '/Config/sales.php',. 'sales'; $this->mergeConfigFrom( dirname(__DIR__ . ); }
-
-
It seems there's some confusion between Laravel configuration and Bagisto configuration. If you check the
system.php
file in the admin package, you'll see all the entries that are used viacore()->getConfigData()
.It appears you are creating configuration entries and registering them via Laravel's config system. I recommend checking the documentation if you want to add configuration correctly in Bagisto.
https://devdocs.bagisto.com/2.1/packages/create-system-configuration.html#create-a-new-configuration
-
@devansh-webkul
Thank you for presenting the documentWe will check here once and ask again if we don't understand.
Thank you very much.If possible, could you please tell me the safest way to make the
increment_id
in theorders
table unique in Bagisto?For example, if I want to change it like this, how can I add and load custom functions in Bagisto?
Target file
bagisto/packages/Webkul/Sales/src/Generators/Sequencer.php
Sample change
Example: Before change
/** * Create and return the next sequence number for e.g. an order. */ public function generate(): string { return $this->prefix.sprintf( "%0{$this->length}d", ($this->lastId + 1) ).($this->suffix); }
Example: After change (I want a unique ID like this)
/** * Create and return the next sequence number for e.g. an order. */ public function generate(): string { return $this->prefix.\Str::uuid().($this->suffix); }
The goal is to use this as one of the keys to retrieve items purchased via guest checkout. Currently, it doesn't work with Bagisto 2.1.2 and Bagisto APIs (REST) 2.0.0, so I'm creating it myself.
I apologize for the inconvenience, but thank you in advance.