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

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Framework\View\Element\BlockFactory $blockFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, CustomerMetadataInterface $customerMetadataService, AddressMetadataInterface $addressMetadataService, \Magento\Customer\Model\Address\Config $addressConfig)
 
 getBookUrl ()
 
 getEditUrl ()
 
 getDeleteUrl ()
 
 getCreateUrl ()
 
 getRenderer ($renderer)
 
 getConfig ($key, $store=null)
 
 getStreetLines ($store=null)
 
 getFormat ($code)
 
 getFormatTypeRenderer ($code)
 
 canShowConfig ($key)
 
 convertStreetLines ($origStreets, $toCount)
 
 isVatValidationEnabled ($store=null)
 
 isDisableAutoGroupAssignDefaultValue ()
 
 hasValidateOnEachTransaction ($store=null)
 
 getTaxCalculationAddressType ($store=null)
 
 isVatAttributeVisible ()
 
 isAttributeVisible ($code)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT = 'customer/create_account/viv_disable_auto_group_assign_default'
 
const XML_PATH_VIV_ON_EACH_TRANSACTION = 'customer/create_account/viv_on_each_transaction'
 
const XML_PATH_VAT_VALIDATION_ENABLED = 'customer/create_account/auto_group_assign'
 
const XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE = 'customer/create_account/tax_calculation_address_type'
 
const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/create_account/vat_frontend_visibility'
 
const TYPE_BILLING = 'billing'
 
const TYPE_SHIPPING = 'shipping'
 

Protected Attributes

 $_attributes
 
 $_config = []
 
 $_streetLines = []
 
 $_formatTemplate = []
 
 $_blockFactory
 
 $_storeManager
 
 $_customerMetadataService
 
 $_addressMetadataService
 
 $_addressConfig
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Customer address helper

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 21 of file Address.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Framework\View\Element\BlockFactory  $blockFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
CustomerMetadataInterface  $customerMetadataService,
AddressMetadataInterface  $addressMetadataService,
\Magento\Customer\Model\Address\Config  $addressConfig 
)
Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Framework\View\Element\BlockFactory$blockFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
CustomerMetadataInterface$customerMetadataService
AddressMetadataInterface$addressMetadataService
\Magento\Customer\Model\Address\Config$addressConfig

Definition at line 104 of file Address.php.

111  {
112  $this->_blockFactory = $blockFactory;
113  $this->_storeManager = $storeManager;
114  $this->_customerMetadataService = $customerMetadataService;
115  $this->_addressMetadataService = $addressMetadataService;
116  $this->_addressConfig = $addressConfig;
117  parent::__construct($context);
118  }
$storeManager

Member Function Documentation

◆ canShowConfig()

canShowConfig (   $key)

Determine if specified address config value can be shown

Parameters
string$key
Returns
bool

Definition at line 237 of file Address.php.

238  {
239  return (bool)$this->getConfig($key);
240  }
getConfig($key, $store=null)
Definition: Address.php:170

◆ convertStreetLines()

convertStreetLines (   $origStreets,
  $toCount 
)

Convert streets array to new street lines count Examples of use: $origStreets = array('street1', 'street2', 'street3', 'street4') $toCount = 3 Result: array('street1 street2', 'street3', 'street4') $toCount = 2 Result: array('street1 street2', 'street3 street4')

Parameters
string[]$origStreets
int$toCount
Returns
string[]

Definition at line 283 of file Address.php.

284  {
285  $lines = [];
286  if (!empty($origStreets) && $toCount > 0) {
287  $countArgs = (int)floor(count($origStreets) / $toCount);
288  $modulo = count($origStreets) % $toCount;
289  $offset = 0;
290  $neededLinesCount = 0;
291  for ($i = 0; $i < $toCount; $i++) {
292  $offset += $neededLinesCount;
293  $neededLinesCount = $countArgs;
294  if ($modulo > 0) {
295  ++$neededLinesCount;
296  --$modulo;
297  }
298  $values = array_slice($origStreets, $offset, $neededLinesCount);
299  if (is_array($values)) {
300  $lines[] = implode(' ', $values);
301  }
302  }
303  }
304 
305  return $lines;
306  }
$values
Definition: options.phtml:88
$i
Definition: gallery.phtml:31

◆ getBookUrl()

getBookUrl ( )

Addresses url

Returns
void

Definition at line 125 of file Address.php.

126  {
127  }

◆ getConfig()

getConfig (   $key,
  $store = null 
)

Return customer address config value by key and store

Parameters
string$key
\Magento\Store\Model\Store | int | string$store
Returns
string|null

Definition at line 170 of file Address.php.

171  {
172  $store = $this->_storeManager->getStore($store);
173  $websiteId = $store->getWebsiteId();
174  if (!isset($this->_config[$websiteId])) {
175  $this->_config[$websiteId] = $this->scopeConfig->getValue(
176  'customer/address',
177  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
178  $store
179  );
180  }
181  return isset($this->_config[$websiteId][$key]) ? (string)$this->_config[$websiteId][$key] : null;
182  }

◆ getCreateUrl()

getCreateUrl ( )
Returns
void

Definition at line 146 of file Address.php.

147  {
148  }

◆ getDeleteUrl()

getDeleteUrl ( )
Returns
void

Definition at line 139 of file Address.php.

140  {
141  }

◆ getEditUrl()

getEditUrl ( )
Returns
void

Definition at line 132 of file Address.php.

133  {
134  }

◆ getFormat()

getFormat (   $code)
Parameters
string$code
Returns
Format|string

Definition at line 210 of file Address.php.

211  {
212  $format = $this->_addressConfig->getFormatByCode($code);
213  return $format->getRenderer() ? $format->getRenderer()->getFormatArray() : '';
214  }
$format
Definition: list.phtml:12
$code
Definition: info.phtml:12

◆ getFormatTypeRenderer()

getFormatTypeRenderer (   $code)

Retrieve renderer by code

Parameters
string$code
Returns
\Magento\Customer\Block\Address\Renderer\RendererInterface|null

Definition at line 222 of file Address.php.

223  {
224  $formatType = $this->_addressConfig->getFormatByCode($code);
225  if (!$formatType || !$formatType->getRenderer()) {
226  return null;
227  }
228  return $formatType->getRenderer();
229  }
$code
Definition: info.phtml:12

◆ getRenderer()

getRenderer (   $renderer)
Parameters
string$renderer
Returns
\Magento\Framework\View\Element\BlockInterface

Definition at line 154 of file Address.php.

155  {
156  if (is_string($renderer) && $renderer) {
157  return $this->_blockFactory->createBlock($renderer, []);
158  } else {
159  return $renderer;
160  }
161  }

◆ getStreetLines()

getStreetLines (   $store = null)

Return Number of Lines in a Street Address for store

Parameters
\Magento\Store\Model\Store | int | string$store
Returns
int

Definition at line 190 of file Address.php.

191  {
192  $websiteId = $this->_storeManager->getStore($store)->getWebsiteId();
193  if (!isset($this->_streetLines[$websiteId])) {
194  $attribute = $this->_addressMetadataService->getAttributeMetadata('street');
195 
196  $lines = $attribute->getMultilineCount();
197  if ($lines <= 0) {
198  $lines = 2;
199  }
200  $this->_streetLines[$websiteId] = min($lines, 20);
201  }
202 
203  return $this->_streetLines[$websiteId];
204  }

◆ getTaxCalculationAddressType()

getTaxCalculationAddressType (   $store = null)

Retrieve customer address type on which tax calculation must be based

Parameters
\Magento\Store\Model\Store | string | int | null$store
Returns
string

Definition at line 357 of file Address.php.

358  {
359  return (string)$this->scopeConfig->getValue(
360  self::XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE,
361  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
362  $store
363  );
364  }

◆ hasValidateOnEachTransaction()

