I've created a module to override
di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Quote\Model\ShippingMethodManagement" type="Custom\FixShippingMethod\Model\ShippingMethodManagement"/>
</config>
class:
namespace Custom\FixShippingMethod\Model;
class ShippingMethodManagement extends \Magento\Quote\Model\ShippingMethodManagement
{
/**
* Get list of available shipping methods
*
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Framework\Api\ExtensibleDataInterface $address
* @return \Magento\Quote\Api\Data\ShippingMethodInterface[]
*/
public function getShippingMethods(Quote $quote, $address)
{
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/shippingmethodmanagement.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('test test test');
$output = [];
$shippingAddress = $quote->getShippingAddress();
//Patch for Magento issue #26682
/** @see https://github.com/magento/magento2/issues/26682 */
$addressData = $this->extractAddressData($address);
if (array_key_exists('extension_attributes', $addressData)) {
unset($addressData['extension_attributes']);
}
$shippingAddress->addData($addressData);
//End patch
$shippingAddress->setCollectShippingRates(true);
$this->totalsCollector->collectAddressTotals($quote, $shippingAddress);
$shippingRates = $shippingAddress->getGroupedAllShippingRates();
foreach ($shippingRates as $carrierRates) {
foreach ($carrierRates as $rate) {
$output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode());
}
}
return $output;
}
The method didn't run, anyone know what is the problem?