diff --git a/app/code/Magento/Customer/Model/Resource/GroupRepository.php b/app/code/Magento/Customer/Model/Resource/GroupRepository.php index 73b59ff2dd1e54166d149019ae8585076b46b37d..fe0d52ca471ef7a45f563a5529657d4a189a2b03 100644 --- a/app/code/Magento/Customer/Model/Resource/GroupRepository.php +++ b/app/code/Magento/Customer/Model/Resource/GroupRepository.php @@ -164,6 +164,7 @@ class GroupRepository implements \Magento\Customer\Api\GroupRepositoryInterface /** @var \Magento\Customer\Model\Resource\Group\Collection $collection */ $collection = $this->groupFactory->create()->getCollection(); + $collection->addTaxClass(); //Add filters from root filter group to the collection /** @var FilterGroup $group */ @@ -234,6 +235,8 @@ class GroupRepository implements \Magento\Customer\Api\GroupRepositoryInterface return 'customer_group_code'; case GroupInterface::ID: return 'customer_group_id'; + case GroupInterface::TAX_CLASS_NAME: + return 'class_name'; default: return $field; } diff --git a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php index 29adf1a01cca112fc6833837accaef7d1c3864ad..efc9e86abe834e477cb21e77577a6f4358f88fc3 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php @@ -171,7 +171,7 @@ class PersonalInfoTest extends \PHPUnit_Framework_TestCase 'customer/online_customers/online_minutes_interval', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) - ->willReturn(60); //TODO: it's value mocked because unit tests run data providers before all testsuite + ->willReturn(240); //TODO: it's value mocked because unit tests run data providers before all testsuite $this->customerLog->expects($this->any())->method('getLastLoginAt')->willReturn($lastLoginAt); $this->customerLog->expects($this->any())->method('getLastVisitAt')->willReturn($lastVisitAt); diff --git a/app/code/Magento/Wishlist/Controller/Index/Cart.php b/app/code/Magento/Wishlist/Controller/Index/Cart.php index ed155aa60585be883c005a3e2cb9f60ea4077016..61a80f8ca58ee312f0bbf5d1572b86c15395b383 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Cart.php +++ b/app/code/Magento/Wishlist/Controller/Index/Cart.php @@ -36,6 +36,16 @@ class Cart extends Action\Action implements IndexInterface */ protected $cart; + /** + * @var \Magento\Checkout\Helper\Cart + */ + protected $cartHelper; + + /** + * @var \Magento\Framework\Json\Helper\Data + */ + protected $jsonHelper; + /** * @var \Magento\Wishlist\Model\Item\OptionFactory */ @@ -66,6 +76,10 @@ class Cart extends Action\Action implements IndexInterface * @param \Magento\Catalog\Helper\Product $productHelper * @param \Magento\Framework\Escaper $escaper * @param \Magento\Wishlist\Helper\Data $helper + * @param \Magento\Checkout\Helper\Cart $cartHelper + * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( Action\Context $context, @@ -76,7 +90,9 @@ class Cart extends Action\Action implements IndexInterface \Magento\Wishlist\Model\Item\OptionFactory $optionFactory, \Magento\Catalog\Helper\Product $productHelper, \Magento\Framework\Escaper $escaper, - \Magento\Wishlist\Helper\Data $helper + \Magento\Wishlist\Helper\Data $helper, + \Magento\Checkout\Helper\Cart $cartHelper, + \Magento\Framework\Json\Helper\Data $jsonHelper ) { $this->wishlistProvider = $wishlistProvider; $this->quantityProcessor = $quantityProcessor; @@ -86,6 +102,8 @@ class Cart extends Action\Action implements IndexInterface $this->productHelper = $productHelper; $this->escaper = $escaper; $this->helper = $helper; + $this->cartHelper = $cartHelper; + $this->jsonHelper = $jsonHelper; parent::__construct($context); } @@ -159,8 +177,8 @@ class Cart extends Action\Action implements IndexInterface $this->messageManager->addSuccess($message); } - if ($this->cart->getShouldRedirectToCart()) { - $redirectUrl = $this->cart->getCartUrl(); + if ($this->cartHelper->getShouldRedirectToCart()) { + $redirectUrl = $this->cartHelper->getCartUrl(); } else { $refererUrl = $this->_redirect->getRefererUrl(); if ($refererUrl && $refererUrl != $configureUrl) { @@ -178,6 +196,13 @@ class Cart extends Action\Action implements IndexInterface $this->helper->calculate(); + if ($this->getRequest()->isAjax()) { + $this->getResponse()->representJson( + $this->jsonHelper->jsonEncode(['backUrl' => $redirectUrl]) + ); + return; + } + return $this->getResponse()->setRedirect($redirectUrl); } } diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php index fd7c06e7336d0ef29f2ab95c9ece2c6804a6a010..fcfec1f1071a82b28b866e753669733d031422de 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php @@ -96,6 +96,16 @@ class CartTest extends \PHPUnit_Framework_TestCase */ protected $urlMock; + /** + * @var \Magento\Checkout\Helper\Cart|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cartHelperMock; + + /** + * @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + */ + protected $jsonHelperMock; + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -139,12 +149,12 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') ->disableOriginalConstructor() - ->setMethods(['getParams', 'getParam']) + ->setMethods(['getParams', 'getParam', 'isAjax']) ->getMockForAbstractClass(); $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') ->disableOriginalConstructor() - ->setMethods(['setRedirect']) + ->setMethods(['setRedirect', 'representJson']) ->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface') @@ -187,6 +197,14 @@ class CartTest extends \PHPUnit_Framework_TestCase ->method('getUrl') ->will($this->returnValue($this->urlMock)); + $this->cartHelperMock = $this->getMockBuilder('Magento\Checkout\Helper\Cart') + ->disableOriginalConstructor() + ->getMock(); + + $this->jsonHelperMock = $this->getMockBuilder('Magento\Framework\Json\Helper\Data') + ->disableOriginalConstructor() + ->getMock(); + $this->model = new Cart( $this->contextMock, $this->wishlistProviderMock, @@ -196,7 +214,9 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, - $this->helperMock + $this->helperMock, + $this->cartHelperMock, + $this->jsonHelperMock ); } @@ -275,9 +295,13 @@ class CartTest extends \PHPUnit_Framework_TestCase } /** + * @param bool $isAjax + * + * @dataProvider dataProviderExecuteWithQuantityArray + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testExecuteWithQuantityArray() + public function testExecuteWithQuantityArray($isAjax) { $itemId = 2; $wishlistId = 1; @@ -397,6 +421,9 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->requestMock->expects($this->once()) ->method('getParams') ->willReturn($params); + $this->requestMock->expects($this->once()) + ->method('isAjax') + ->willReturn($isAjax); $buyRequestMock = $this->getMockBuilder('Magento\Framework\Object') ->disableOriginalConstructor() @@ -467,7 +494,7 @@ class CartTest extends \PHPUnit_Framework_TestCase ->with('You added ' . $productName . ' to your shopping cart.', null) ->willReturnSelf(); - $this->checkoutCartMock->expects($this->once()) + $this->cartHelperMock->expects($this->once()) ->method('getShouldRedirectToCart') ->willReturn(false); @@ -479,12 +506,33 @@ class CartTest extends \PHPUnit_Framework_TestCase ->method('calculate') ->willReturnSelf(); - $this->responseMock->expects($this->once()) + $this->jsonHelperMock->expects($this->any()) + ->method('jsonEncode') + ->with(['backUrl' => $refererUrl]) + ->willReturn('{"backUrl":"' . $refererUrl . '"}'); + + $this->responseMock->expects($this->any()) ->method('setRedirect') ->with($refererUrl) ->willReturn($this->responseMock); + $this->responseMock->expects($this->any()) + ->method('representJson') + ->with('{"backUrl":"' . $refererUrl . '"}') + ->willReturnSelf(); - $this->assertEquals($this->responseMock, $this->model->execute()); + $expectedResult = ($isAjax ? null : $this->responseMock); + $this->assertEquals($expectedResult, $this->model->execute()); + } + + /** + * @return array + */ + public function dataProviderExecuteWithQuantityArray() + { + return [ + ['isAjax' => false], + ['isAjax' => true], + ]; } /** diff --git a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml index 035364489f3caa8386c6d57bd34e6994b2d965ac..624a320f30a7e00e0722812837cab07b9d079a86 100644 --- a/app/code/Magento/Wishlist/view/frontend/templates/view.phtml +++ b/app/code/Magento/Wishlist/view/frontend/templates/view.phtml @@ -13,14 +13,6 @@ <?php echo($block->getChildHtml('wishlist.rss.link'));?> <form class="form-wishlist-items" id="wishlist-view-form" data-mage-init='{"wishlist":{ - "dataAttribute":"item-id", - "nameFormat":"qty[{0}]", - "btnRemoveSelector":".action.delete", - "qtySelector":".qty", - "addToCartSelector":".action.tocart", - "addAllToCartSelector":".primary > .action.tocart", - "commentInputType":"textarea", - "infoList":false, "addToCartUrl":"<?php echo $block->getItemAddToCartUrl("%item%");?>", "confirmRemoveMessage":"<?php echo __("Are you sure you want to remove this product from your wishlist?") ?>", "addAllToCartUrl":"<?php echo $block->getAddAllToCartUrl(); ?>", diff --git a/app/code/Magento/Wishlist/view/frontend/web/wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/wishlist.js index ad01e333ef0cfd2a9b3b88a821fdaf665c3f390c..973cde4f0b4e90fddb1cf9990b8f726c70acd152 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/wishlist.js @@ -81,12 +81,11 @@ define([ var itemId = elem.data(this.options.dataAttribute), url = this.options.addToCartUrl.replace('%item%', itemId), inputName = $.validator.format(this.options.nameFormat, itemId), - inputValue = elem.parent().find('[name="' + inputName + '"]').val(), + inputValue = $('[name="' + inputName + '"]').val(), separator = (url.indexOf('?') >= 0) ? '&' : '?'; url += separator + inputName + '=' + encodeURIComponent(inputValue); this._validateAndRedirect(url); } - }, /** diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php index 00e3a4896a7fd2e3f979d9eefffd284b1839cda0..427bc6c11cd4edfd7ed82f34ccafe2b6229d88e2 100644 --- a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Fixture/GroupedProduct/Associated.php @@ -198,19 +198,19 @@ class Associated implements FixtureInterface 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 17, + 'qty' => 3, ], [ 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 36, + 'qty' => 1, ], [ 'id' => '%id%', 'name' => '%item1_simple::getProductName%', 'position' => '%position%', - 'qty' => 20, + 'qty' => 2, ], ], 'products' => [ diff --git a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml index 066996237682324629b01255adc02af4a05a67af..1cf13be71e2cd00324fbc5303d2a6bd31230fa33 100644 --- a/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml +++ b/dev/tests/functional/tests/app/Magento/Wishlist/Test/TestCase/AddProductsToCartFromCustomerWishlistOnFrontendTest.xml @@ -33,28 +33,24 @@ <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> </variation> <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation5"> - <data name="issue" xsi:type="string">Bug: MAGETWO-36224</data> <data name="products" xsi:type="string">downloadableProduct::with_two_separately_links</data> <data name="qty" xsi:type="string">-</data> <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> </variation> <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation6"> - <data name="issue" xsi:type="string">Bug: MAGETWO-36224</data> <data name="products" xsi:type="string">configurableProduct::default</data> <data name="qty" xsi:type="string">3</data> <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> </variation> <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation7"> - <data name="issue" xsi:type="string">Bug: MAGETWO-36224</data> <data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product</data> <data name="qty" xsi:type="string">2</data> <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> <constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" /> </variation> <variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation8"> - <data name="issue" xsi:type="string">Bug: MAGETWO-36224</data> <data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data> <data name="qty" xsi:type="string">2</data> <constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" /> diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php index f147db9a5a5cc26f376e77d0080e766967e7344e..905a5a9affc1d62dd9ba398a247cf40dbfc12780 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/Resource/GroupRepositoryTest.php @@ -7,6 +7,7 @@ namespace Magento\Customer\Model\Resource; use Magento\Customer\Api\Data\GroupInterface; +use Magento\Framework\Api\SearchCriteria; /** * Integration test for \Magento\Customer\Model\Resource\GroupRepository @@ -28,12 +29,16 @@ class GroupRepositoryTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Framework\Api\SearchCriteriaBuilder */ private $searchCriteriaBuilder; + /** @var \Magento\Framework\Api\SortOrderBuilder */ + private $sortOrderBuilder; + protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->groupRepository = $this->objectManager->create('Magento\Customer\Api\GroupRepositoryInterface'); $this->groupFactory = $this->objectManager->create('Magento\Customer\Api\Data\GroupInterfaceFactory'); $this->searchCriteriaBuilder = $this->objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder'); + $this->sortOrderBuilder = $this->objectManager->create('Magento\Framework\Api\SortOrderBuilder'); } /** @@ -249,6 +254,95 @@ class GroupRepositoryTest extends \PHPUnit_Framework_TestCase 3 => [GroupInterface::CODE => 'Retailer', GroupInterface::TAX_CLASS_ID => 3] ], ], + 'like_tax_name' => [ + [ + $builder->setField(GroupInterface::TAX_CLASS_NAME)->setValue('Retail Customer') + ->setConditionType('like') + ->create(), + ], + [], + [ + 0 => [GroupInterface::CODE => 'NOT LOGGED IN', GroupInterface::TAX_CLASS_ID => 3], + 1 => [GroupInterface::CODE => 'General', GroupInterface::TAX_CLASS_ID => 3], + 2 => [GroupInterface::CODE => 'Wholesale', GroupInterface::TAX_CLASS_ID => 3], + 3 => [GroupInterface::CODE => 'Retailer', GroupInterface::TAX_CLASS_ID => 3], + ], + ], + ]; + } + + /** + * @param string $field + * @param string, $direction + * @param string, $methodName + * @param array $expectedResult + * + * @dataProvider sortOrderDataProvider + */ + public function testGetListSortOrder($field, $direction, $methodName, $expectedResult) + { + /** @var \Magento\Framework\Api\SortOrder $sortOrder */ + /** @var string $direction */ + $direction = ($direction == 'ASC') ? SearchCriteria::SORT_ASC : SearchCriteria::SORT_DESC; + $sortOrder = $this->sortOrderBuilder->setField($field)->setDirection($direction)->create(); + $this->searchCriteriaBuilder->addSortOrder($sortOrder); + + $searchResults = $this->groupRepository->getList($this->searchCriteriaBuilder->create()); + + /** @var \Magento\Customer\Api\Data\GroupInterface[] $resultItems */ + $resultItems = $searchResults->getItems(); + $this->assertTrue(count($resultItems) > 0); + + $result = []; + foreach ($resultItems as $item) { + /** @var \Magento\Customer\Model\Data\Group $item */ + $result[] = $item->$methodName(); + } + $this->assertEquals($expectedResult, $result); + } + + /** + * @return array + */ + public function sortOrderDataProvider() + { + return [ + [ + GroupInterface::ID, + 'ASC', + 'getId', + [0, 1, 2, 3], + ], + [ + GroupInterface::ID, + 'DESC', + 'getId', + [3, 2, 1, 0], + ], + [ + GroupInterface::CODE, + 'ASC', + 'getCode', + ['General', 'NOT LOGGED IN', 'Retailer', 'Wholesale'], + ], + [ + GroupInterface::CODE, + 'DESC', + 'getCode', + ['Wholesale', 'Retailer', 'NOT LOGGED IN', 'General'], + ], + [ + GroupInterface::TAX_CLASS_NAME, + 'ASC', + 'getTaxClassName', + ['Retail Customer', 'Retail Customer', 'Retail Customer', 'Retail Customer'] + ], + [ + GroupInterface::TAX_CLASS_NAME, + 'DESC', + 'getTaxClassName', + ['Retail Customer', 'Retail Customer', 'Retail Customer', 'Retail Customer'] + ], ]; } }