0
    public function afterEstimateByExtendedAddress(
        \Magento\Quote\Api\ShipmentEstimationInterface $subject,
        $result,
        $cartId,
        \Magento\Quote\Api\Data\AddressInterface $address
    ) {
        $quote = $this->checkoutSession->getQuote();
        $shippingAddress = $address;


        if (empty($shippingAddress->getCity()))
            return $result;

        $areaTerm = $shippingAddress->getCity() . ':' . $shippingAddress->getCountryId();

        $searchRequest = $this->searchRequestBuilder
            ->setScopeCode('base')
            ->setAreaRadius(80)
            ->setAreaSearchTerm($areaTerm)
            ->create();

        $searchCriteria = $this->searchCriteriaResolver->resolve($searchRequest);

        $searchResult = $this->sourceRepository->getList($searchCriteria);

        $sources = $this->extractor->getSources($searchRequest, $searchResult);
        if (!$sources) {
            throw new NotFoundException(__('Sorry, We can not find available dealer for your address. You may check our pick-in store locations.'));
            $this->logger->info('SearchRequest', $sources);
            return $this->sendPickupOnly($result);
        }
1
  • <type name="Magento\Quote\Api\ShipmentEstimationInterface"> <plugin name="vendor_dropshipping_dealer_delivery" type="Vendor\Dropshipping\Plugin\ShipmentEstimation" /> </type> this is the event.xml
    – K-N
    Commented Aug 18, 2022 at 8:24

1 Answer 1

1

In webapi.xml you can find 2 different methods to estimate

<routes>
    <!-- ... -->
    <route url="/V1/carts/mine/estimate-shipping-methods" method="POST">
        <service class="Magento\Quote\Api\ShipmentEstimationInterface" method="estimateByExtendedAddress"/>
        <resources>
            <resource ref="self" />
        </resources>
        <data>
            <parameter name="cartId" force="true">%cart_id%</parameter>
        </data>
    </route>
    <route url="/V1/carts/mine/estimate-shipping-methods-by-address-id" method="POST">
        <service class="Magento\Quote\Api\ShippingMethodManagementInterface" method="estimateByAddressId"/>
        <resources>
            <resource ref="self" />
        </resources>
        <data>
            <parameter name="cartId" force="true">%cart_id%</parameter>
        </data>
    </route>
    <!-- ... -->
</routes>

You need to create another one plugin for Magento\Quote\Api\ShippingMethodManagementInterface::estimateByAddressId

1
  • It works. Thank you so much
    – K-N
    Commented Aug 19, 2022 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.