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

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Directory\Model\Country\FormatFactory $formatFactory, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionCollectionFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 loadByCode ($code)
 
 getRegions ()
 
 getLoadedRegionCollection ()
 
 getRegionCollection ()
 
 formatAddress (\Magento\Framework\DataObject $address, $html=false)
 
 getFormats ()
 
 getFormat ($type)
 
 getName ($locale=null)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Static Public Attributes

static $_format = []
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_localeLists
 
 $_formatFactory
 
 $_regionCollectionFactory
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Country model

@method string getCountryId() @method \Magento\Directory\Model\Country setCountryId(string $value)

@api

Since
100.0.2 @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 19 of file Country.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Locale\ListsInterface  $localeLists,
\Magento\Directory\Model\Country\FormatFactory  $formatFactory,
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory  $regionCollectionFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Locale\ListsInterface$localeLists
Country\FormatFactory$formatFactory
\Magento\Directory\Model\ResourceModel\Region\CollectionFactory$regionCollectionFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 51 of file Country.php.

60  {
61  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
62  $this->_localeLists = $localeLists;
63  $this->_formatFactory = $formatFactory;
64  $this->_regionCollectionFactory = $regionCollectionFactory;
65  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 70 of file Country.php.

71  {
72  $this->_init(\Magento\Directory\Model\ResourceModel\Country::class);
73  }

◆ formatAddress()

formatAddress ( \Magento\Framework\DataObject  $address,
  $html = false 
)
Parameters
\Magento\Framework\DataObject$address
bool$html
Returns
string

Definition at line 122 of file Country.php.

123  {
124  //TODO: is it still used?
125  $address->getRegion();
126  $address->getCountry();
127 
128  $template = $this->getData('address_template_' . ($html ? 'html' : 'plain'));
129  if (empty($template)) {
130  if (!$this->getId()) {
131  $template = '{{firstname}} {{lastname}}';
132  } elseif (!$html) {
133  $template = "{{firstname}} {{lastname}}
134 {{company}}
135 {{street1}}
136 {{street2}}
137 {{city}}, {{region}} {{postcode}}";
138  } else {
139  $template = "{{firstname}} {{lastname}}<br/>
140 {{street}}<br/>
141 {{city}}, {{region}} {{postcode}}<br/>
142 T: {{telephone}}";
143  }
144  }
145 
146  $filter = new \Magento\Framework\Filter\Template\Simple();
147  $addressText = $filter->setData($address->getData())->filter($template);
148 
149  if ($html) {
150  $addressText = preg_replace('#(<br\s*/?>\s*){2,}#im', '<br/>', $addressText);
151  } else {
152  $addressText = preg_replace('#(\n\s*){2,}#m', "\n", $addressText);
153  }
154 
155  return $addressText;
156  }
getData($key='', $index=null)
Definition: DataObject.php:119
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$address
Definition: customer.php:38
$template
Definition: export.php:12

◆ getFormat()

getFormat (   $type)

Retrieve country format

Parameters
string$type
Returns
\Magento\Directory\Model\Country\Format|null

Definition at line 184 of file Country.php.

185  {
186  if ($this->getFormats()) {
187  foreach ($this->getFormats() as $format) {
188  if ($format->getType() == $type) {
189  return $format;
190  }
191  }
192  }
193  return null;
194  }
$type
Definition: item.phtml:13
$format
Definition: list.phtml:12

◆ getFormats()

getFormats ( )

Retrieve country formats

Returns
\Magento\Directory\Model\ResourceModel\Country\Format\Collection

Definition at line 163 of file Country.php.

164  {
165  if (!isset(self::$_format[$this->getId()]) && $this->getId()) {
166  self::$_format[$this->getId()] = $this->_formatFactory->create()->getCollection()->setCountryFilter(
167  $this
168  )->load();
169  }
170 
171  if (isset(self::$_format[$this->getId()])) {
172  return self::$_format[$this->getId()];
173  }
174 
175  return null;
176  }

◆ getLoadedRegionCollection()

getLoadedRegionCollection ( )
Returns
\Magento\Directory\Model\ResourceModel\Region\Collection

Definition at line 100 of file Country.php.

101  {
102  $collection = $this->getRegionCollection();
103  $collection->load();
104  return $collection;
105  }

◆ getName()

getName (   $locale = null)

Get country name

Returns
string

Definition at line 201 of file Country.php.

202  {
203  if ($locale == null) {
204  $cache_key = 'name_default';
205  } else {
206  $cache_key = 'name_' . $locale;
207  }
208 
209  if (!$this->getData($cache_key)) {
210  $this->setData($cache_key, $this->_localeLists->getCountryTranslation($this->getId(), $locale));
211  }
212  return $this->getData($cache_key);
213  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getRegionCollection()

getRegionCollection ( )
Returns
\Magento\Directory\Model\ResourceModel\Region\Collection

Definition at line 110 of file Country.php.

111  {
112  $collection = $this->_regionCollectionFactory->create();
113  $collection->addCountryFilter($this->getId());
114  return $collection;
115  }

◆ getRegions()

getRegions ( )

Get regions

Returns
\Magento\Directory\Model\ResourceModel\Region\Collection

Definition at line 92 of file Country.php.

93  {
94  return $this->getLoadedRegionCollection();
95  }

◆ loadByCode()

loadByCode (   $code)

Load country by code

Parameters
string$code
Returns
$this

Definition at line 81 of file Country.php.

82  {
83  $this->_getResource()->loadByCode($this, $code);
84  return $this;
85  }
$code
Definition: info.phtml:12

Field Documentation

◆ $_format

$_format = []
static

Definition at line 24 of file Country.php.

◆ $_formatFactory

$_formatFactory
protected

Definition at line 34 of file Country.php.

◆ $_localeLists

$_localeLists
protected

Definition at line 29 of file Country.php.

◆ $_regionCollectionFactory

$_regionCollectionFactory
protected

Definition at line 39 of file Country.php.


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