An Adobe Commerce developer is asked to implement a 15% surcharge for all users from a 'Wholesale' customer group. Keeping best practices in mind, what is a correct to accomplish this?
A.
Declare a new total collector class to calculate the modified total if the current user is in the group, register it in the module's etc/sales .xml file, modify the checkout_cart_index.xml and checkout_index_index.xml layouts to include a new child in the totals block.
B.
Create a Cart Price Rule that applies only to the 'Wholesale' group. Specify no conditions for the rule, and in the Actions section, specify for the rule to apply a "Percent of product price discount", with the 'Discount Amount" field set to -15.
C.
Create an Observer to the cataiog_product_get_final_price event. Check if the current customer is in the 'Wholesale' group, and if so, retrieve the
product from the $observer->getEventC) data and Call $product->setData('final_price', $product->getData( 'final_price') * 1.15).
The best practice to add a surcharge in Magento is to create a custom total collector that calculates and applies the surcharge. This approach integrates smoothly with Magento’s sales and checkout processes.
Total Collector for Surcharge:
Creating a new total collector class allows Magento to calculate a custom surcharge and display it in the appropriate sections of the checkout and order summaries.
Registering this in etc/sales.xml ensures that Magento includes this total during order processing and ensures it’s displayed properly on the frontend and backend.
Why Option A is Correct:
This approach follows Magento’s framework for managing additional charges. It ensures the surcharge is correctly applied and displayed.
Options B and C involve less maintainable and less integrated approaches. Option B misuses a Cart Price Rule, and Option C uses an observer, which does not fit well with Magento’s total calculation architecture.
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit