Calling Developers!
We are reenergizing our code contribution process! Learn More

Is it possible to reset the quote with all calculated discounts?

dominik.marx Spryker Customer Posts: 2 πŸ§‘πŸ»β€πŸš€ - Cadet
edited November 2023 in Spryker Development

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 πŸ™ˆ


  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,018 βš–οΈ - 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,


  • dominik.marx
    dominik.marx Spryker Customer Posts: 2 πŸ§‘πŸ»β€πŸš€ - Cadet

    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
        return (new QuoteTransfer())
            ->setStore((new StoreTransfer())->setName(self::DEFAULT_STORE))
            ->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