本文整理汇总了PHP中Magento\Customer\Model\Session::getAddressFormData方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getAddressFormData方法的具体用法?PHP Session::getAddressFormData怎么用?PHP Session::getAddressFormData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Model\Session
的用法示例。
在下文中一共展示了Session::getAddressFormData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareLayout
/**
* Prepare the layout of the address edit block.
*
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
// Init address object
if ($addressId = $this->getRequest()->getParam('id')) {
try {
$this->_address = $this->_addressRepository->getById($addressId);
if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) {
$this->_address = null;
}
} catch (NoSuchEntityException $e) {
$this->_address = null;
}
}
if ($this->_address === null || !$this->_address->getId()) {
$this->_address = $this->addressDataFactory->create();
$customer = $this->getCustomer();
$this->_address->setPrefix($customer->getPrefix());
$this->_address->setFirstname($customer->getFirstname());
$this->_address->setMiddlename($customer->getMiddlename());
$this->_address->setLastname($customer->getLastname());
$this->_address->setSuffix($customer->getSuffix());
}
$this->pageConfig->getTitle()->set($this->getTitle());
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
$postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']];
}
$this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
}
return $this;
}
示例2: _prepareLayout
/**
* Prepare the layout of the address edit block.
*
* @return $this
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
// Init address object
if ($addressId = $this->getRequest()->getParam('id')) {
try {
$this->_address = $this->_addressService->getAddress($addressId);
} catch (NoSuchEntityException $e) {
}
}
if (is_null($this->_address) || !$this->_address->getId()) {
$this->_address = $this->_addressBuilder->setPrefix($this->getCustomer()->getPrefix())->setFirstname($this->getCustomer()->getFirstname())->setMiddlename($this->getCustomer()->getMiddlename())->setLastname($this->getCustomer()->getLastname())->setSuffix($this->getCustomer()->getSuffix())->create();
}
if ($headBlock = $this->getLayout()->getBlock('head')) {
$headBlock->setTitle($this->getTitle());
}
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
$postedData['region'] = array('region_id' => $postedData['region_id'], 'region' => $postedData['region']);
}
$this->_address = $this->_addressBuilder->mergeDataObjectWithArray($this->_address, $postedData);
}
return $this;
}