Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Book Class Reference
Inheritance diagram for Book:
Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (\Magento\Framework\View\Element\Template\Context $context, CustomerRepositoryInterface $customerRepository, AddressRepositoryInterface $addressRepository, \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer, \Magento\Customer\Model\Address\Config $addressConfig, Mapper $addressMapper, array $data=[])
 
 getAddAddressUrl ()
 
 getBackUrl ()
 
 getDeleteUrl ()
 
 getAddressEditUrl ($addressId)
 
 hasPrimaryAddress ()
 
 getAdditionalAddresses ()
 
 getCustomer ()
 
 getDefaultBilling ()
 
 getAddressById ($addressId)
 
 getDefaultShipping ()
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- 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)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _prepareLayout ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $currentCustomer
 
 $customerRepository
 
 $addressRepository
 
 $_addressConfig
 
 $addressMapper
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Customer address book block

@api

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Since
100.0.2

Definition at line 19 of file Book.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\View\Element\Template\Context  $context,
CustomerRepositoryInterface  $customerRepository,
AddressRepositoryInterface  $addressRepository,
\Magento\Customer\Helper\Session\CurrentCustomer  $currentCustomer,
\Magento\Customer\Model\Address\Config  $addressConfig,
Mapper  $addressMapper,
array  $data = [] 
)
Parameters
\Magento\Framework\View\Element\Template\Context$context
CustomerRepositoryInterface$customerRepository
AddressRepositoryInterface$addressRepository
\Magento\Customer\Helper\Session\CurrentCustomer$currentCustomer
\Magento\Customer\Model\Address\Config$addressConfig
Mapper$addressMapper
array$data

Definition at line 55 of file Book.php.

63  {
64  $this->customerRepository = $customerRepository;
65  $this->currentCustomer = $currentCustomer;
66  $this->addressRepository = $addressRepository;
67  $this->_addressConfig = $addressConfig;
68  $this->addressMapper = $addressMapper;
69  parent::__construct($context, $data);
70  }

Member Function Documentation

◆ _prepareLayout()

_prepareLayout ( )
protected
Returns
$this

Definition at line 75 of file Book.php.

76  {
77  $this->pageConfig->getTitle()->set(__('Address Book'));
78  return parent::_prepareLayout();
79  }
__()
Definition: __.php:13

◆ getAddAddressUrl()

getAddAddressUrl ( )
Returns
string

Definition at line 84 of file Book.php.

85  {
86  return $this->getUrl('customer/address/new', ['_secure' => true]);
87  }

◆ getAdditionalAddresses()

getAdditionalAddresses ( )
Returns
\Magento\Customer\Api\Data\AddressInterface[]|bool

Definition at line 128 of file Book.php.

129  {
130  try {
131  $addresses = $this->customerRepository->getById($this->currentCustomer->getCustomerId())->getAddresses();
132  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
133  return false;
134  }
135  $primaryAddressIds = [$this->getDefaultBilling(), $this->getDefaultShipping()];
136  foreach ($addresses as $address) {
137  if (!in_array($address->getId(), $primaryAddressIds)) {
138  $additional[] = $address;
139  }
140  }
141  return empty($additional) ? false : $additional;
142  }
return false
Definition: gallery.phtml:36
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38

◆ getAddressById()

getAddressById (   $addressId)
Parameters
int$addressId
Returns
\Magento\Customer\Api\Data\AddressInterface|null

Definition at line 194 of file Book.php.

195  {
196  try {
197  return $this->addressRepository->getById($addressId);
198  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
199  return null;
200  }
201  }

◆ getAddressEditUrl()

getAddressEditUrl (   $addressId)
Parameters
int$addressId
Returns
string

Definition at line 112 of file Book.php.

113  {
114  return $this->getUrl('customer/address/edit', ['_secure' => true, 'id' => $addressId]);
115  }

◆ getBackUrl()

getBackUrl ( )
Returns
string

Definition at line 92 of file Book.php.

93  {
94  if ($this->getRefererUrl()) {
95  return $this->getRefererUrl();
96  }
97  return $this->getUrl('customer/account/', ['_secure' => true]);
98  }

◆ getCustomer()

getCustomer ( )
Returns
\Magento\Customer\Api\Data\CustomerInterface|null

Definition at line 163 of file Book.php.

164  {
165  $customer = $this->getData('customer');
166  if ($customer === null) {
167  try {
168  $customer = $this->customerRepository->getById($this->currentCustomer->getCustomerId());
169  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
170  return null;
171  }
172  $this->setData('customer', $customer);
173  }
174  return $customer;
175  }
getData($key='', $index=null)
Definition: DataObject.php:119
$customer
Definition: customers.php:11
setData($key, $value=null)
Definition: DataObject.php:72

◆ getDefaultBilling()

getDefaultBilling ( )
Returns
int|null

Definition at line 180 of file Book.php.

181  {
182  $customer = $this->getCustomer();
183  if ($customer === null) {
184  return null;
185  } else {
186  return $customer->getDefaultBilling();
187  }
188  }
$customer
Definition: customers.php:11

◆ getDefaultShipping()

getDefaultShipping ( )
Returns
int|null

Definition at line 206 of file Book.php.

207  {
208  $customer = $this->getCustomer();
209  if ($customer === null) {
210  return null;
211  } else {
212  return $customer->getDefaultShipping();
213  }
214  }
$customer
Definition: customers.php:11

◆ getDeleteUrl()

getDeleteUrl ( )
Returns
string

Definition at line 103 of file Book.php.

104  {
105  return $this->getUrl('customer/address/delete');
106  }

◆ hasPrimaryAddress()

hasPrimaryAddress ( )
Returns
bool

Definition at line 120 of file Book.php.

121  {
122  return $this->getDefaultBilling() || $this->getDefaultShipping();
123  }

Field Documentation

◆ $_addressConfig

$_addressConfig
protected

Definition at line 39 of file Book.php.

◆ $addressMapper

$addressMapper
protected

Definition at line 44 of file Book.php.

◆ $addressRepository

$addressRepository
protected

Definition at line 34 of file Book.php.

◆ $currentCustomer

$currentCustomer
protected

Definition at line 24 of file Book.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 29 of file Book.php.


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