craftcms / commerce

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

[3.x]: yii\base\InvalidConfigException: Invalid product ID when saving product after disabling a site #3079

Closed JodebaDigitalPulse closed 1 year ago

JodebaDigitalPulse commented 1 year ago

What happened?

Description

yii\base\InvalidConfigException: Invalid product ID: when saving a product (via CP or other ways)

In the database I see content-rows for each site (enabled+disabled) for the variants, while there are only content-rows for products for each enabled site.

Steps to reproduce

  1. Create a product with multiple sites enabled
  2. Disable a few site
  3. ... something in the past introduced variants for each site, but not products
  4. Save product

Expected behavior

Save only variants for enabled sites, or create a row in content-table for each product despite disabled site

Actual behavior

Tries to save a variant for the disabled site and can't find a product for that site.

Stack trace

2023-02-02 09:22:24 [-][251734][ulqr53sqs0334vv6eoo2m25pge][error][yii\base\InvalidConfigException] yii\base\InvalidConfigException: Invalid product ID: 33804 in C:\www\project\vendor\craftcms\commerce\src\elements\Variant.php:435
Stack trace:
#0 C:\www\project\vendor\craftcms\commerce\src\elements\Variant.php(1160): craft\commerce\elements\Variant->getProduct()
#1 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(2527): craft\commerce\elements\Variant->beforeSave(false)
#2 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(2980): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Variant), true, false, NULL, Array)
#3 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(2759): craft\services\Elements->_propagateElement(Object(craft\commerce\elements\Variant), Array, 8, Object(craft\commerce\elements\Variant))
#4 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(785): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Variant), false, true, true)
#5 C:\www\project\vendor\craftcms\commerce\src\elements\Product.php(822): craft\services\Elements->saveElement(Object(craft\commerce\elements\Variant), false)
#6 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(2728): craft\commerce\elements\Product->afterSave(false)
#7 C:\www\project\vendor\craftcms\cms\src\services\Elements.php(785): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Product), true, true, true)
#8 C:\www\project\vendor\craftcms\commerce\src\controllers\ProductsController.php(301): craft\services\Elements->saveElement(Object(craft\commerce\elements\Product))
#9 [internal function]: craft\commerce\controllers\ProductsController->actionSaveProduct(false)
#10 C:\www\project\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#11 C:\www\project\vendor\yiisoft\yii2\base\Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#12 C:\www\project\vendor\yiisoft\yii2\base\Module.php(552): yii\base\Controller->runAction('save-product', Array)
#13 C:\www\project\vendor\craftcms\cms\src\web\Application.php(293): yii\base\Module->runAction('commerce/produc...', Array)
#14 C:\www\project\vendor\craftcms\cms\src\web\Application.php(602): craft\web\Application->runAction('commerce/produc...', Array)
#15 C:\www\project\vendor\craftcms\cms\src\web\Application.php(272): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#16 C:\www\project\vendor\yiisoft\yii2\base\Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#17 C:\www\project\web\index.php(22): yii\base\Application->run()
#18 {main}

Craft CMS version

3.7.63.1

Craft Commerce version

3.4.19

PHP version

7.4

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

lukeholder commented 1 year ago

This should be fixed in 4.2.5, just run php craft resave/products after upgrading.