Skip to content

[5.x]: Error viewing a Product in the Control Panel - setting read-only property allVariants #4241

@mike-moreau

Description

@mike-moreau

What happened?

Description

A user has an edited product and attempts to view it. Receives a 500 error - Setting read-only property: craft\commerce\elements\Product::allVariants

The issue fixed in 5.5.3 sounds similar:

But in this case the user is attempting to view a provisional draft.

Image

I'll include the stack trace below. In the short term I resolved it by manually setting provisional to 0 in the database for the record in the craft_drafts table with matching canonicalId.

Steps to reproduce

  1. Edit a product
  2. Attempt to view it

Expected behavior

No error.

Actual behavior

500 error.

Stack Trace:

yii\base\InvalidCallException: Setting read-only property: craft\commerce\elements\Product::allVariants in /var/www/html/vendor/yiisoft/yii2/base/Component.php:223
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/base/Element.php(2668): yii\base\Component->__set('allVariants', Object(craft\commerce\elements\VariantCollection))
#1 /var/www/html/vendor/craftcms/cms/src/base/Element.php(3340): craft\base\Element->__set('allVariants', Object(craft\commerce\elements\VariantCollection))
#2 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1426): craft\base\Element->mergeCanonicalChanges()
#3 [internal function]: craft\services\Elements->craft\services{closure}(Object(craft\db\Connection))
#4 /var/www/html/vendor/yiisoft/yii2/db/Connection.php(822): call_user_func(Object(Closure), Object(craft\db\Connection))
#5 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1407): yii\db\Connection->transaction(Object(Closure))
#6 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1254): craft\services\Elements->craft\services{closure}()
#7 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1406): craft\services\Elements->ensureBulkOp(Object(Closure))
#8 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(299): craft\services\Elements->mergeCanonicalChanges(Object(craft\commerce\elements\Product))
#9 [internal function]: craft\controllers\ElementsController->actionEdit(Object(craft\commerce\elements\Product), 1220252)
#10 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(66): call_user_func_array(Array, Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(197): yii\base\InlineAction->runWithParams(Array)
#12 /var/www/html/vendor/yiisoft/yii2/base/Module.php(554): yii\base\Controller->runAction('edit', Array)
#13 /var/www/html/vendor/craftcms/cms/src/web/Application.php(370): yii\base\Module->runAction('elements/edit', Array)
#14 /var/www/html/vendor/yiisoft/yii2/web/Application.php(112): craft\web\Application->runAction('elements/edit', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/Application.php(338): yii\web\Application->handleRequest(Object(craft\web\Request))
#16 /var/www/html/vendor/yiisoft/yii2/base/Application.php(391): craft\web\Application->handleRequest(Object(craft\web\Request))
#17 /var/www/html/public/index.php(12): yii\base\Application->run()
#18 {main}

Craft CMS version

5.9.12

Craft Commerce version

5.5.4

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions