Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit ca42048

Browse files
authored
Merge pull request #3115 from magento-honey-badgers/MAGETWO-91439-Price-prices-disappearing-on-category-page-remove-resolver
[honey] MAGETWO-91439: Prices disappearing when product is assigned to a different store and default store is disabled
2 parents 22a2e2c + e861d64 commit ca42048

File tree

39 files changed

+959
-501
lines changed

39 files changed

+959
-501
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/BaseSelectProcessorInterface.php

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

1010
/**
1111
* Interface BaseSelectProcessorInterface
12+
*
1213
* @api
1314
* @since 101.0.3
1415
*/
@@ -20,6 +21,8 @@ interface BaseSelectProcessorInterface
2021
const PRODUCT_TABLE_ALIAS = 'child';
2122

2223
/**
24+
* Process the select statement
25+
*
2326
* @param Select $select
2427
* @return Select
2528
* @since 101.0.3

app/code/Magento/Catalog/Model/ResourceModel/Product/StatusBaseSelectProcessor.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\EntityManager\MetadataPool;
1414
use Magento\Store\Api\StoreResolverInterface;
1515
use Magento\Store\Model\Store;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
1819
* Class StatusBaseSelectProcessor
@@ -30,28 +31,32 @@ class StatusBaseSelectProcessor implements BaseSelectProcessorInterface
3031
private $metadataPool;
3132

3233
/**
33-
* @var StoreResolverInterface
34+
* @var StoreManagerInterface
3435
*/
35-
private $storeResolver;
36+
private $storeManager;
3637

3738
/**
3839
* @param Config $eavConfig
3940
* @param MetadataPool $metadataPool
4041
* @param StoreResolverInterface $storeResolver
42+
* @param StoreManagerInterface $storeManager
43+
*
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4145
*/
4246
public function __construct(
4347
Config $eavConfig,
4448
MetadataPool $metadataPool,
45-
StoreResolverInterface $storeResolver
49+
StoreResolverInterface $storeResolver,
50+
StoreManagerInterface $storeManager = null
4651
) {
4752
$this->eavConfig = $eavConfig;
4853
$this->metadataPool = $metadataPool;
49-
$this->storeResolver = $storeResolver;
54+
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
55+
->get(StoreManagerInterface::class);
5056
}
5157

5258
/**
53-
* @param Select $select
54-
* @return Select
59+
* @inheritdoc
5560
*/
5661
public function process(Select $select)
5762
{
@@ -70,7 +75,7 @@ public function process(Select $select)
7075
['status_attr' => $statusAttribute->getBackendTable()],
7176
"status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
7277
. ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
73-
. ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(),
78+
. ' AND status_attr.store_id = ' . $this->storeManager->getStore()->getId(),
7479
[]
7580
);
7681

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Magento\Framework\EntityManager\EntityMetadataInterface;
1717
use Magento\Framework\EntityManager\MetadataPool;
1818
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
19-
use Magento\Store\Api\StoreResolverInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
2020
use Magento\Store\Model\Store;
2121

2222
/**
@@ -35,9 +35,9 @@ class StatusBaseSelectProcessorTest extends \PHPUnit\Framework\TestCase
3535
private $metadataPool;
3636

3737
/**
38-
* @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
38+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
3939
*/
40-
private $storeResolver;
40+
private $storeManager;
4141

4242
/**
4343
* @var Select|\PHPUnit_Framework_MockObject_MockObject
@@ -53,13 +53,13 @@ protected function setUp()
5353
{
5454
$this->eavConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
5555
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
56-
$this->storeResolver = $this->getMockBuilder(StoreResolverInterface::class)->getMock();
56+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)->getMock();
5757
$this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
5858

5959
$this->statusBaseSelectProcessor = (new ObjectManager($this))->getObject(StatusBaseSelectProcessor::class, [
6060
'eavConfig' => $this->eavConfig,
6161
'metadataPool' => $this->metadataPool,
62-
'storeResolver' => $this->storeResolver,
62+
'storeManager' => $this->storeManager,
6363
]);
6464
}
6565

@@ -94,8 +94,14 @@ public function testProcess()
9494
->with(Product::ENTITY, ProductInterface::STATUS)
9595
->willReturn($statusAttribute);
9696

97-
$this->storeResolver->expects($this->once())
98-
->method('getCurrentStoreId')
97+
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock();
98+
99+
$this->storeManager->expects($this->once())
100+
->method('getStore')
101+
->willReturn($storeMock);
102+
103+
$storeMock->expects($this->once())
104+
->method('getId')
99105
->willReturn($currentStoreId);
100106

101107
$this->select->expects($this->at(0))

app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php

Lines changed: 28 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Checkout\Helper\Data;
99
use Magento\Framework\App\ObjectManager;
10-
use Magento\Store\Api\StoreResolverInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
1111

1212
/**
1313
* Class LayoutProcessor
@@ -40,9 +40,9 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
4040
private $checkoutDataHelper;
4141

4242
/**
43-
* @var StoreResolverInterface
43+
* @var StoreManagerInterface
4444
*/
45-
private $storeResolver;
45+
private $storeManager;
4646

