Is it possible to reset the quote with all calculated discounts?
Hey together π
I developed a console command, which is calculating discount percentages for all existing products with given cart rules. At first, I created a big quote and added each concrete product separately as cart item. After that, I'm calling the discount facade, pass the quote and let it calculate all discounts.
After that, I have the discount amount at the cart items and can store them for frontend usage.
But I have one issue now. During calculation of all discounts for all cart items in the quote, Spryker has a really good calculation logic and is remembering the rounding error of each cart item. And if this rounding error sum up is big enough, it will be calculated to the next best item.
I thought, I can solve it with looping through the products and create each time a new quote and add just 1 product and calculate the discount. But this is not working, because there is a kind of caching or I don't know what.
To solve this, I have to run the command for all products separately. It has to be a new php task. And this is much slower than before.
An other solution would be, to have a look, how I can prevent the rounding error sum up calculation during that command. With that, I could use my super big quote again.
Perhaps someone has an idea, how I can solve that issue, because the command is now running instead of a few seconds, 20min π
Answers
-
fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,052 βοΈ - Guardians (admin)
Heyhey @dominik.marx ,
did you find a solution yet?
How do you create the quote? - I want to understand what is caching and how you could may overrule that :)
All the best,
Florian
0 -
Hey @fsmeier ,
Our solution is still to run the command each time with one SKU :-(
I had no time to invest more to solve that issue. The command is running now ~30min for ~3.700 products.I have a small private function to create the quote:
private function createQuote(ItemTransfer $itemTransfer): QuoteTransfer { $itemTransfer->setQuantity(1); return (new QuoteTransfer()) ->setStore((new StoreTransfer())->setName(self::DEFAULT_STORE)) ->setPriceMode(PriceConfig::PRICE_MODE_GROSS) ->addItem((new ItemTransfer())->fromArray($itemTransfer->toArray())); }
If I would add all products here, it would just need 1-2min, but then I have the rounding error on some products.
I also thought, that I could try to deactivate the rounding calculation. But I didn't try it.
But it would help, if I could just do a foreach.. create quote.. add 1 item. β repeat instead of running the whole command new as a separate php-process. This is consuming the most time.
But yes, if you have an idea, how to reset the quote, this would be enough. Because, it's remembering somehow something that the calculation is not correct, if I run it with a foreach loop with just 1 item.
But starting the process again and again with 1 item is working fine.Best regards
Dominik
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 68 Spryker News
- 890 Developer Corner
- 753 Spryker Development
- 83 Spryker Dev Environment
- 360 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 22 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 68 Spryker Safari Questions
- 50 Random