Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x/4.x]: 'Qty must be no less than 1.' reported twice for low quantity #3334

Closed
msbit opened this issue Nov 11, 2023 · 1 comment
Closed
Labels
bug commerce3 Issues related to Commerce v3

Comments

@msbit
Copy link
Contributor

msbit commented Nov 11, 2023

What happened?

Description

Due to the rule being applied in two places:

LineItem::defineRules
https://github.com/craftcms/commerce/blob/3.4.23/src/models/LineItem.php#L465
https://github.com/craftcms/commerce/blob/4.3.2/src/models/LineItem.php#L420

Variant::getLineItemRules()
https://github.com/craftcms/commerce/blob/3.4.23/src/elements/Variant.php#L820
https://github.com/craftcms/commerce/blob/4.3.2/src/elements/Variant.php#L826

at validation time, the error is added twice.

I haven't tested the 4.x branch, but the code appears to be the same.

Steps to reproduce

$lineItem = new \craft\commerce\models\LineItem([
    'purchasableId' => Craft::$app->getElements()->createElementQuery(\craft\commerce\elements\Variant::class)->scalar(),
    'qty' => 0,
]);
$lineItem->validate();
var_dump($lineItem->getErrors('qty'));

Expected behavior

array(1) {
  [0] =>
  string(27) "Qty must be no less than 1."
}

Actual behavior

array(2) {
  [0] =>
  string(27) "Qty must be no less than 1."
  [1] =>
  string(27) "Qty must be no less than 1."
}

Craft CMS version

"craftcms/cms": "3.9.5"

Craft Commerce version

"craftcms/commerce": "3.4.23"

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@msbit msbit added commerce3 Issues related to Commerce v3 bug labels Nov 11, 2023
@lukeholder
Copy link
Member

lukeholder commented Nov 13, 2023

Thanks for reporting that! I’ve just fixed it for the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "dev-develop#ad6803123e4dbe5127fb7780a9ed650dda27ac29",
  "...": "..."
}

Then run composer update.

We will update you here once the release is out. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce3 Issues related to Commerce v3
Projects
None yet
Development

No branches or pull requests

2 participants