diff --git a/app/code/Magento/Bundle/Model/Product/Type.php b/app/code/Magento/Bundle/Model/Product/Type.php index a3484d081f64b..3d08530aedd21 100644 --- a/app/code/Magento/Bundle/Model/Product/Type.php +++ b/app/code/Magento/Bundle/Model/Product/Type.php @@ -636,6 +636,12 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p if (!empty($selectionIds)) { $selections = $this->getSelectionsByIds($selectionIds, $product); + if (count($selections->getItems()) !== count($selectionIds)) { + throw new \Magento\Framework\Exception\LocalizedException( + __('The options you selected are not available.') + ); + } + // Check if added selections are still on sale $this->checkSelectionsIsSale( $selections, @@ -808,12 +814,6 @@ public function getSelectionsByIds($selectionIds, $product) ->addFilterByRequiredOptions() ->setSelectionIdsFilter($selectionIds); - if (count($usedSelections->getItems()) !== count($selectionIds)) { - throw new \Magento\Framework\Exception\LocalizedException( - __('The options you selected are not available.') - ); - } - if (!$this->_catalogData->isPriceGlobal() && $storeId) { $websiteId = $this->_storeManager->getStore($storeId) ->getWebsiteId(); diff --git a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php index 2b41f1ccf12a9..f834c9bab3c21 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php @@ -232,7 +232,7 @@ function ($key) use ($optionCollection, $selectionCollection) { ->willReturn('options'); $option->expects($this->at(3)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->once()) ->method('getRequired') ->willReturn(true); @@ -379,7 +379,7 @@ function ($key) use ($optionCollection, $selectionCollection) { $resultValue = $selectionCollection; break; case '_cache_instance_used_selections_ids': - $resultValue = [2, 5, 14]; + $resultValue = [5]; break; } @@ -404,7 +404,7 @@ function ($key) use ($optionCollection, $selectionCollection) { ->method('setStoreFilter'); $buyRequest->expects($this->once()) ->method('getBundleOption') - ->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]); + ->willReturn([3 => 5]); $selectionCollection->expects($this->any()) ->method('getItems') ->willReturn([$selection]); @@ -433,13 +433,13 @@ function ($key) use ($optionCollection, $selectionCollection) { ->willReturn($productType); $option->expects($this->at(3)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->at(9)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->once()) ->method('getRequired') - ->willReturn(true); + ->willReturn(false); $option->expects($this->once()) ->method('isMultiSelection') ->willReturn(true); @@ -611,7 +611,7 @@ function ($key) use ($optionCollection, $selectionCollection) { $resultValue = $selectionCollection; break; case '_cache_instance_used_selections_ids': - $resultValue = [2, 5, 14]; + $resultValue = [5]; break; } @@ -636,7 +636,7 @@ function ($key) use ($optionCollection, $selectionCollection) { ->method('setStoreFilter'); $buyRequest->expects($this->once()) ->method('getBundleOption') - ->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]); + ->willReturn([3 => 5]); $selectionCollection->expects($this->any()) ->method('getItems') ->willReturn([$selection]); @@ -665,13 +665,13 @@ function ($key) use ($optionCollection, $selectionCollection) { ->willReturn($productType); $option->expects($this->at(3)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->at(9)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->once()) ->method('getRequired') - ->willReturn(true); + ->willReturn(false); $option->expects($this->once()) ->method('isMultiSelection') ->willReturn(true); @@ -831,7 +831,7 @@ function ($key) use ($optionCollection, $selectionCollection) { $resultValue = $selectionCollection; break; case '_cache_instance_used_selections_ids': - $resultValue = [2, 5, 14]; + $resultValue = [5]; break; } @@ -856,7 +856,7 @@ function ($key) use ($optionCollection, $selectionCollection) { ->method('setStoreFilter'); $buyRequest->expects($this->once()) ->method('getBundleOption') - ->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]); + ->willReturn([3 => 5]); $selectionCollection->expects($this->any()) ->method('getItems') ->willReturn([$selection]); @@ -885,13 +885,13 @@ function ($key) use ($optionCollection, $selectionCollection) { ->willReturn($productType); $option->expects($this->at(3)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->at(9)) ->method('getId') - ->willReturn(10); + ->willReturn(3); $option->expects($this->once()) ->method('getRequired') - ->willReturn(true); + ->willReturn(false); $option->expects($this->once()) ->method('isMultiSelection') ->willReturn(true); @@ -1118,41 +1118,29 @@ function ($key) use ($optionCollection, $selectionCollection) { $resultValue = $selectionCollection; break; case '_cache_instance_used_selections_ids': - $resultValue = [2, 5, 14]; + $resultValue = [5]; break; } return $resultValue; } ); - $optionCollection->expects($this->once()) - ->method('getItemById') - ->willReturn($option); $optionCollection->expects($this->once()) ->method('appendSelections'); $productType->expects($this->once()) ->method('setStoreFilter'); $buyRequest->expects($this->once()) ->method('getBundleOption') - ->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]); + ->willReturn([3 => 5]); $selectionCollection->expects($this->at(0)) ->method('getItems') ->willReturn([$selection]); $selectionCollection->expects($this->at(1)) ->method('getItems') ->willReturn([]); - $selection->expects($this->once()) - ->method('isSalable') - ->willReturn(false); - $option->expects($this->at(3)) + $option->expects($this->any()) ->method('getId') - ->willReturn(10); - $option->expects($this->once()) - ->method('getRequired') - ->willReturn(true); - $option->expects($this->once()) - ->method('isMultiSelection') - ->willReturn(true); + ->willReturn(3); $result = $this->model->prepareForCartAdvanced($buyRequest, $product); $this->assertEquals('Please specify product option(s).', $result); @@ -1262,7 +1250,7 @@ function ($key) use ($optionCollection, $selectionCollection) { $buyRequest->expects($this->once()) ->method('getBundleOption') ->willReturn([3 => 5]); - $selectionCollection->expects($this->once()) + $selectionCollection->expects($this->any()) ->method('getItems') ->willReturn([$selection]); $selection->expects($this->once()) @@ -1921,8 +1909,7 @@ public function testGetSelectionsByIds() 'setPositionOrder', 'addFilterByRequiredOptions', 'setSelectionIdsFilter', - 'joinPrices', - 'getItems' + 'joinPrices' ] ) ->disableOriginalConstructor() @@ -1991,9 +1978,6 @@ public function testGetSelectionsByIds() ->method('setSelectionIdsFilter') ->with($selectionIds) ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('getItems') - ->willReturn($usedSelectionsIds); $usedSelectionsMock->expects($this->once()) ->method('joinPrices') @@ -2007,96 +1991,6 @@ public function testGetSelectionsByIds() $this->model->getSelectionsByIds($selectionIds, $productMock); } - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - * @expectedExceptionMessage The options you selected are not available. - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testGetSelectionsByIdsException() - { - $selectionIds = [1, 2, 3]; - $usedSelectionsIds = [4, 5]; - $storeId = 2; - $storeFilter = 'store_filter'; - $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') - ->disableOriginalConstructor() - ->getMock(); - $usedSelectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection') - ->setMethods( - [ - 'addAttributeToSelect', - 'setFlag', - 'addStoreFilter', - 'setStoreId', - 'setPositionOrder', - 'addFilterByRequiredOptions', - 'setSelectionIdsFilter', - 'joinPrices', - 'getItems' - ] - ) - ->disableOriginalConstructor() - ->getMock(); - $productGetMap = [ - ['_cache_instance_used_selections', null, null], - ['_cache_instance_used_selections_ids', null, $usedSelectionsIds], - ['_cache_instance_store_filter', null, $storeFilter], - ]; - $productMock->expects($this->any()) - ->method('getData') - ->will($this->returnValueMap($productGetMap)); - $productSetMap = [ - ['_cache_instance_used_selections', $usedSelectionsMock, $productMock], - ['_cache_instance_used_selections_ids', $selectionIds, $productMock], - ]; - $productMock->expects($this->any()) - ->method('setData') - ->will($this->returnValueMap($productSetMap)); - $productMock->expects($this->once()) - ->method('getStoreId') - ->will($this->returnValue($storeId)); - - $this->bundleCollection->expects($this->once()) - ->method('create') - ->will($this->returnValue($usedSelectionsMock)); - - $usedSelectionsMock->expects($this->once()) - ->method('addAttributeToSelect') - ->with('*') - ->will($this->returnSelf()); - $flagMap = [ - ['require_stock_items', true, $usedSelectionsMock], - ['product_children', true, $usedSelectionsMock], - ]; - $usedSelectionsMock->expects($this->any()) - ->method('setFlag') - ->will($this->returnValueMap($flagMap)); - $usedSelectionsMock->expects($this->once()) - ->method('addStoreFilter') - ->with($storeFilter) - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setStoreId') - ->with($storeId) - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setPositionOrder') - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('addFilterByRequiredOptions') - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('setSelectionIdsFilter') - ->with($selectionIds) - ->will($this->returnSelf()); - $usedSelectionsMock->expects($this->once()) - ->method('getItems') - ->willReturn($usedSelectionsIds); - - - $this->model->getSelectionsByIds($selectionIds, $productMock); - } /** * @return void */ diff --git a/app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php b/app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php index 819693334aa20..c9b60879c9dfe 100644 --- a/app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php +++ b/app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php @@ -109,6 +109,7 @@ public function process($jsLayout) $fieldSetPointer = &$jsLayout['components']['block-summary']['children']['block-shipping'] ['children']['address-fieldsets']['children']; $fieldSetPointer = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fieldSetPointer); + $fieldSetPointer['region_id']['config']['skipValidation'] = true; } return $jsLayout; } diff --git a/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php b/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php index 81ff1b2fd4382..b31d21906b4b5 100644 --- a/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php +++ b/app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php @@ -7,6 +7,7 @@ namespace Magento\Checkout\Model; use Magento\Quote\Api\CartRepositoryInterface; +use Magento\Framework\Exception\CouldNotSaveException; class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPaymentInformationManagementInterface { @@ -76,7 +77,12 @@ public function savePaymentInformationAndPlaceOrder( \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress); - return $this->cartManagement->placeOrder($cartId); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (\Exception $e) { + throw new CouldNotSaveException(__('Cannot place order'), $e); + } + return $orderId; } /** diff --git a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php index 54fe9c13bd4df..018fed2f513ac 100644 --- a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php +++ b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php @@ -3,12 +3,12 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\Checkout\Model; +use Magento\Framework\Exception\CouldNotSaveException; + class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInformationManagementInterface { - /** * @var \Magento\Quote\Api\BillingAddressManagementInterface */ @@ -67,7 +67,12 @@ public function savePaymentInformationAndPlaceOrder( \Magento\Quote\Api\Data\AddressInterface $billingAddress = null ) { $this->savePaymentInformation($cartId, $paymentMethod, $billingAddress); - return $this->cartManagement->placeOrder($cartId); + try { + $orderId = $this->cartManagement->placeOrder($cartId); + } catch (\Exception $e) { + throw new CouldNotSaveException(__('Cannot place order'), $e); + } + return $orderId; } /** diff --git a/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php index a5e0a6ce00ecc..e838ab9c80304 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Checkout\Test\Unit\Model; +use Magento\Framework\Exception\CouldNotSaveException; + class GuestPaymentInformationManagementTest extends \PHPUnit_Framework_TestCase { /** @@ -90,6 +92,29 @@ public function testSavePaymentInformationAndPlaceOrder() ); } + /** + * @expectedExceptionMessage Cannot place order + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testSavePaymentInformationAndPlaceOrderException() + { + $cartId = 100; + $email = 'email@magento.com'; + $paymentMock = $this->getMock('\Magento\Quote\Api\Data\PaymentInterface'); + $billingAddressMock = $this->getMock('\Magento\Quote\Api\Data\AddressInterface'); + + $billingAddressMock->expects($this->once())->method('setEmail')->with($email)->willReturnSelf(); + + $this->billingAddressManagementMock->expects($this->once()) + ->method('assign') + ->with($cartId, $billingAddressMock); + $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); + $exception = new CouldNotSaveException(__('DB exception')); + $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException($exception); + + $this->model->savePaymentInformationAndPlaceOrder($cartId, $email, $paymentMock, $billingAddressMock); + } + public function testSavePaymentInformation() { $cartId = 100; diff --git a/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php b/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php index 925fed1484b0e..008d573a8fc2e 100644 --- a/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php +++ b/app/code/Magento/Checkout/Test/Unit/Model/PaymentInformationManagementTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Checkout\Test\Unit\Model; +use Magento\Framework\Exception\CouldNotSaveException; + class PaymentInformationManagementTest extends \PHPUnit_Framework_TestCase { /** @@ -67,6 +69,26 @@ public function testSavePaymentInformationAndPlaceOrder() ); } + /** + * @expectedExceptionMessage Cannot place order + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testSavePaymentInformationAndPlaceOrderException() + { + $cartId = 100; + $paymentMock = $this->getMock('\Magento\Quote\Api\Data\PaymentInterface'); + $billingAddressMock = $this->getMock('\Magento\Quote\Api\Data\AddressInterface'); + + $this->billingAddressManagementMock->expects($this->once()) + ->method('assign') + ->with($cartId, $billingAddressMock); + $this->paymentMethodManagementMock->expects($this->once())->method('set')->with($cartId, $paymentMock); + $exception = new CouldNotSaveException(__('DB exception')); + $this->cartManagementMock->expects($this->once())->method('placeOrder')->willThrowException($exception); + + $this->model->savePaymentInformationAndPlaceOrder($cartId, $paymentMock, $billingAddressMock); + } + public function testSavePaymentInformationAndPlaceOrderIfBillingAddressNotExist() { $cartId = 100; diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml index da3abaada38c7..2154558f09ce4 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml @@ -86,7 +86,7 @@ checkoutProvider - Magento_Ui/js/form/element/select + Magento_Ui/js/form/element/region 112 ui/form/field diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js index a3f7e273100c6..4701d943a93d3 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/new-customer-address.js @@ -40,7 +40,7 @@ define([], function() { return addressData.default_billing; }, getType: function() { - return 'new-customer-address' + return 'new-customer-address'; }, getKey: function() { return this.getType(); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js index 0bca684b800ee..2ee067fcc0ec5 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js @@ -284,9 +284,14 @@ define( if (addressData.hasOwnProperty(field) && shippingAddress.hasOwnProperty(field) && - typeof addressData[field] != 'function' + typeof addressData[field] != 'function' && + _.isEqual(shippingAddress[field], addressData[field]) ) { shippingAddress[field] = addressData[field]; + } else if (typeof addressData[field] != 'function' && + !_.isEqual(shippingAddress[field], addressData[field])) { + shippingAddress = addressData; + break; } } diff --git a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php index eaeb4cc9be636..3d6a159bf906f 100644 --- a/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php +++ b/app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php @@ -234,11 +234,14 @@ public function toOptionArray($emptyLabel = ' ') unset($sort[$name]); $sort = [$name => $foregroundCountry] + $sort; } + $isRegionVisible = (bool)$this->helperData->isShowNonRequiredState(); $options = []; foreach ($sort as $label => $value) { $option = ['value' => $value, 'label' => $label]; if ($this->helperData->isRegionRequired($value)) { $option['is_region_required'] = true; + } else { + $option['is_region_visible'] = $isRegionVisible; } if ($this->helperData->isZipCodeOptional($value)) { $option['is_zipcode_optional'] = true; diff --git a/app/code/Magento/GiftMessage/Model/CartRepository.php b/app/code/Magento/GiftMessage/Model/CartRepository.php index 760c47eef5cf5..c5b9281f78f58 100644 --- a/app/code/Magento/GiftMessage/Model/CartRepository.php +++ b/app/code/Magento/GiftMessage/Model/CartRepository.php @@ -101,11 +101,11 @@ public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $gi $quote = $this->quoteRepository->getActive($cartId); if (0 == $quote->getItemsCount()) { - throw new InputException(__('Gift Messages is not applicable for empty cart')); + throw new InputException(__('Gift Messages are not applicable for empty cart')); } if ($quote->isVirtual()) { - throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); + throw new InvalidTransitionException(__('Gift Messages are not applicable for virtual products')); } $messageText = $giftMessage->getMessage(); if ($messageText && !$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) { diff --git a/app/code/Magento/GiftMessage/Model/ItemRepository.php b/app/code/Magento/GiftMessage/Model/ItemRepository.php index d7ebf051a1c8f..687a538d38639 100644 --- a/app/code/Magento/GiftMessage/Model/ItemRepository.php +++ b/app/code/Magento/GiftMessage/Model/ItemRepository.php @@ -119,7 +119,7 @@ public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $gi }; if ($item->getIsVirtual()) { - throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); + throw new InvalidTransitionException(__('Gift Messages are not applicable for virtual products')); } $messageText = $giftMessage->getMessage(); if ($messageText && !$this->helper->isMessagesAllowed('items', $quote, $this->storeManager->getStore())) { diff --git a/app/code/Magento/GiftMessage/Model/OrderItemRepository.php b/app/code/Magento/GiftMessage/Model/OrderItemRepository.php index 4c71f599f0b1f..52218a5c43905 100644 --- a/app/code/Magento/GiftMessage/Model/OrderItemRepository.php +++ b/app/code/Magento/GiftMessage/Model/OrderItemRepository.php @@ -110,7 +110,7 @@ public function save($orderId, $orderItemId, \Magento\GiftMessage\Api\Data\Messa }; if ($order->getIsVirtual()) { - throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); + throw new InvalidTransitionException(__('Gift Messages are not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); diff --git a/app/code/Magento/GiftMessage/Model/OrderRepository.php b/app/code/Magento/GiftMessage/Model/OrderRepository.php index 5bbff94c44bf9..d1702055eab8a 100644 --- a/app/code/Magento/GiftMessage/Model/OrderRepository.php +++ b/app/code/Magento/GiftMessage/Model/OrderRepository.php @@ -107,11 +107,11 @@ public function save($orderId, \Magento\GiftMessage\Api\Data\MessageInterface $g }; if (0 == $order->getTotalItemCount()) { - throw new InputException(__('Gift Messages is not applicable for empty order')); + throw new InputException(__('Gift Messages are not applicable for empty order')); } if ($order->getIsVirtual()) { - throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); + throw new InvalidTransitionException(__('Gift Messages are not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('order', $order, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php index 598861b2f4a0b..2076fc56e31eb 100644 --- a/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php +++ b/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php @@ -147,7 +147,7 @@ public function testGet() /** * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Gift Messages is not applicable for empty cart + * @expectedExceptionMessage Gift Messages are not applicable for empty cart */ public function testSaveWithInputException() { @@ -158,7 +158,7 @@ public function testSaveWithInputException() /** * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException - * @expectedExceptionMessage Gift Messages is not applicable for virtual products + * @expectedExceptionMessage Gift Messages are not applicable for virtual products */ public function testSaveWithInvalidTransitionException() { diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/GuestItemRepositoryTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/GuestItemRepositoryTest.php index 8d9f37ee941d3..7150d06342023 100644 --- a/app/code/Magento/GiftMessage/Test/Unit/Model/GuestItemRepositoryTest.php +++ b/app/code/Magento/GiftMessage/Test/Unit/Model/GuestItemRepositoryTest.php @@ -184,7 +184,7 @@ public function testSaveWithNoSuchEntityException() /** * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException - * @expectedExceptionMessage Gift Messages is not applicable for virtual products + * @expectedExceptionMessage Gift Messages are not applicable for virtual products */ public function testSaveWithInvalidTransitionException() { diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php index 69e55c905fc3d..8dfcc1ad3b01e 100644 --- a/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php +++ b/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php @@ -184,7 +184,7 @@ public function testSaveWithNoSuchEntityException() /** * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException - * @expectedExceptionMessage Gift Messages is not applicable for virtual products + * @expectedExceptionMessage Gift Messages are not applicable for virtual products */ public function testSaveWithInvalidTransitionException() { diff --git a/app/code/Magento/Ui/view/base/web/js/form/element/region.js b/app/code/Magento/Ui/view/base/web/js/form/element/region.js index 2d85cafb4df55..4c611a1a70fca 100644 --- a/app/code/Magento/Ui/view/base/web/js/form/element/region.js +++ b/app/code/Magento/Ui/view/base/web/js/form/element/region.js @@ -12,6 +12,7 @@ define([ return Select.extend({ defaults: { + skipValidation: false, imports: { update: '${ $.parentName }.country_id:value' } @@ -31,14 +32,43 @@ define([ option = options[value]; - if (!option['is_region_required']) { - this.error(false); - this.validation = _.omit(this.validation, 'required-entry'); + if (this.skipValidation) { + this.validation['required-entry'] = false; + this.required(false); } else { - this.validation['required-entry'] = true; + if (!option['is_region_required']) { + this.error(false); + this.validation = _.omit(this.validation, 'required-entry'); + } else { + this.validation['required-entry'] = true; + } + + this.required(!!option['is_region_required']); } + }, + + /** + * Filters 'initialOptions' property by 'field' and 'value' passed, + * calls 'setOptions' passing the result to it + * + * @param {*} value + * @param {String} field + */ + filter: function (value, field) { + var country = registry.get(this.parentName + '.' + 'country_id'), + option = country.indexedOptions[value]; + + this._super(value, field); + + if (option && option['is_region_visible'] === false) { + // hide select and corresponding text input field if region must not be shown for selected country + this.setVisible(false); - this.required(!!option['is_region_required']); + if (this.customEntry) { + this.toggleInput(false); + } + } } }); }); + diff --git a/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderItemRepositoryTest.php b/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderItemRepositoryTest.php index 18532c48952e4..bde6cab3c0ce8 100644 --- a/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderItemRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderItemRepositoryTest.php @@ -125,7 +125,7 @@ public function testSaveMessageIsNotAvailable() * @magentoDataFixture Magento/GiftMessage/_files/virtual_order.php * @magentoConfigFixture default_store sales/gift_options/allow_items 1 * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException - * @expectedExceptionMessage Gift Messages is not applicable for virtual products + * @expectedExceptionMessage Gift Messages are not applicable for virtual products */ public function testSaveMessageIsVirtual() { diff --git a/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderRepositoryTest.php b/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderRepositoryTest.php index f47174a49cf26..4812ae62f0cf3 100644 --- a/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/GiftMessage/Model/OrderRepositoryTest.php @@ -90,7 +90,7 @@ public function testSaveMessageIsNotAvailable() * @magentoDataFixture Magento/GiftMessage/_files/virtual_order.php * @magentoConfigFixture default_store sales/gift_options/allow_order 1 * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException - * @expectedExceptionMessage Gift Messages is not applicable for virtual products + * @expectedExceptionMessage Gift Messages are not applicable for virtual products */ public function testSaveMessageIsVirtual() { @@ -105,7 +105,7 @@ public function testSaveMessageIsVirtual() * @magentoDataFixture Magento/GiftMessage/_files/empty_order.php * @magentoConfigFixture default_store sales/gift_options/allow_order 1 * @expectedException \Magento\Framework\Exception\InputException - * @expectedExceptionMessage Gift Messages is not applicable for empty order + * @expectedExceptionMessage Gift Messages are not applicable for empty order */ public function testSaveMessageIsEmpty() {