hasValidateOnEachTransaction (   $store = null)

Retrieve 'validate on each transaction' value

Parameters
\Magento\Store\Model\Store | string | int$store
Returns
bool

Definition at line 342 of file Address.php.

343  {
344  return (bool)$this->scopeConfig->getValue(
345  self::XML_PATH_VIV_ON_EACH_TRANSACTION,
346  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
347  $store
348  );
349  }

◆ isAttributeVisible()

isAttributeVisible (   $code)

Retrieve attribute visibility

Parameters
string$code
Returns
bool
Since
101.0.0

Definition at line 386 of file Address.php.

387  {
388  $attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code);
389  if ($attributeMetadata) {
390  return $attributeMetadata->isVisible();
391  }
392  return false;
393  }
$code
Definition: info.phtml:12

◆ isDisableAutoGroupAssignDefaultValue()

isDisableAutoGroupAssignDefaultValue ( )

Retrieve disable auto group assign default value

Returns
bool

Definition at line 328 of file Address.php.

329  {
330  return (bool)$this->scopeConfig->getValue(
331  self::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT,
332  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
333  );
334  }

◆ isVatAttributeVisible()

isVatAttributeVisible ( )

Check if VAT ID address attribute has to be shown on frontend (on Customer Address management forms)

Returns
boolean

Definition at line 371 of file Address.php.

372  {
373  return (bool)$this->scopeConfig->getValue(
374  self::XML_PATH_VAT_FRONTEND_VISIBILITY,
375  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
376  );
377  }

◆ isVatValidationEnabled()

isVatValidationEnabled (   $store = null)

Check whether VAT ID validation is enabled

Parameters
\Magento\Store\Model\Store | string | int$store
Returns
bool

Definition at line 314 of file Address.php.

315  {
316  return (bool)$this->scopeConfig->getValue(
317  self::XML_PATH_VAT_VALIDATION_ENABLED,
318  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
319  $store
320  );
321  }

Field Documentation

◆ $_addressConfig

$_addressConfig
protected

Definition at line 94 of file Address.php.

◆ $_addressMetadataService

$_addressMetadataService
protected

Definition at line 89 of file Address.php.

◆ $_attributes

$_attributes
protected

Definition at line 48 of file Address.php.

◆ $_blockFactory

$_blockFactory
protected

Definition at line 72 of file Address.php.

◆ $_config

$_config = []
protected

Definition at line 55 of file Address.php.

◆ $_customerMetadataService

$_customerMetadataService
protected

Definition at line 84 of file Address.php.

◆ $_formatTemplate

$_formatTemplate = []
protected

Definition at line 67 of file Address.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 77 of file Address.php.

◆ $_streetLines

$_streetLines = []
protected

Definition at line 62 of file Address.php.

◆ TYPE_BILLING

const TYPE_BILLING = 'billing'

Possible customer address types

Definition at line 39 of file Address.php.

◆ TYPE_SHIPPING

const TYPE_SHIPPING = 'shipping'

Definition at line 41 of file Address.php.

◆ XML_PATH_VAT_FRONTEND_VISIBILITY

const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/create_account/vat_frontend_visibility'

Definition at line 34 of file Address.php.

◆ XML_PATH_VAT_VALIDATION_ENABLED

const XML_PATH_VAT_VALIDATION_ENABLED = 'customer/create_account/auto_group_assign'

Definition at line 30 of file Address.php.

◆ XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT

const XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT = 'customer/create_account/viv_disable_auto_group_assign_default'

VAT Validation parameters XML paths

Definition at line 26 of file Address.php.

◆ XML_PATH_VIV_ON_EACH_TRANSACTION

const XML_PATH_VIV_ON_EACH_TRANSACTION = 'customer/create_account/viv_on_each_transaction'

Definition at line 28 of file Address.php.

◆ XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE

const XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE = 'customer/create_account/tax_calculation_address_type'

Definition at line 32 of file Address.php.


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