本文整理汇总了PHP中Magento\Framework\Event\Observer::getCustomerAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::getCustomerAddress方法的具体用法?PHP Observer::getCustomerAddress怎么用?PHP Observer::getCustomerAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Event\Observer
的用法示例。
在下文中一共展示了Observer::getCustomerAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(Observer $observer)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
/** @var $customerAddress Address */
$address = $observer->getCustomerAddress();
// Check if the address is either the default billing, shipping, or both
if ($this->isDefaultBilling($address)) {
$this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($this->isDefaultShipping($address)) {
$this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
}
}
示例2: execute
/**
* Address before save event handler
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_coreRegistry->registry(self::VIV_CURRENTLY_SAVED_ADDRESS)) {
$this->_coreRegistry->unregister(self::VIV_CURRENTLY_SAVED_ADDRESS);
}
/** @var $customerAddress Address */
$customerAddress = $observer->getCustomerAddress();
if ($customerAddress->getId()) {
$this->_coreRegistry->register(self::VIV_CURRENTLY_SAVED_ADDRESS, $customerAddress->getId());
} else {
$configAddressType = $this->_customerAddress->getTaxCalculationAddressType();
$forceProcess = $configAddressType == AbstractAddress::TYPE_SHIPPING ? $customerAddress->getIsDefaultShipping() : $customerAddress->getIsDefaultBilling();
if ($forceProcess) {
$customerAddress->setForceProcess(true);
} else {
$this->_coreRegistry->register(self::VIV_CURRENTLY_SAVED_ADDRESS, 'new_address');
}
}
}
示例3: execute
/**
* Address after save event handler
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var $customerAddress Address */
$customerAddress = $observer->getCustomerAddress();
$customer = $customerAddress->getCustomer();
if (!$this->_customerAddress->isVatValidationEnabled($customer->getStore()) || $this->_coreRegistry->registry(self::VIV_PROCESSED_FLAG) || !$this->_canProcessAddress($customerAddress)) {
return;
}
try {
$this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, true);
if ($customerAddress->getVatId() == '' || !$this->_customerVat->isCountryInEU($customerAddress->getCountry())) {
$defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
$customer->setGroupId($defaultGroupId);
$customer->save();
}
} else {
$result = $this->_customerVat->checkVatNumber($customerAddress->getCountryId(), $customerAddress->getVatId());
$newGroupId = $this->_customerVat->getCustomerGroupIdBasedOnVatNumber($customerAddress->getCountryId(), $result, $customer->getStore());
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $newGroupId) {
$customer->setGroupId($newGroupId);
$customer->save();
}
$customerAddress->setVatValidationResult($result);
if ($this->appState->getAreaCode() == Area::AREA_FRONTEND) {
if ($result->getIsValid()) {
$this->addValidMessage($customerAddress, $result);
} elseif ($result->getRequestSuccess()) {
$this->addInvalidMessage($customerAddress);
} else {
$this->addErrorMessage($customerAddress);
}
}
}
} catch (\Exception $e) {
$this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, false, true);
}
}
示例4: afterAddressSave
/**
* Address after save event handler
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function afterAddressSave($observer)
{
/** @var $customerAddress Address */
$customerAddress = $observer->getCustomerAddress();
$customer = $customerAddress->getCustomer();
if (!$this->_customerAddress->isVatValidationEnabled($customer->getStore()) || $this->_coreRegistry->registry(self::VIV_PROCESSED_FLAG) || !$this->_canProcessAddress($customerAddress)) {
return;
}
try {
$this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, true);
if ($customerAddress->getVatId() == '' || !$this->_customerVat->isCountryInEU($customerAddress->getCountry())) {
$defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
$customer->setGroupId($defaultGroupId);
$customer->save();
}
} else {
$result = $this->_customerVat->checkVatNumber($customerAddress->getCountryId(), $customerAddress->getVatId());
$newGroupId = $this->_customerVat->getCustomerGroupIdBasedOnVatNumber($customerAddress->getCountryId(), $result, $customer->getStore());
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $newGroupId) {
$customer->setGroupId($newGroupId);
$customer->save();
}
$customerAddress->setVatValidationResult($result);
}
} catch (\Exception $e) {
$this->_coreRegistry->register(self::VIV_PROCESSED_FLAG, false, true);
}
}
示例5: afterAddressSave
/**
* Address after save event handler
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function afterAddressSave($observer)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->weeeHelper->isEnabled()) {
/** @var $customerAddress Address */
$address = $observer->getCustomerAddress();
// Check if the address is either the default billing, shipping, or both
if ($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) {
$this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
if ($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) {
$this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
}
}
}