Skip to content

Commit 9fc9c24

Browse files
committed
Merge branch 'mainline_develop' into checkout
2 parents 22edaa9 + 318377f commit 9fc9c24

File tree

17 files changed

+453
-154
lines changed

17 files changed

+453
-154
lines changed

app/code/Magento/Backend/Service/V1/ModuleServiceInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Backend\Service\V1;
88

9+
/**
10+
* Interface for module service.
11+
*/
912
interface ModuleServiceInterface
1013
{
1114
/**

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function __construct(
6161
public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
6262
{
6363
$existingData = $category->toFlatArray();
64+
/** 'available_sort_by' should be set separately because fields of array type are destroyed by toFlatArray() */
65+
$existingData['available_sort_by'] = $category->getAvailableSortBy();
6466
if ($category->getId()) {
6567
$existingCategory = $this->get($category->getId());
6668
if (isset($existingData['image']) && is_array($existingData['image'])) {

app/code/Magento/CatalogInventory/Helper/Stock.php

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
*/
66
namespace Magento\CatalogInventory\Helper;
77

8-
use Magento\CatalogInventory\Api\StockRegistryInterface;
8+
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
99
use Magento\Store\Model\StoreManagerInterface;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\CatalogInventory\Model\Resource\Stock\StatusFactory;
12+
use Magento\CatalogInventory\Model\Resource\Stock\Status;
13+
use Magento\Catalog\Model\Resource\Collection\AbstractCollection;
14+
use Magento\Catalog\Model\Product;
1215

1316
/**
1417
* Class Stock
1518
*/
1619
class Stock
1720
{
18-
/**
19-
* @var StockRegistryInterface
20-
*/
21-
protected $stockRegistry;
22-
2321
/**
2422
* Store model manager
2523
*
@@ -35,45 +33,50 @@ class Stock
3533
protected $scopeConfig;
3634

3735
/**
38-
* @var \Magento\CatalogInventory\Model\Resource\Stock\Status
36+
* @var Status
3937
*/
4038
protected $stockStatusResource;
4139

4240
/**
43-
* @var \Magento\Framework\ObjectManagerInterface
41+
* @var StatusFactory
42+
*/
43+
protected $stockStatusFactory;
44+
45+
/**
46+
* @var StockRegistryProviderInterface
4447
*/
45-
protected $objectManger;
48+
private $stockRegistryProvider;
4649

4750
/**
48-
* @param StockRegistryInterface $stockRegistry
4951
* @param StoreManagerInterface $storeManager
5052
* @param ScopeConfigInterface $scopeConfig
51-
* @param ObjectManagerInterface $objectManager
53+
* @param StatusFactory $stockStatusFactory
54+
* @param StockRegistryProviderInterface $stockRegistryProvider
5255
*/
5356
public function __construct(
54-
StockRegistryInterface $stockRegistry,
5557
StoreManagerInterface $storeManager,
5658
ScopeConfigInterface $scopeConfig,
57-
ObjectManagerInterface $objectManager
59+
StatusFactory $stockStatusFactory,
60+
StockRegistryProviderInterface $stockRegistryProvider
5861
) {
59-
$this->stockRegistry = $stockRegistry;
6062
$this->storeManager = $storeManager;
6163
$this->scopeConfig = $scopeConfig;
62-
$this->objectManger = $objectManager;
64+
$this->stockStatusFactory = $stockStatusFactory;
65+
$this->stockRegistryProvider = $stockRegistryProvider;
6366
}
6467

6568
/**
6669
* Assign stock status information to product
6770
*
68-
* @param \Magento\Catalog\Model\Product $product
71+
* @param Product $product
6972
* @param int $stockStatus
7073
* @return void
7174
*/
72-
public function assignStatusToProduct(\Magento\Catalog\Model\Product $product, $stockStatus = null)
75+
public function assignStatusToProduct(Product $product, $stockStatus = null)
7376
{
7477
if ($stockStatus === null) {
7578
$websiteId = $product->getStore()->getWebsiteId();
76-
$stockStatus = $this->stockRegistry->getStockStatus($product->getId(), $websiteId);
79+
$stockStatus = $this->stockRegistryProvider->getStockStatus($product->getId(), $websiteId);
7780
$status = $stockStatus->getStockStatus();
7881
}
7982
$product->setIsSalable($status);
@@ -82,18 +85,15 @@ public function assignStatusToProduct(\Magento\Catalog\Model\Product $product, $
8285
/**
8386
* Add stock status information to products
8487
*
85-
* @param \Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection
88+
* @param AbstractCollection $productCollection
8689
* @return void
87-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
8890
*/
89-
public function addStockStatusToProducts(
90-
\Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection
91-
) {
91+
public function addStockStatusToProducts(AbstractCollection $productCollection)
92+
{
9293
$websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
93-
$productIds = [];
9494
foreach ($productCollection as $product) {
9595
$productId = $product->getId();
96-
$stockStatus = $this->stockRegistry->getStockStatus($productId, $websiteId);
96+
$stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $websiteId);
9797
$status = $stockStatus->getStockStatus();
9898
$product->setIsSalable($status);
9999
}
@@ -131,19 +131,6 @@ public function addInStockFilterToCollection($collection)
131131
);
132132
}
133133

134-
/**
135-
* Add stock status to prepare index select
136-
*
137-
* @param \Magento\Framework\DB\Select $select
138-
* @param \Magento\Store\Model\Website $website
139-
* @return void
140-
*/
141-
public function addStockStatusToSelect(\Magento\Framework\DB\Select $select, \Magento\Store\Model\Website $website)
142-
{
143-
$resource = $this->getStockStatusResource();
144-
$resource->addStockStatusToSelect($select, $website);
145-
}
146-
147134
/**
148135
* Add only is in stock products filter to product collection
149136
*
@@ -157,14 +144,12 @@ public function addIsInStockFilterToCollection($collection)
157144
}
158145

159146
/**
160-
* @return \Magento\CatalogInventory\Model\Resource\Stock\Status
147+
* @return Status
161148
*/
162149
protected function getStockStatusResource()
163150
{
164151
if (empty($this->stockStatusResource)) {
165-
$this->stockStatusResource = $this->objectManger->get(
166-
'Magento\CatalogInventory\Model\Resource\Stock\Status'
167-
);
152+
$this->stockStatusResource = $this->stockStatusFactory->create();
168153
}
169154
return $this->stockStatusResource;
170155
}

app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,29 @@ class StockTest extends \PHPUnit_Framework_TestCase
1818
protected $stock;
1919

2020
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
21+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface
2222
*/
23-
protected $stockRegistryMock;
23+
protected $stockRegistryProviderMock;
2424

2525
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
26+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
2727
*/
2828
protected $storeManagerMock;
2929

3030
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
31+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
3232
*/
3333
protected $scopeConfigMock;
3434

3535
/**
36-
* @var \PHPUnit_Framework_MockObject_MockObject
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CatalogInventory\Model\Resource\Stock\StatusFactory
3737
*/
38-
protected $productFactoryMock;
39-
40-
/**
41-
* @var \PHPUnit_Framework_MockObject_MockObject
42-
*/
43-
protected $objectManagerMock;
38+
protected $statusFactoryMock;
4439

4540
protected function setUp()
4641
{
47-
$this->stockRegistryMock = $this->getMockBuilder(
48-
'Magento\CatalogInventory\Api\StockRegistryInterface'
42+
$this->stockRegistryProviderMock = $this->getMockBuilder(
43+
'Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface'
4944
)
5045
->disableOriginalConstructor()
5146
->getMock();
@@ -55,14 +50,15 @@ protected function setUp()
5550
$this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
5651
->disableOriginalConstructor()
5752
->getMock();
58-
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\App\ObjectManager')
53+
$this->statusFactoryMock = $this->getMockBuilder('Magento\CatalogInventory\Model\Resource\Stock\StatusFactory')
5954
->disableOriginalConstructor()
55+
->setMethods(['create'])
6056
->getMock();
6157
$this->stock = new Stock(
62-
$this->stockRegistryMock,
6358
$this->storeManagerMock,
6459
$this->scopeConfigMock,
65-
$this->objectManagerMock
60+
$this->statusFactoryMock,
61+
$this->stockRegistryProviderMock
6662
);
6763
}
6864

@@ -77,7 +73,7 @@ public function testAssignStatusToProduct()
7773
$stockStatusMock->expects($this->any())
7874
->method('getStockStatus')
7975
->willReturn($status);
80-
$this->stockRegistryMock->expects($this->any())
76+
$this->stockRegistryProviderMock->expects($this->any())
8177
->method('getStockStatus')
8278
->willReturn($stockStatusMock);
8379
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
@@ -142,7 +138,7 @@ public function testAddStockStatusToProducts()
142138
$this->storeManagerMock->expects($this->once())
143139
->method('getStore')
144140
->willReturn($storeMock);
145-
$this->stockRegistryMock->expects($this->once())
141+
$this->stockRegistryProviderMock->expects($this->once())
146142
->method('getStockStatus')
147143
->withAnyParameters()
148144
->willReturn($stockStatusMock);
@@ -177,28 +173,6 @@ public function filterProvider()
177173
];
178174
}
179175

180-
public function testAddStockStatusToSelect()
181-
{
182-
$selectMock = $this->getMockBuilder('Magento\Framework\DB\Select')
183-
->disableOriginalConstructor()
184-
->getMock();
185-
$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
186-
->disableOriginalConstructor()
187-
->getMock();
188-
$stockStatusMock = $this->getMockBuilder('Magento\CatalogInventory\Model\Resource\Stock\Status')
189-
->disableOriginalConstructor()
190-
->setMethods(['addStockStatusToSelect'])
191-
->getMock();
192-
$stockStatusMock->expects($this->once())
193-
->method('addStockStatusToSelect')
194-
->with($selectMock, $websiteMock);
195-
$this->objectManagerMock->expects($this->once())
196-
->method('get')
197-
->willReturn($stockStatusMock);
198-
199-
$this->assertNull($this->stock->addStockStatusToSelect($selectMock, $websiteMock));
200-
}
201-
202176
public function testAddIsInStockFilterToCollection()
203177
{
204178
$collectionMock = $this->getMockBuilder('Magento\Catalog\Model\Resource\Product\Collection')
@@ -211,8 +185,8 @@ public function testAddIsInStockFilterToCollection()
211185
$stockStatusMock->expects($this->once())
212186
->method('addIsInStockFilterToCollection')
213187
->with($collectionMock);
214-
$this->objectManagerMock->expects($this->once())
215-
->method('get')
188+
$this->statusFactoryMock->expects($this->once())
189+
->method('create')
216190
->willReturn($stockStatusMock);
217191

218192
$this->assertNull($this->stock->addIsInStockFilterToCollection($collectionMock));

app/code/Magento/Store/App/Action/Plugin/Context.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,27 @@ public function aroundDispatch(
7474
\Closure $proceed,
7575
\Magento\Framework\App\RequestInterface $request
7676
) {
77+
/** @var \Magento\Store\Model\Store $defaultStore */
7778
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
78-
$this->httpContext->setValue(
79-
HttpContext::CONTEXT_CURRENCY,
80-
$this->session->getCurrencyCode(),
81-
$defaultStore->getDefaultCurrency()->getCode()
79+
80+
$requestedStoreCode = $this->httpRequest->getParam(
81+
StoreResolverInterface::PARAM_NAME,
82+
$this->storeCookieManager->getStoreCodeFromCookie()
8283
);
84+
/** @var \Magento\Store\Model\Store $currentStore */
85+
$currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore;
8386

8487
$this->httpContext->setValue(
8588
StoreManagerInterface::CONTEXT_STORE,
86-
$this->httpRequest->getParam(
87-
StoreResolverInterface::PARAM_NAME,
88-
$this->storeCookieManager->getStoreCodeFromCookie()
89-
) ?: $defaultStore->getCode(),
89+
$currentStore->getCode(),
9090
$this->storeManager->getDefaultStoreView()->getCode()
9191
);
92+
93+
$this->httpContext->setValue(
94+
HttpContext::CONTEXT_CURRENCY,
95+
$this->session->getCurrencyCode() ?: $currentStore->getDefaultCurrencyCode(),
96+
$defaultStore->getDefaultCurrencyCode()
97+
);
9298
return $proceed($request);
9399
}
94100
}

app/code/Magento/Store/Controller/Store/SwitchAction.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
use Magento\Store\Model\Store;
1515
use Magento\Store\Model\StoreIsInactiveException;
1616
use Magento\Store\Model\StoreResolver;
17+
use Magento\Store\Model\StoreManagerInterface;
1718

19+
/**
20+
* Switch current store view.
21+
*/
1822
class SwitchAction extends Action
1923
{
2024
/**
@@ -33,21 +37,31 @@ class SwitchAction extends Action
3337
protected $storeRepository;
3438

3539
/**
40+
* @var StoreManagerInterface
41+
*/
42+
protected $storeManager;
43+
44+
/**
45+
* Initialize dependencies.
46+
*
3647
* @param ActionContext $context
3748
* @param StoreCookieManagerInterface $storeCookieManager
3849
* @param HttpContext $httpContext
3950
* @param StoreRepositoryInterface $storeRepository
51+
* @param StoreManagerInterface $storeManager
4052
*/
4153
public function __construct(
4254
ActionContext $context,
4355
StoreCookieManagerInterface $storeCookieManager,
4456
HttpContext $httpContext,
45-
StoreRepositoryInterface $storeRepository
57+
StoreRepositoryInterface $storeRepository,
58+
StoreManagerInterface $storeManager
4659
) {
4760
parent::__construct($context);
4861
$this->storeCookieManager = $storeCookieManager;
4962
$this->httpContext = $httpContext;
5063
$this->storeRepository = $storeRepository;
64+
$this->storeManager = $storeManager;
5165
}
5266

5367
/**
@@ -64,7 +78,7 @@ public function execute()
6478
$store = $this->storeRepository->getActiveStoreByCode($storeCode);
6579
} catch (StoreIsInactiveException $e) {
6680
$error = __('Requested store is inactive');
67-
} catch (\InvalidArgumentException $e) { // TODO: MAGETWO-39826 Need to replace on NoSuchEntityException
81+
} catch (\InvalidArgumentException $e) {
6882
$error = __('Requested store is not found');
6983
}
7084

@@ -74,11 +88,12 @@ public function execute()
7488
return;
7589
}
7690

77-
if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) {
91+
$defaultStoreView = $this->storeManager->getDefaultStoreView();
92+
if ($defaultStoreView->getId() == $store->getId()) {
7893
$this->storeCookieManager->deleteStoreCookie($store);
7994
} else {
95+
$this->httpContext->setValue(Store::ENTITY, $store->getCode(), $defaultStoreView->getCode());
8096
$this->storeCookieManager->setStoreCookie($store);
81-
$this->httpContext->setValue(Store::ENTITY, $store->getCode(), Store::DEFAULT_CODE);
8297
}
8398

8499
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());

0 commit comments

Comments
 (0)