本文整理汇总了PHP中Magento\Customer\Helper\Address类的典型用法代码示例。如果您正苦于以下问题:PHP Address类的具体用法?PHP Address怎么用?PHP Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Restore initial customer group ID in quote if needed on collect_totals_after event of quote address
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute($observer)
{
$quoteAddress = $observer->getQuoteAddress();
$configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType();
// Restore initial customer group ID in quote only if VAT is calculated based on shipping address
if ($quoteAddress->hasPrevQuoteCustomerGroupId() && $configAddressType == \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING) {
$quoteAddress->getQuote()->setCustomerGroupId($quoteAddress->getPrevQuoteCustomerGroupId());
$quoteAddress->unsPrevQuoteCustomerGroupId();
}
}
示例2: isEnabled
/**
* Check whether VAT ID validation is enabled
*
* @param \Magento\Quote\Model\Quote\Address $quoteAddress
* @param \Magento\Store\Model\Store|int $store
* @return bool
*/
public function isEnabled(\Magento\Quote\Model\Quote\Address $quoteAddress, $store)
{
$configAddressType = $this->customerAddress->getTaxCalculationAddressType($store);
// When VAT is based on billing address then Magento have to handle only billing addresses
$additionalBillingAddressCondition = $configAddressType == \Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING ? $configAddressType != $quoteAddress->getAddressType() : false;
// Handle only addresses that corresponds to VAT configuration
if (!$this->customerAddress->isVatValidationEnabled($store) || $additionalBillingAddressCondition) {
return false;
}
return true;
}
示例3: testExecute
/**
* @param string|null $configAddressType
* @dataProvider restoreCustomerGroupIdDataProvider
*/
public function testExecute($configAddressType)
{
$quoteAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['getQuote', 'setCustomerGroupId', 'getPrevQuoteCustomerGroupId', 'unsPrevQuoteCustomerGroupId', 'hasPrevQuoteCustomerGroupId'], [], '', false);
$observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getQuoteAddress'], [], '', false);
$observer->expects($this->once())->method('getQuoteAddress')->will($this->returnValue($quoteAddress));
$this->customerAddressHelperMock->expects($this->once())->method('getTaxCalculationAddressType')->will($this->returnValue($configAddressType));
$quoteAddress->expects($this->once())->method('hasPrevQuoteCustomerGroupId');
$id = $quoteAddress->expects($this->any())->method('getPrevQuoteCustomerGroupId');
$quoteAddress->expects($this->any())->method('setCustomerGroupId')->with($id);
$quoteAddress->expects($this->any())->method('getQuote');
$quoteAddress->expects($this->any())->method('unsPrevQuoteCustomerGroupId');
$this->assertNull($this->quote->execute($observer));
}
示例4: _getVatRequiredSalesAddress
/**
* Retrieve sales address (order or quote) on which tax calculation must be based
*
* @param \Magento\Sales\Model\Order $order
* @param \Magento\Store\Model\Store|string|int|null $store
* @return \Magento\Sales\Model\Order\Address|null
*/
protected function _getVatRequiredSalesAddress($order, $store = null)
{
$configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType($store);
$requiredAddress = null;
switch ($configAddressType) {
case \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING:
$requiredAddress = $order->getShippingAddress();
break;
default:
$requiredAddress = $order->getBillingAddress();
break;
}
return $requiredAddress;
}
示例5: execute
/**
* Restore initial customer group ID in quote if needed on collect_totals_after event of quote address
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
/** @var ShippingAssignmentInterface $shippingAssignment */
$shippingAssignment = $observer->getEvent()->getShippingAssignment();
/** @var Quote $quote */
$quote = $observer->getEvent()->getQuote();
$address = $shippingAssignment->getShipping()->getAddress();
$configAddressType = $this->customerAddressHelper->getTaxCalculationAddressType();
// Restore initial customer group ID in quote only if VAT is calculated based on shipping address
if ($address->hasPrevQuoteCustomerGroupId() && $configAddressType == AbstractAddress::TYPE_SHIPPING) {
$quote->setCustomerGroupId($address->getPrevQuoteCustomerGroupId());
$address->unsPrevQuoteCustomerGroupId();
}
}
示例6: 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);
}
}
示例7: testAddVatRequestParamsOrderComment
/**
* @param string $configAddressType
* @param string|int $vatRequestId
* @param string|int $vatRequestDate
* @param string $orderHistoryComment
* @dataProvider addVatRequestParamsOrderCommentDataProvider
*/
public function testAddVatRequestParamsOrderComment($configAddressType, $vatRequestId, $vatRequestDate, $orderHistoryComment)
{
$this->customerAddressHelperMock->expects($this->once())->method('getTaxCalculationAddressType')->will($this->returnValue($configAddressType));
$orderAddressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['getVatRequestId', 'getVatRequestDate', '__wakeup'], [], '', false);
$orderAddressMock->expects($this->any())->method('getVatRequestId')->will($this->returnValue($vatRequestId));
$orderAddressMock->expects($this->any())->method('getVatRequestDate')->will($this->returnValue($vatRequestDate));
$orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['getShippingAddress', '__wakeup', 'addStatusHistoryComment', 'getBillingAddress'])->getMock();
$orderMock->expects($this->any())->method('getShippingAddress')->will($this->returnValue($orderAddressMock));
if ($orderHistoryComment === null) {
$orderMock->expects($this->never())->method('addStatusHistoryComment');
} else {
$orderMock->expects($this->once())->method('addStatusHistoryComment')->with($orderHistoryComment, false);
}
$observer = $this->getMock('Magento\\Framework\\Event\\Observer', ['getOrder'], [], '', false);
$observer->expects($this->once())->method('getOrder')->will($this->returnValue($orderMock));
$this->assertNull($this->observer->execute($observer));
}
示例8: getAddressAsString
/**
* Represent customer address in 'online' format.
*
* @param \Magento\Customer\Api\Data\AddressInterface $address
* @return string
*/
public function getAddressAsString(\Magento\Customer\Api\Data\AddressInterface $address)
{
$formatTypeRenderer = $this->_addressHelper->getFormatTypeRenderer('oneline');
$result = '';
if ($formatTypeRenderer) {
$result = $formatTypeRenderer->renderArray($this->addressMapper->toFlatArray($address));
}
return $this->escapeHtml($result);
}
示例9: testGetFormat
/**
* @param string $code
* @param array $result
* @dataProvider getFormatDataProvider
*/
public function testGetFormat($code, $result)
{
if ($result) {
$renderer = $this->getMockBuilder('Magento\\Customer\\Block\\Address\\Renderer\\RendererInterface')->disableOriginalConstructor()->getMock();
$renderer->expects($this->once())->method('getFormatArray')->will($this->returnValue(array('key' => 'value')));
}
$this->addressConfig->expects($this->once())->method('getFormatByCode')->with($code)->will($this->returnValue(new \Magento\Framework\Object(!empty($result) ? array('renderer' => $renderer) : array())));
$this->assertEquals($result, $this->helper->getFormat($code));
}
示例10: getStreetFieldConfig
/**
* Retrieve field configuration for street address attribute
*
* @param string $attributeCode
* @param array $attributeConfig
* @param string $providerName name of the storage container used by UI component
* @param string $dataScopePrefix
* @return array
*/
protected function getStreetFieldConfig($attributeCode, array $attributeConfig, $providerName, $dataScopePrefix)
{
$streetLines = [];
for ($lineIndex = 0; $lineIndex < $this->addressHelper->getStreetLines(); $lineIndex++) {
$isFirstLine = $lineIndex === 0;
$streetLines[] = ['component' => 'Magento_Ui/js/form/element/abstract', 'config' => ['customScope' => $dataScopePrefix, 'template' => 'ui/form/field', 'elementTmpl' => 'ui/form/element/input'], 'dataScope' => $lineIndex, 'provider' => $providerName, 'validation' => $isFirstLine ? ['required-entry' => true] : [], 'additionalClasses' => $isFirstLine ?: 'additional'];
}
return ['component' => 'Magento_Ui/js/form/components/group', 'label' => __('Address'), 'required' => true, 'dataScope' => $dataScopePrefix . '.' . $attributeCode, 'provider' => $providerName, 'sortOrder' => $attributeConfig['sortOrder'], 'type' => 'group', 'config' => ['template' => 'ui/group/group', 'additionalClasses' => 'street'], 'children' => $streetLines];
}
示例11: getBillingAddressHtml
/**
* @return string|null
*/
public function getBillingAddressHtml()
{
try {
$address = $this->_addressService->getAddress($this->getCustomer()->getDefaultBilling());
} catch (NoSuchEntityException $e) {
return __('The customer does not have default billing address.');
}
return $this->_addressHelper->getFormatTypeRenderer('html')->renderArray(AddressConverter::toFlatArray($address));
}
示例12: _getBillingAddress
/**
* Get billing address request data
*
* @param \Magento\Framework\Object $address
* @return array
*/
protected function _getBillingAddress(\Magento\Framework\Object $address)
{
$request = array('billing_first_name' => $address->getFirstname(), 'billing_last_name' => $address->getLastname(), 'billing_city' => $address->getCity(), 'billing_state' => $address->getRegionCode() ? $address->getRegionCode() : $address->getCity(), 'billing_zip' => $address->getPostcode(), 'billing_country' => $address->getCountry());
// convert streets to tow lines format
$street = $this->_customerAddress->convertStreetLines($address->getStreet(), 2);
$request['billing_address1'] = isset($street[0]) ? $street[0] : '';
$request['billing_address2'] = isset($street[1]) ? $street[1] : '';
return $request;
}
示例13: getAddressAsHtml
/**
* Represent customer address in HTML format.
*
* @param \Magento\Customer\Api\Data\AddressInterface $address
* @return string
*/
public function getAddressAsHtml(\Magento\Customer\Api\Data\AddressInterface $address)
{
$formatTypeRenderer = $this->_customerAddressHelper->getFormatTypeRenderer('html');
$result = '';
if ($formatTypeRenderer) {
$result = $formatTypeRenderer->renderArray($this->addressMapper->toFlatArray($address));
}
return $result;
}
示例14: getAddressAsString
/**
* Represent customer address in 'online' format.
*
* @param \Magento\Customer\Service\V1\Data\Address $addressData
* @return string
*/
public function getAddressAsString($addressData)
{
$formatTypeRenderer = $this->_addressHelper->getFormatTypeRenderer('oneline');
$result = '';
if ($formatTypeRenderer) {
$result = $formatTypeRenderer->renderArray(AddressConverter::toFlatArray($addressData));
}
return $this->escapeHtml($result);
}
示例15: getAddressAsHtml
/**
* Represent customer address in HTML format.
*
* @param \Magento\Customer\Service\V1\Data\Address $addressData
* @return string
*/
public function getAddressAsHtml($addressData)
{
$formatTypeRenderer = $this->_customerAddressHelper->getFormatTypeRenderer('html');
$result = '';
if ($formatTypeRenderer) {
$result = $formatTypeRenderer->renderArray(AddressConverter::toFlatArray($addressData));
}
return $result;
}