I would like to develop one add-on on my product detail page. I want to calculate estimated Shipping rates and Taxes.
Please review the following process which I am trying to achieve:
- On product detail page there is an button called "Estimate Shipping Rates".
- User clicks on the button and pop up will be opened with three fields Country, State and Zipcode.
- User fills those details and submit the form an AJAX request will be sent.
- Magento will calculate shipping rates send data in JSON format.
I am successful to achieve till third step. The problem is on 4th step. As per my findings I tried to replicate scenario as it is working on Cart page >> Estimate Shipping and Tax section:
-
Magento's process will be initiated from
vendor/magento/module-quote/etc/webapi.xml
file.<route url="/V1/guest-carts/:cartId/estimate-shipping-methods" method="POST"> <service class="Magento\Quote\Api\GuestShipmentEstimationInterface" method="estimateByExtendedAddress"/> <resources> <resource ref="anonymous" /> </resources> </route>
-
It will traverse to couple of interfaces and classes.
- At the end it will retrieve from file –
vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php
, this file extendsShipmentEstimationInterface
, ShipmentEstimationInterface call functionestimateByExtendedAddress($cartId, AddressInterface $address)
. Which locate in this pathvendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php
I am sure how to call or integrate this process in my custom module.I found an example for magento 1 here. Please suggest way to achieve this task.
Best Answer