diff --git a/app/code/Magento/Catalog/Model/Category.php b/app/code/Magento/Catalog/Model/Category.php index b95b1e9da7424d3806837b07a89467186cc7a7fd..4361b3bdd501c55c0f206bca0a430aacce0d4216 100644 --- a/app/code/Magento/Catalog/Model/Category.php +++ b/app/code/Magento/Catalog/Model/Category.php @@ -1086,9 +1086,10 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements $flatIndexer->reindexRow($this->getId()); } } - $affectedProductIds = $this->getAffectedProductIds(); $productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID); - if (!$productIndexer->isScheduled() && !empty($affectedProductIds)) { + if (!$productIndexer->isScheduled() + && (!empty($this->getAffectedProductIds()) || $this->dataHasChangedFor('is_anchor')) + ) { $productIndexer->reindexList($this->getPathIds()); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php index 3b24090d3ecf394401f6fca1d83af8171298a047..60ebb6b20fb9bdf09f8a2515a71ebd22c30875dd 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php @@ -380,21 +380,37 @@ class CategoryTest extends \PHPUnit_Framework_TestCase public function reindexFlatDisabledTestDataProvider() { return [ - 'set 1' => [false, 1], - 'set 2' => [true, 0], + [false, null, null, null, 0], + [true, null, null, null, 0], + [false, [], null, null, 0], + [false, ["1", "2"], null, null, 1], + [false, null, 1, null, 1], + [false, ["1", "2"], 0, 1, 1], + [false, null, 1, 1, 0], ]; } /** - * @param $productScheduled - * @param $expectedProductReindexCall + * @param bool $productScheduled + * @param array $affectedIds + * @param int|string $isAnchorOrig + * @param int|string $isAnchor + * @param int $expectedProductReindexCall * * @dataProvider reindexFlatDisabledTestDataProvider */ - public function testReindexFlatDisabled($productScheduled, $expectedProductReindexCall) - { - $affectedProductIds = ["1", "2"]; - $this->category->setAffectedProductIds($affectedProductIds); + public function testReindexFlatDisabled( + $productScheduled, + $affectedIds, + $isAnchorOrig, + $isAnchor, + $expectedProductReindexCall + ) { + $this->category->setAffectedProductIds($affectedIds); + $this->category->setData('is_anchor', $isAnchor); + $this->category->setOrigData('is_anchor', $isAnchorOrig); + $this->category->setAffectedProductIds($affectedIds); + $pathIds = ['path/1/2', 'path/2/3']; $this->category->setData('path_ids', $pathIds); $this->category->setId('123'); @@ -403,8 +419,12 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->method('isFlatEnabled') ->will($this->returnValue(false)); - $this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled)); - $this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds); + $this->productIndexer->expects($this->exactly(1)) + ->method('isScheduled') + ->willReturn($productScheduled); + $this->productIndexer->expects($this->exactly($expectedProductReindexCall)) + ->method('reindexList') + ->with($pathIds); $this->indexerRegistry->expects($this->at(0)) ->method('get') diff --git a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js index 052e79cbc7fced3a29f041489cd076f1a421e3b0..3882419363315a6bbfdc57eb8a304c060ef7e143 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/sidebar.js @@ -52,7 +52,11 @@ define([ customer = customerData.get('customer'); if (!customer().firstname && !cart().isGuestCheckoutAllowed) { - authenticationPopup.showModal(); + if (this.options.url.isRedirectRequired) { + location.href = this.options.url.loginUrl; + } else { + authenticationPopup.showModal(); + } return false; } diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js b/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js index 68f02b5d5722412fa17880c59124cf5ee84cdb03..2a9375a40eba1f95c258bc2cebc42b7d021d5615 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js @@ -33,7 +33,9 @@ define([ "url": { "checkout": window.checkout.checkoutUrl, "update": window.checkout.updateItemQtyUrl, - "remove": window.checkout.removeItemUrl + "remove": window.checkout.removeItemUrl, + "loginUrl": window.checkout.customerLoginUrl, + "isRedirectRequired": window.checkout.isRedirectRequired }, "button": { "checkout": "#top-cart-btn-checkout", diff --git a/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php b/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php new file mode 100644 index 0000000000000000000000000000000000000000..2be36da4d90404f302e1a6cbba48386ad1f995ef --- /dev/null +++ b/app/code/Magento/Customer/Model/Cart/ConfigPlugin.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Customer\Model\Cart; + +use Magento\Customer\Model\Checkout\ConfigProvider; + +class ConfigPlugin +{ + /** + * @var ConfigProvider + */ + protected $configProvider; + + /** + * @param ConfigProvider $configProvider + */ + public function __construct( + ConfigProvider $configProvider + ) { + $this->configProvider = $configProvider; + } + + /** + * @param \Magento\Checkout\Block\Cart\Sidebar $subject + * @param array $result + * @return array + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetConfig(\Magento\Checkout\Block\Cart\Sidebar $subject, array $result) + { + return array_merge_recursive($result, $this->configProvider->getConfig()); + } +} diff --git a/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php new file mode 100644 index 0000000000000000000000000000000000000000..f09e2129c36d1555411e702d451df283f1b31ca2 --- /dev/null +++ b/app/code/Magento/Customer/Model/Checkout/ConfigProvider.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Customer\Model\Checkout; + +use Magento\Checkout\Model\ConfigProviderInterface; +use Magento\Customer\Model\Url; +use Magento\Framework\UrlInterface; +use Magento\Store\Model\StoreManagerInterface; + +class ConfigProvider implements ConfigProviderInterface +{ + /** + * @var StoreManagerInterface + */ + protected $storeManager; + + /** + * @var UrlInterface + */ + protected $urlBuilder; + + /** + * @param UrlInterface $urlBuilder + * @param StoreManagerInterface $storeManager + */ + public function __construct( + UrlInterface $urlBuilder, + StoreManagerInterface $storeManager + ) { + $this->urlBuilder = $urlBuilder; + $this->storeManager = $storeManager; + } + + /** + * {@inheritdoc} + */ + public function getConfig() + { + return [ + 'customerLoginUrl' => $this->getLoginUrl(), + 'isRedirectRequired' => $this->isRedirectRequired(), + ]; + } + + /** + * Returns URL to login controller action + * + * @return string + */ + protected function getLoginUrl() + { + return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN); + } + + /** + * Whether redirect to login page is required + * + * @return bool + */ + protected function isRedirectRequired() + { + $baseUrl = $this->storeManager->getStore()->getBaseUrl(); + + if (strpos($this->getLoginUrl(), $baseUrl) !== false) { + return false; + } + + return true; + } +} diff --git a/app/code/Magento/Customer/etc/frontend/di.xml b/app/code/Magento/Customer/etc/frontend/di.xml index ad1f406500e98edf92f80ea8a3edd7a2a24f968f..0205fbf62fc367b690edeee8f98fa32b3c0f0118 100644 --- a/app/code/Magento/Customer/etc/frontend/di.xml +++ b/app/code/Magento/Customer/etc/frontend/di.xml @@ -54,4 +54,7 @@ <type name="Magento\Customer\Controller\AccountInterface"> <plugin name="customer_account" type="Magento\Customer\Controller\Plugin\Account" /> </type> + <type name="Magento\Checkout\Block\Cart\Sidebar"> + <plugin name="customer_cart" type="\Magento\Customer\Model\Cart\ConfigPlugin" /> + </type> </config> diff --git a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js index bf788ddfe1d5ba5f56c34ed24d1433be91b3bc8b..e35407fde4535ce349e7b99a5b8c27af56009b2a 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js @@ -66,7 +66,7 @@ define([ $('[data-action="add-to-wishlist"]').each(function(index, element) { var params = $(element).data('post'); if (!params) - params = {}; + params = {'data': {}}; if (!$.isEmptyObject(dataToAdd)) { self._removeExcessiveData(params, dataToAdd);