shipcloud / shipcloud-for-woocommerce

shipcloud for WooCommerce
GNU General Public License v3.0
6 stars 0 forks source link

Carriers are not being initialized when editing shipping method #200

Open luzat opened 3 years ago

luzat commented 3 years ago

When editing shipping methods, there are none shown: image

The problem seems to be one of the following two, not sure which one:

  1. WC_Shipcloud_Shipping::carriers is only initialized for the settings screen in init_settings_screen and thus is not available in init_settings_fields to in turn initialize $carriers_options for use in instance_form_fields' allowed_carriers field:
    
        $this->instance_form_fields = array(
            'allowed_carriers'                  => array(
                'title'       => __( 'Shipping methods', 'shipcloud-for-woocommerce' ),
                'type'        => 'multi_checkbox',
                'description' => __( 'Select the carriers that you want to use in your shop.', 'shipcloud-for-woocommerce' ),
                'desc_tip'    => true,
                'options'     => $carriers_options
            ),
  2. Alternatively or additionally, could it be that allowed_carriers should actually be initialized from available_carriers here?

Another thing that I noticed is, that WC_Shipcloud_Shipping::init_allowed_carriers does not initialize anything. Isn't it meant to at least assign allowed_carriers to some instance variable? Instead it seems that most methods seem to do this on their own. It's at least a misnomer.

thd-fox commented 3 years ago

Same here! But I face this issue, when initially enter API key on new install.

andrecedik commented 3 years ago

Yes I know. We previously had this update upon entering and saving the form. Unfortunately Wordpress always loads the shipping method (multiple times), resulting in multiple calls to the API, which is unnecessary and can get people to reach their request limits. Therefore you currently have to save your settings one more time after entering the API key for them to be loaded.

thd-fox commented 3 years ago

Unfortunately this "...save your settings one more time after entering the API key..." doesn't work either.

luzat commented 3 years ago

For me, the carriers do display in settings, but not when editing shipping methods, which is because $this->carriers is only initialized in this code path:

if ( wcsc_is_settings_screen() ) {
  if ( ! $this->init_settings_screen() ) {
    return false;
  }
}

Given that shipping methods are not edited on the shipcloud settings screen, $this->carriers is always going to be [].

andrecedik commented 3 years ago

Hmm, ok interesting. Will have to have a look at that.