Issue with Dependency Injection in Custom Price Modificator #16946
Unanswered
AlephCode
asked this question in
Q&A / Support
Replies: 1 comment 2 replies
-
@mattamon Could you lend me a hand with this at some point, please? I would greatly appreciate it if you could provide me with some guidance on how to use my service within my Modifier class, as I won't be using a static shipping fee but rather it should be calculated using the service I want to inject. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Pimcore Community,
I am currently developing a custom price modificator named Shipping for the cart system (specifically on the price calculator) in Pimcore. My goal is to inject a service called LocalShippingService into this modificator to utilize some of its specific functionalities.
Context
I have configured my Shipping modificator in the Pimcore system as follows:
The issue arises when I attempt to inject the LocalShippingService directly into the constructor of Shipping. The CartPriceCalculator class, which is responsible for creating the modificators, does not pass this service to the constructor, resulting in a "Too few arguments" error, as the constructor expects to receive the service as an argument.
Specific Problem
When CartPriceCalculator instances the modificators, there is no provision to inject services or additional dependencies other than those explicitly configured in modificators:
I attempted to use a custom class instead of CartPriceCalculator by extending it and injecting the LocalShippingService into its constructor. However, this resulted in an error stating that the constructor is not compatible with the CartPriceCalculatorInterface.
Requests for Help
Is there a standard or Pimcore-recommended way to handle dependency injection in price modificators? I am looking for a solution that allows me to integrate services without modifying Pimcore's core logic.
Has anyone faced and overcome a similar issue when trying to extend cart functionality or working with custom modificators? Any code examples or guidance would be greatly appreciated.
Would modifying CartPriceCalculator to allow dependency injections be advisable, or is there a better practice for handling such configuration needs?
Thank you in advance for any help or direction you can provide.
Beta Was this translation helpful? Give feedback.
All reactions