diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js index 6cc7849683a39..ead5e9fd32cf6 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js @@ -1,6 +1,6 @@ /** - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. + * Copyright 2014 Adobe + * All Rights Reserved. */ /** @@ -84,6 +84,11 @@ define([ $.each(elements, function (index, field) { uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self)); }); + let regionId = uiRegistry.async(formPath + '.region_id'); + + if (regionId() !== undefined) { + this.bindHandler(regionId(), self.validateDelay); + } }, /** diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php index 034c9c10269e0..f70ac358f7ce3 100644 --- a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php +++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php @@ -1,8 +1,9 @@ customerAddressFactory->create(); - $customerAddress->setCountryId($address->getCountryId()); - $customerAddress->setRegion( - $this->customerAddressRegionFactory->create()->setRegionId($address->getRegionId()) + $region = $this->customerAddressRegionFactory->create( + [ + 'data' => [ + 'region_id' => $address->getRegionId(), + 'region_code' => $address->getRegionCode(), + 'region' => $address->getRegion() + ] + ] ); - $customerAddress->setPostcode($address->getPostcode()); - $customerAddress->setCity($address->getCity()); - $customerAddress->setStreet($address->getStreet()); - return $customerAddress; + return $this->customerAddressFactory->create( + [ + 'data' => [ + 'country_id' => $address->getCountryId(), + 'region' => $region, + 'postcode' => $address->getPostcode(), + 'city' => $address->getCity(), + 'street' => $address->getStreet() + ] + ] + ); } /** diff --git a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php index 58c048fd771ec..892e535377f50 100644 --- a/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php +++ b/app/code/Magento/Tax/Test/Unit/Model/Sales/Total/Quote/CommonTaxCollectorTest.php @@ -1,13 +1,17 @@ taxConfig = $this->getMockBuilder(Config::class) ->disableOriginalConstructor() ->onlyMethods(['getShippingTaxClass', 'shippingPriceIncludesTax', 'discountTax']) @@ -117,8 +154,13 @@ protected function setUp(): void ->method('getQuote') ->willReturn($this->quote); $methods = ['create']; - $this->quoteDetailsItemDataObject = $objectManager->getObject(ItemDetails::class); - $this->taxClassKeyDataObject = $objectManager->getObject(TaxClassKey::class); + $this->quoteDetailsItemDataObject = $this->createMock(ItemDetails::class); + $this->quoteDetailsItemDataObject->method('setType')->willReturnSelf(); + $this->quoteDetailsItemDataObject->method('setCode')->willReturnSelf(); + $this->quoteDetailsItemDataObject->method('setQuantity')->willReturnSelf(); + $this->taxClassKeyDataObject = $this->createMock(TaxClassKey::class); + $this->taxClassKeyDataObject->method('setType')->willReturnSelf(); + $this->taxClassKeyDataObject->method('setValue')->willReturnSelf(); $this->quoteDetailsItemDataObjectFactoryMock = $this->createPartialMock(QuoteDetailsItemInterfaceFactory::class, $methods); $this->quoteDetailsItemDataObjectFactoryMock @@ -132,15 +174,78 @@ protected function setUp(): void $this->taxHelper = $this->getMockBuilder(TaxHelper::class) ->disableOriginalConstructor() ->getMock(); - $this->commonTaxCollector = $objectManager->getObject( - CommonTaxCollector::class, - [ - 'taxConfig' => $this->taxConfig, - 'quoteDetailsItemDataObjectFactory' => $this->quoteDetailsItemDataObjectFactoryMock, - 'taxClassKeyDataObjectFactory' => $this->taxClassKeyDataObjectFactoryMock, - 'taxHelper' => $this->taxHelper, - ] + $this->taxCalculation = $this->createMock(TaxCalculationInterface::class); + $this->quoteDetailsFactory = $this->createMock(QuoteDetailsInterfaceFactory::class); + $this->addressFactory = $this->createMock(AddressInterfaceFactory::class); + $this->regionFactory = $this->createMock(RegionInterfaceFactory::class); + $this->quoteDetailsItemExtensionFactory = $this->createMock(QuoteDetailsItemExtensionInterfaceFactory::class); + $this->accountManagement = $this->createMock(AccountManagementInterface::class); + $this->commonTaxCollector = new CommonTaxCollector( + $this->taxConfig, + $this->taxCalculation, + $this->quoteDetailsFactory, + $this->quoteDetailsItemDataObjectFactoryMock, + $this->taxClassKeyDataObjectFactoryMock, + $this->addressFactory, + $this->regionFactory, + $this->taxHelper, + $this->quoteDetailsItemExtensionFactory, + $this->accountManagement ); + + parent::setUp(); + } + + /** + * @return void + * @throws Exception + */ + public function testMapAddress(): void + { + $countryId = 1; + $regionId = 2; + $regionCode = 'regionCode'; + $region = 'region'; + $postCode = 'postCode'; + $city = 'city'; + $street = ['street']; + + $address = $this->createMock(QuoteAddress::class); + $address->expects($this->once())->method('getCountryId')->willReturn($countryId); + $address->expects($this->once())->method('getRegionId')->willReturn($regionId); + $address->expects($this->once())->method('getRegionCode')->willReturn($regionCode); + $address->expects($this->once())->method('getRegion')->willReturn($region); + $address->expects($this->once())->method('getPostcode')->willReturn($postCode); + $address->expects($this->once())->method('getCity')->willReturn($city); + $address->expects($this->once())->method('getStreet')->willReturn($street); + + $regionData = [ + 'data' => [ + 'region_id' => $regionId, + 'region_code' => $regionCode, + 'region' => $region, + ] + ]; + $regionObject = $this->createMock(RegionInterface::class); + $this->regionFactory->expects($this->once())->method('create')->with($regionData)->willReturn($regionObject); + $customerAddress = $this->createMock(AddressInterface::class); + + $this->addressFactory->expects($this->once()) + ->method('create') + ->with( + [ + 'data' => [ + 'country_id' => $countryId, + 'region' => $regionObject, + 'postcode' => $postCode, + 'city' => $city, + 'street' => $street + ] + ] + ) + ->willReturn($customerAddress); + + $this->assertSame($customerAddress, $this->commonTaxCollector->mapAddress($address)); } /** @@ -153,12 +258,13 @@ protected function setUp(): void * * @return void * @dataProvider getShippingDataObjectDataProvider + * @throws Exception */ public function testGetShippingDataObject( array $addressData, - $useBaseCurrency, - $shippingTaxClass, - $shippingPriceInclTax + bool $useBaseCurrency, + string $shippingTaxClass, + bool $shippingPriceInclTax ): void { $shippingAssignmentMock = $this->getMockForAbstractClass(ShippingAssignmentInterface::class); /** @var MockObject|QuoteAddressTotal $totalsMock */ @@ -201,10 +307,8 @@ public function testGetShippingDataObject( ->expects($this->once()) ->method('getBaseShippingDiscountAmount') ->willReturn($baseShippingAmount); - $expectedDiscountAmount = $baseShippingAmount; } else { $totalsMock->expects($this->never())->method('getBaseShippingDiscountAmount'); - $expectedDiscountAmount = $shippingAmount; } } foreach ($addressData as $key => $value) { @@ -214,10 +318,6 @@ public function testGetShippingDataObject( $this->quoteDetailsItemDataObject, $this->commonTaxCollector->getShippingDataObject($shippingAssignmentMock, $totalsMock, $useBaseCurrency) ); - - if ($shippingAmount) { - $this->assertEquals($expectedDiscountAmount, $this->quoteDetailsItemDataObject->getDiscountAmount()); - } } /**