public function toOptionArray() { $arr = []; $carriers = $this->shippingConfig->getAllCarriers($this->storeManager->getStore()); foreach ($carriers as $carrierCode => $carrierModel) { $carrierTitle = $this->shipperDataHelper->getConfigValue('carriers/' . $carrierCode . '/title'); if (strpos($carrierCode, 'shipper') === 0 || $carrierTitle == '') { continue; } if ($this->shipperDataHelper->getConfigValue('carriers/' . $carrierCode . '/model') == 'ShipperHQ\\Shipper\\Model\\Carrier\\Shipper') { continue; } $arr[] = ['value' => $carrierCode, 'label' => $carrierTitle]; } array_unshift($arr, ['value' => false, 'label' => __('No Carrier')]); return $arr; }
/** * Return array of carriers. * If $isActiveOnlyFlag is set to true, will return only active carriers * * @param bool $isActiveOnlyFlag * @return array */ public function toOptionArray($isActiveOnlyFlag = false) { $methods = [['value' => '', 'label' => '']]; $carriers = $this->_shippingConfig->getAllCarriers(); foreach ($carriers as $carrierCode => $carrierModel) { if (!$carrierModel->isActive() && (bool) $isActiveOnlyFlag === true) { continue; } $carrierMethods = $carrierModel->getAllowedMethods(); if (!$carrierMethods) { continue; } $carrierTitle = $this->_scopeConfig->getValue('carriers/' . $carrierCode . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $methods[$carrierCode] = ['label' => $carrierTitle, 'value' => []]; foreach ($carrierMethods as $methodCode => $methodTitle) { $methods[$carrierCode]['value'][] = ['value' => $carrierCode . '_' . $methodCode, 'label' => '[' . $carrierCode . '] ' . $methodTitle]; } } return $methods; }
/** * @return array */ protected function _getCarriersInstances() { return $this->_shippingConfig->getAllCarriers($this->getShipment()->getStoreId()); }
/** * Returns active carriers codes * @return array */ private function getActiveCarriers() { $activeCarriers = []; foreach ($this->shippingMethodConfig->getActiveCarriers() as $carrier) { $activeCarriers[] = $carrier->getCarrierCode(); } return $activeCarriers; }