What are the Slack Archives?
It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.
Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..
Hi! Quick question: I want to calculate a discount dynamically according to the products that are in
Hi!
Quick question: I want to calculate a discount dynamically according to the products that are in the cart. The rule system is on an external API.
I've currently extended the Discount Module to use the API to fetch for the discount rate. However, now I don't know how to read the Cart from the provided DiscountTransfer
or DiscountableItem[]
.
What would be the most "Sprykery way" of achieving this? I'm currently thinking about adding the cartId (the literal string) and cartHash (also the string you'd get in the If-Matches header) to the DiscountTransfer
in order to receive the cart from withing my calculation method. Is this a good approach?
Comments
-
Hi Thomas, for that case, The “most spryker way” would be to ignore the standard Spryker discounts and introduce your Calculator (that will fetch the discounts from external system and apply the discount) to the Calculation Stack
0 -
you can check f.e. here https://documentation.spryker.com/capabilities/cart/calculation/calculation-3-0.htm and then follow the links
0 -
the calculation stack is defined in Zed, CalculationDependencyProvider::getQuoteCalculatorPluginStack()
0 -
Hmm. That would mean though that I would skip the "normal" Discount calculation and interface. By adding my own
QuoteCalculatorPlugin
, I would effectively hook into calculating the end price of the cart, right?I don't think this is really what I want, I might have left out a crucial bit: We want to be able to add voucher codes from the web interface that are valid for certain products. Then we want to fetch the real discount rate by calling another API that does the calculation, according to other items in the cart (which might give extra discount).
0 -
Extending the calculation stack - would be the way I would implement that. Both discounts - spryker and your’s will stay separate, you can put your’s further in calculation stack, to be able to “overwrite” the default one. But you can of course try to find another way, by extending discounts, maybe some one else had such experience already and could share with you
0 -
Alright 🙂 Thank you very much!
0 -
Hi @UKJSE6T47, thanks for your response.
The calculation stack has already a DiscountCalculationPlugin right now which get’s in fact the QuoteTransfer. The calculation plugins we need at the moment are sub-parts of the DiscountCalculationPlugin ( like FixedPlugin, PerecentagePlugin etc.). But they just get DiscountableItems and Discount as input. When we would write a complete own calculator-plugin (e.g. “CustomDiscountCalculatorPlugin”) like you recommended, we can’t reuse the whole logic that is already in spryker (like the backend form, filter queries etc.).
I don’t see a way to reach our goals by implementing another calculator plugin without discarding the existing spryker stuff, which we want to use in every case …
So what would be your idea with “overwriting” the default one?0 -
@UPWG9AYH2 okay, I thought the only thing you need is to send a cart items to some external service and get back f.e. “18%” and apply it to the cart. If you need to completely re-use Zed UI and combine it some how with your external system - that might be totally different requirement.
0 -
Yeah, we added another plugin to the DiscountCalculator internal calculator stack. So, next to existing FixedPlugin and PerecentagePlugin there is now a “ExternalApiPlugin” which works out of the box especially for the backend form … the problem is - as already said - getting parameters into that plugin that are required for the external api call … like attributes from the cart etc. …
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 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
- 70 Spryker Safari Questions
- 50 Random