Should be achieved by preference not using the plugin and observer. can anyone provide code for this ?
- Using 'preference' should always be your last option, you should always choose plugin or observer as your first choiceMagePal Extensions– MagePal Extensions2022-06-30 11:57:17 +00:00Commented Jun 30, 2022 at 11:57
- This question is already answered. See magento.stackexchange.com/questions/357360/…MagePal Extensions– MagePal Extensions2022-06-30 11:58:35 +00:00Commented Jun 30, 2022 at 11:58
- Okay @MagePal Extensions I think this is not right question that guy is new on magento exchange so accept solution . Can you describe code here ?Mark– Mark2022-06-30 12:15:14 +00:00Commented Jun 30, 2022 at 12:15
Add a comment |
1 Answer
See Whenever a product is added to cart an additional qty of same product should be added to cart
Option 1 - (Don't recommend)
You can create a preference for
Magento\Checkout\Controller\Cart\Add and modify the
executemethod
Option 2 - (Strongly recommend)
Create a before plugin for
Magento\Checkout\Model\Cart\RequestQuantityProcessor::prepareQuantity
then check if the current request and update the qty as per your logic
- Okay Thanks @MagePal ExtensionsMark– Mark2022-06-30 16:36:08 +00:00Commented Jun 30, 2022 at 16:36