verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

Set 'Shipping Category Conditions' for a service in postie.php file #115

Closed sjcallender closed 1 month ago

sjcallender commented 9 months ago

Question

Is it possible to set the values for a service's 'Shipping Category Conditions' values in the config/postie.php file?

It appears not. Since we need specific rules, we're unable to use the services config at all as it sets each category condition to "Allow."

Additional context

We have this our config/postie.php file...

                'services' => [
                    'S_AIR_1DAY' => 'UPS Next Day Air (Overnight)',
                    'S_AIR_2DAY' => 'UPS Second Day Air (in 2 Days)',
                    'S_3DAYSELECT' => 'UPS Three-Day Select (in 3 Days)',
                    'S_GROUND' => 'UPS Ground (1-5 Days)'
                ]

In the CP, the result is...

Markup 2023-09-19 at 21 19 58

...where we can't set a condition to "Disallow."

We have to remove the services config in order to achieve the following...

Markup 2023-09-19 at 21 22 08

We'd like to be able to define all this in the config file if possible.

engram-design commented 9 months ago

You can if you like! You just need to alter your syntax.

'services' => [
    'S_GROUND' => [
        'enabled' => true,
        'name' => 'UPS Ground (1-5 Days)',
        'shippingCategories' => [
            1 => [
                'condition' => 'disallow',
            ],
        ],
    ],
],

Note that the array index 1 in this case refers to your Shipping Category ID, not just the array index.