Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Allmethods.php
Go to the documentation of this file.
1 <?php
7 
9 {
15  protected $_scopeConfig;
16 
20  protected $_shippingConfig;
21 
26  public function __construct(
27  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
28  \Magento\Shipping\Model\Config $shippingConfig
29  ) {
30  $this->_scopeConfig = $scopeConfig;
31  $this->_shippingConfig = $shippingConfig;
32  }
33 
41  public function toOptionArray($isActiveOnlyFlag = false)
42  {
43  $methods = [['value' => '', 'label' => '']];
44  $carriers = $this->_shippingConfig->getAllCarriers();
45  foreach ($carriers as $carrierCode => $carrierModel) {
46  if (!$carrierModel->isActive() && (bool)$isActiveOnlyFlag === true) {
47  continue;
48  }
49  $carrierMethods = $carrierModel->getAllowedMethods();
50  if (!$carrierMethods) {
51  continue;
52  }
53  $carrierTitle = $this->_scopeConfig->getValue(
54  'carriers/' . $carrierCode . '/title',
55  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
56  );
57  $methods[$carrierCode] = ['label' => $carrierTitle, 'value' => []];
58  foreach ($carrierMethods as $methodCode => $methodTitle) {
59  $methods[$carrierCode]['value'][] = [
60  'value' => $carrierCode . '_' . $methodCode,
61  'label' => '[' . $carrierCode . '] ' . $methodTitle,
62  ];
63  }
64  }
65 
66  return $methods;
67  }
68 }
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Shipping\Model\Config $shippingConfig)
Definition: Allmethods.php:26
$methods
Definition: billing.phtml:71