4747
/**
4848
* @var \Magento\Shipping\Model\Config
@@ -53,30 +53,36 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
5353
* @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider
5454
* @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper
5555
* @param AttributeMerger $merger
56+
* @param \Magento\Customer\Model\Options|null $options
57+
* @param Data|null $checkoutDataHelper
58+
* @param \Magento\Shipping\Model\Config|null $shippingConfig
59+
* @param StoreManagerInterface|null $storeManager
5660
*/
5761
public function __construct(
5862
\Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider,
5963
\Magento\Ui\Component\Form\AttributeMapper $attributeMapper,
60-
AttributeMerger $merger
64+
AttributeMerger $merger,
65+
\Magento\Customer\Model\Options $options = null,
66+
Data $checkoutDataHelper = null,
67+
\Magento\Shipping\Model\Config $shippingConfig = null,
68+
StoreManagerInterface $storeManager = null
6169
) {
6270
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
6371
$this->attributeMapper = $attributeMapper;
6472
$this->merger = $merger;
73+
$this->options = $options ?: \Magento\Framework\App\ObjectManager::getInstance()
74+
->get(\Magento\Customer\Model\Options::class);
75+
$this->checkoutDataHelper = $checkoutDataHelper ?: \Magento\Framework\App\ObjectManager::getInstance()
76+
->get(Data::class);
77+
$this->shippingConfig = $shippingConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
78+
->get(\Magento\Shipping\Model\Config::class);
79+
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(StoreManagerInterface::class);
6581
}
6682

