Skip to content

[5.x]: qty in populateLineItem event is always 1 #3883

@jornwildenbeest

Description

@jornwildenbeest

What happened?

Description

Not sure if this is a bug or just changed in Craft Commerce 5.

But the qty in the populateLineItem event (https://craftcms.com/docs/commerce/5.x/extend/events.html#populatelineitem) is always 1.
We used the populateLineItem to calculate a new salePrice depending on how many items the customer bought.

Since updating from Craft 3 tot Craft 5 I've noticed that this new salePrice is wrong, so after a little investigating I found out that the qty in the event is always 1.

Probably because the default is set to 1: https://github.com/craftcms/commerce/blob/5.3.1/src/services/LineItems.php#L432

If this is just changed and not a bug anymore, which event do we need to use to calculate a new salePrice depending on custom Logic?

Steps to reproduce

  1. Add the populateLineItem in a module and log the qty.
  2. Add a product to the cart with qty higher then.
  3. The log shows that the qty is always 1, even when you add for example 5 products.

Expected behavior

The qty in the populateLineItem is greater then 1.

Actual behavior

The log shows that the qty is always 1, even when you add for example 5 products.

Craft CMS version

5.6.4

Craft Commerce version

5.3.1

PHP version

8.3

Operating system and version

Mac os

Database type and version

Mysql 8

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions