Promotion activation #4009
Replies: 2 comments 12 replies
-
I don't know the answer TBH, but I'd make an attempt to change the code and see if specs fail. I hope this helps us identify potential issues hidden somewhere in the promotions code. If everything is green, I think we can work on a PR for this. |
Beta Was this translation helpful? Give feedback.
-
Hi, when you say
do you have any links to those discussions? We at Lawbite are building a brand new Rails app, which will need promotion & credits functionality that overlaps to 90% what Solidus promotion engine has on offer. I wonder if you were me, how would you go about building it? Do you know of any gems built solely for that purpose, or good examples ? Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hey there,
I know there is discussion about adding ability to replace the promotion system, but I wanted to discuss the current architecture if it is there to stay.
From what I understand, and please, correct me if I'm wrong, when a line item is added to the cart or has its quantity updated, the PromotionHandler::Cart is activated with the affected line item.
Then, it loops through all active promotions, even the ones that are not currently associated to the order if they are automatically applied, and perform all needed actions.
Once again, as I understand it, the CreateItemAdjustmentAction is the only default action which work on a line item level. But it does not use the line item passed inside the payload it receive, and instead loops on all items associated with the order.
So the big questions : why do we have to pass a line item to the PromotionHandler::Cart object ? Can we avoid the loop and work directly the the line item in the payload ?
I'm asking 'cause we have created a service object to add multiple line items at once, and we're hitting a big performance block inside the cart handler. To talk with numbers :
And that's for an empty cart!
The same modification on an existing cart with 10 other products (the average cart size on our shop is ~25) would call Spree::Promotion#line_item_actionable? ~18k
Another way we can go is by not activating promotions for each line item, but only once for the order, but I don't know if there is any side effect to know about.
That would drastically decrease the work it has to do, but will still be a O(N) according to the cart size, which is way worst than the O(1) we would have if the CreateItemAdjustment could work on the newly added or updated line item only.
What do you think about all this? Are we walking to dead end trying to add multiple product at once? Is it possible to use the payload's line item inside CreateItemAdjustment ?
Beta Was this translation helpful? Give feedback.
All reactions