6783
/**
68-
* @deprecated 100.0.11
69-
* @return \Magento\Customer\Model\Options
70-
*/
71-
private function getOptions()
72-
{
73-
if (!is_object($this->options)) {
74-
$this->options = ObjectManager::getInstance()->get(\Magento\Customer\Model\Options::class);
75-
}
76-
return $this->options;
77-
}
78-
79-
/**
84+
* Get address attributes.
85+
*
8086
* @return array
8187
*/
8288
private function getAddressAttributes()
@@ -143,8 +149,8 @@ private function convertElementsToSelect($elements, $attributesToConvert)
143149
public function process($jsLayout)
144150
{
145151
$attributesToConvert = [
146-
'prefix' => [$this->getOptions(), 'getNamePrefixOptions'],
147-
'suffix' => [$this->getOptions(), 'getNameSuffixOptions'],
152+
'prefix' => [$this->options, 'getNamePrefixOptions'],
153+
'suffix' => [$this->options, 'getNameSuffixOptions'],
148154
];
149155

150156
$elements = $this->getAddressAttributes();
@@ -192,8 +198,8 @@ public function process($jsLayout)
192198
*/
193199
private function processShippingChildrenComponents($shippingRatesLayout)
194200
{
195-
$activeCarriers = $this->getShippingConfig()->getActiveCarriers(
196-
$this->getStoreResolver()->getCurrentStoreId()
201+
$activeCarriers = $this->shippingConfig->getActiveCarriers(
202+
$this->storeManager->getStore()->getId()
197203
);
198204
foreach (array_keys($shippingRatesLayout) as $carrierName) {
199205
$carrierKey = str_replace('-rates-validation', '', $carrierName);
@@ -206,6 +212,7 @@ private function processShippingChildrenComponents($shippingRatesLayout)
206212

207213
/**
208214
* Appends billing address form component to payment layout
215+
*
209216
* @param array $paymentLayout
210217
* @param array $elements
211218
* @return array
@@ -221,7 +228,7 @@ private function processPaymentChildrenComponents(array $paymentLayout, array $e
221228
}
222229

223230
// The if billing address should be displayed on Payment method or page
224-
if ($this->getCheckoutDataHelper()->isDisplayBillingOnPaymentMethodAvailable()) {
231+
if ($this->checkoutDataHelper->isDisplayBillingOnPaymentMethodAvailable()) {
225232
$paymentLayout['payments-list']['children'] =
226233
array_merge_recursive(
227234
$paymentLayout['payments-list']['children'],
@@ -340,49 +347,4 @@ private function getBillingAddressComponent($paymentCode, $elements)
340347
],
341348
];
342349
}
343-
344-
/**
345-
* Get checkout data helper instance
346-
*
347-
* @return Data
348-
* @deprecated 100.1.4
349-
*/
350-
private function getCheckoutDataHelper()
351-
{
352-
if (!$this->checkoutDataHelper) {
353-
$this->checkoutDataHelper = ObjectManager::getInstance()->get(Data::class);
354-
}
355-
356-
return $this->checkoutDataHelper;
357-
}
358-
359-
/**
360-
* Retrieve Shipping Configuration.
361-
*
362-
* @return \Magento\Shipping\Model\Config
363-
* @deprecated 100.2.0
364-
*/
365-
private function getShippingConfig()
366-
{
367-
if (!$this->shippingConfig) {
368-
$this->shippingConfig = ObjectManager::getInstance()->get(\Magento\Shipping\Model\Config::class);
369-
}
370-
371-
return $this->shippingConfig;
372-
}
373-
374-
/**
375-
* Get store resolver.
376-
*
377-
* @return StoreResolverInterface
378-
* @deprecated 100.2.0
379-
*/
380-
private function getStoreResolver()
381-
{
382-
if (!$this->storeResolver) {
383-
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
384-
}
385-
386-
return $this->storeResolver;
387-
}
388350
}

app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
use Magento\Checkout\Helper\Data;
1111
use Magento\Customer\Model\AttributeMetadataDataProvider;
1212
use Magento\Customer\Model\Options;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
1414
use Magento\Ui\Component\Form\AttributeMapper;
1515
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1616

1717
/**
18-
* LayoutProcessorTest covers a list of variations for
19-
* checkout layout processor
20-
*
21-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
* LayoutProcessorTest covers a list of variations for checkout layout processor
2219
*/
2320
class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
2421
{
@@ -50,12 +47,10 @@ class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
5047
/**
5148
* @var MockObject
5249
*/
53-
private $storeResolver;
50+
private $storeManager;
5451

5552
protected function setUp()
5653
{
57-
$objectManager = new ObjectManager($this);
58-
5954
$this->attributeDataProvider = $this->getMockBuilder(AttributeMetadataDataProvider::class)
6055
->disableOriginalConstructor()
6156
->setMethods(['loadAttributesCollection'])
@@ -80,17 +75,21 @@ protected function setUp()
8075
->disableOriginalConstructor()
8176
->getMock();
8277

78+
$shippingConfig = $this->getMockBuilder(\Magento\Shipping\Model\Config::class)
79+
->disableOriginalConstructor()
80+
->getMock();
81+
82+
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
83+
8384
$this->layoutProcessor = new LayoutProcessor(
8485
$this->attributeDataProvider,
8586
$this->attributeMapper,
86-
$this->attributeMerger
87+
$this->attributeMerger,
88+
$options,
89+
$this->dataHelper,
90+
$shippingConfig,
91+
$this->storeManager
8792
);
88-
89-
$this->storeResolver = $this->createMock(\Magento\Store\Api\StoreResolverInterface::class);
90-
91-
$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'checkoutDataHelper', $this->dataHelper);
92-
$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'options', $options);
93-
$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'storeResolver', $this->storeResolver);
9493
}
9594

9695
/**
@@ -277,7 +276,7 @@ private function getBillingComponent($paymentCode)
277276
'telephone' => [
278277
'config' => [
279278
'tooltip' => [
280-
'description' => __('For delivery questions.'),
279+
'description' => ('For delivery questions.'),
281280
],
282281
],
283282
],

app/code/Magento/Cms/Block/Adminhtml/Page/Grid/Renderer/Action/UrlBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66
namespace Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action;
77

8-
use Magento\Store\Api\StoreResolverInterface;
9-
8+
/**
9+
* Url builder class used to compose dynamic urls.
10+
*/
1011
class UrlBuilder
1112
{
1213
/**
@@ -38,7 +39,7 @@ public function getUrl($routePath, $scope, $store)
3839
[
3940
'_current' => false,
4041
'_nosid' => true,
41-
'_query' => [StoreResolverInterface::PARAM_NAME => $store]
42+
'_query' => [\Magento\Store\Model\StoreManagerInterface::PARAM_NAME => $store]
4243
]
4344
);
4445

0 commit comments

Comments
 (0)