Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
CarrierFactory Class Reference
Inheritance diagram for CarrierFactory:
CarrierFactoryInterface

Public Member Functions

 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\ObjectManagerInterface $objectManager)
 
 get ($carrierCode)
 
 create ($carrierCode, $storeId=null)
 
 getIfActive ($carrierCode)
 
 createIfActive ($carrierCode, $storeId=null)
 

Protected Attributes

 $_scopeConfig
 
 $_objectManager
 

Detailed Description

Class CarrierFactory

Definition at line 11 of file CarrierFactory.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Framework\ObjectManagerInterface$objectManager

Definition at line 29 of file CarrierFactory.php.

32  {
33  $this->_scopeConfig = $scopeConfig;
34  $this->_objectManager = $objectManager;
35  }
$objectManager
Definition: bootstrap.php:17

Member Function Documentation

◆ create()

create (   $carrierCode,
  $storeId = null 
)

Create carrier instance

Parameters
string$carrierCode
int | null$storeId
Returns
bool|Carrier\AbstractCarrier

Implements CarrierFactoryInterface.

Definition at line 64 of file CarrierFactory.php.

65  {
66  $className = $this->_scopeConfig->getValue(
67  'carriers/' . $carrierCode . '/model',
68  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
69  $storeId
70  );
71  if (!$className) {
72  return false;
73  }
74  $carrier = $this->_objectManager->create($className);
75  $carrier->setId($carrierCode);
76  if ($storeId) {
77  $carrier->setStore($storeId);
78  }
79  return $carrier;
80  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ createIfActive()

createIfActive (   $carrierCode,
  $storeId = null 
)

Create carrier by its code if it is active

Parameters
string$carrierCode
null | int$storeId
Returns
bool|Carrier\AbstractCarrier

Implements CarrierFactoryInterface.

Definition at line 105 of file CarrierFactory.php.

106  {
107  return $this->_scopeConfig->isSetFlag(
108  'carriers/' . $carrierCode . '/active',
109  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
110  $storeId
111  ) ? $this->create(
112  $carrierCode,
113  $storeId
114  ) : false;
115  }
return false
Definition: gallery.phtml:36
create($carrierCode, $storeId=null)

◆ get()

get (   $carrierCode)

Get carrier instance

Parameters
string$carrierCode
Returns
bool|Carrier\AbstractCarrier

Implements CarrierFactoryInterface.

Definition at line 43 of file CarrierFactory.php.

44  {
45  $className = $this->_scopeConfig->getValue(
46  'carriers/' . $carrierCode . '/model',
47  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
48  );
49  if (!$className) {
50  return false;
51  }
52  $carrier = $this->_objectManager->get($className);
53  $carrier->setId($carrierCode);
54  return $carrier;
55  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ getIfActive()

getIfActive (   $carrierCode)

Get carrier by its code if it is active

Parameters
string$carrierCode
Returns
bool|Carrier\AbstractCarrier

Implements CarrierFactoryInterface.

Definition at line 88 of file CarrierFactory.php.

89  {
90  return $this->_scopeConfig->isSetFlag(
91  'carriers/' . $carrierCode . '/active',
92  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
93  ) ? $this->get(
94  $carrierCode
95  ) : false;
96  }

Field Documentation

◆ $_objectManager

$_objectManager
protected

Definition at line 23 of file CarrierFactory.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 18 of file CarrierFactory.php.


The documentation for this class was generated from the following file: