Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheapestMethodChooser.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Quote\Api\Data\ShippingMethodInterfaceFactory;
10 
15 {
19  private $shippingMethodFactory;
20 
24  private $carrierFinder;
25 
31  public function __construct(
32  ShippingMethodInterfaceFactory $shippingMethodFactory,
33  CarrierFinder $carrierFinder
34  ) {
35  $this->shippingMethodFactory = $shippingMethodFactory;
36  $this->carrierFinder = $carrierFinder;
37  }
38 
42  public function choose(Address $address)
43  {
44  $shippingMethod = $this->shippingMethodFactory->create()
47  ->setMethodTitle(__('Cheapest price'))
48  ->setAvailable($this->areShippingMethodsAvailable($address));
49  return $shippingMethod;
50  }
51 
58  private function areShippingMethodsAvailable(Address $address): bool
59  {
60  $carriersForAddress = $this->carrierFinder->getCarriersForCustomerAddress($address);
61  return !empty($carriersForAddress);
62  }
63 }
__()
Definition: __.php:13
$address
Definition: customer.php:38
__construct(ShippingMethodInterfaceFactory $shippingMethodFactory, CarrierFinder $carrierFinder)
$shippingMethod
Definition: popup.phtml:12