Hi we would like to sort and display the shipping methods by price Low to High on checkout page.
For example:
$31.72 Express Saver Federal Express
$37.50 2 DayFederal Express
$80.47 Standard Overnight Federal Express
$87.77 Priority Overnight Federal Express
$5.00 Fixed Flat Rate
$5.00 Media Mail Select Shipping Method
$10.00 FedEx Home Delivery Select Shipping Method
Referring this plugin concept trying to change my output using plugin. Magento 2: Hide other shipping methods when free shipping is available
<?php
namespace Demo\Test\Plugin\Model;
use Magento\Framework\Session\Generic;
class ShippingMethodManagement {
/**
* @var Generic
*/
private $coreSession;
/**
* @param \Magento\Framework\Session\Generic $sessionManager
*/
public function __construct(
Generic $sessionManager
) {
$this->coreSession = $sessionManager;
}
public function afterEstimateByExtendedAddress($shippingMethodManagement, $output)
{
return $this->filterOutput($output);
}
public function afterEstimateByAddress($shippingMethodManagement, $output)
{
return $this->filterOutput($output);
}
public function afterEstimateByAddressId($shippingMethodManagement, $output)
{
return $this->filterOutput($output);
}
private function filterOutput($output)
{
//Here i would like to sort shipping methods by shipping amount
$all = [];
foreach ($output as $shippingMethod) {
$all[] = $shippingMethod;
}
return $all;
}
}
}
vendor/magento/module-shipping/Model/Rate/CarrierResult.php
here you findgetAllRates
. Try to add breakpoint here with xdebug and check what you get and what it does.