Skip to content

[5.x]: Discounts: Can't select a variant for the "Only match certain purchasables…" field that is related to a Product Type that is not enabled on the "first" site. #4059

Open
@jesuismaxime

Description

@jesuismaxime

What happened?

Description

Can't select a variant on "Only match certain purchasables…" field that is related to a Product Type that is not enabled on the "first" sites.

More context: The variant i am selecting belongs to a Product Type that is not enabled on all sites (3rd and 4th and not on the 1st and 2nd) of my setup. Since the Discounts has no "sites" concept (at least to relation to a site), the element returns null because it does not belong to the "first" site. On the other hand, if I choose a product that belongs to all sites, the discount is saved properly.

Steps to reproduce

  1. Create a discount that will match certain purchasable which belongs to a Product Type that is not enabled on the first site
  2. Save the discount

Expected behavior

Be saved properly with the variant(s) in the relation field

Actual behavior

Throw the error bellow:

TypeError: Cannot use "::class" on value of type null in /var/www/html/cms/vendor/craftcms/commerce/src/services/Discounts.php:868
Stack trace:
#0 /var/www/html/cms/vendor/craftcms/commerce/src/controllers/DiscountsController.php(350): craft\commerce\services\Discounts->saveDiscount(Object(craft\commerce\models\Discount))
#1 [internal function]: craft\commerce\controllers\DiscountsController->actionSave()
#2 /var/www/html/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /var/www/html/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#4 /var/www/html/cms/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('save', Array)
#5 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module->runAction('commerce/discou...', Array)
#6 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application->runAction('commerce/discou...', Array)
#7 /var/www/html/cms/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#8 /var/www/html/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 /var/www/html/web/index.php(13): yii\base\Application->run()
#10 {main}

Craft CMS version

5.7.10

Craft Commerce version

5.7.0

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