craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[5.x]: Attempt to read property "id" on null (ShippingCategories.php) #3530

Closed sunscreem closed 1 month ago

sunscreem commented 1 month ago

What happened?

Description

I've just upgraded from commerce 4 to 5.

When I go into commerce > settings > product types in the control panel I get the following error:

image

I had a little look into the source here:

https://github.com/craftcms/commerce/blob/de024cac7190284c4c94c3db63084f81a34b9362/src/services/ShippingCategories.php#L296C1-L305C65

It looks like the code is looking for a shipping category with a default value.

If I manually add:

$shippingCategory = $this->getAllShippingCategories()->first();

The problem goes away.

I'm guessing somewhere on the journey from Commerce 2 a default hasn't been set?

Happy to send over my DB if its needed to recreate the issue.

Craft CMS version

5.1.7

Craft Commerce version

5.x-dev

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 1 month ago

PT-1778 [5.x]: Attempt to read property "id" on null (ShippingCategories.php)

sunscreem commented 1 month ago

After working with Craft support on this, somewhere along the line my shipping methods had no default set. You can correct this in Commerce > Store Management > Shipping Categories > General. You'll maybe need to create a new one to get this all working.