Last active
July 31, 2018 17:48
-
-
Save dunkrupp/c05d54159729db74b708e6d6bfc85fa2 to your computer and use it in GitHub Desktop.
Retrieves a list of active carriers in Magento 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var \Magento\Shipping\Model\Config $methods */ | |
$shippingConfig = $this->objectManager->create('Magento\Shipping\Model\Config'); | |
$deliveryMethods = $shippingConfig->getAllCarriers(); | |
/** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopConfig */ | |
$scopeConfig = $this->objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface'); | |
$carriers = []; | |
foreach ($deliveryMethods as $shippingCode => $shippingModel) { | |
$shippingTitle = $scopeConfig->getValue('carriers/'.$shippingCode.'/title'); | |
$carriers[$shippigCode] = [ | |
'label' => $shippingTitle, | |
'value' => $shippingCode | |
]; | |
} | |
var_dump($carriers); | |
die; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment