You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@jornwildenbeest Thanks for reporting this. I have made a PR with some fixes to address the issues you were seeing. I will update you once it's in a release. Thanks!
@jornwildenbeest We have decided to make that PR referenced above a part of larger changes we will be making in the next minor release (5.4) - including possible deprecations of those methods that need refactoring.
In the meantime, we think that it would be more accurate for you to use the
craft\commerce\elements\Order::EVENT_BEFORE_LINE_ITEMS_REFRESHED and \craft\commerce\elements\Order::EVENT_AFTER_LINE_ITEMS_REFRESHED events.
These events will be called when the order recalculates, and will have the correct qty when those events are triggered. You can still manipulate the line item the same as LineItems::EVENT_POPULATE_LINE_ITEM.
We will look to improve the upgrade guide to recommend these new events.
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
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
The text was updated successfully, but these errors were encountered: