Bagisto Forum

    Bagisto

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

    Configuration file to load custom classes cannot be loaded

    Bug Report
    3
    5
    393
    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.
    • T
      tmss last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Rishabh-Webkul
        Rishabh-Webkul last edited by Rishabh-Webkul

        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

        1 Reply Last reply Reply Quote 0
        • T
          tmss last edited by tmss

          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.

          1. directly using the config() method

          2. 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__ .
                  );
              }
          
          devansh-webkul 1 Reply Last reply Reply Quote 0
          • devansh-webkul
            devansh-webkul @tmss last edited by

            @tmss,

            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 via core()->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

            T 1 Reply Last reply Reply Quote 0
            • T
              tmss @devansh-webkul last edited by tmss

              @devansh-webkul
              Thank you for presenting the document

              We 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 the orders 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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post