Skip to content

Commit 9374faf

Browse files
author
Robert He
committed
Merge branch 'MAGETWO-58312-Products-Out-Of-Stock' into MAGETWO-60060-Release-Publication
2 parents c39809b + 7a2a5c9 commit 9374faf

File tree

195 files changed

+7436
-1699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+7436
-1699
lines changed

app/code/Magento/Backend/App/Config.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,66 @@
1010

1111
namespace Magento\Backend\App;
1212

13+
use Magento\Config\App\Config\Type\System;
1314
use Magento\Framework\App\Config\ScopeConfigInterface;
1415

1516
/**
16-
* Backend config accessor
17+
* Backend config accessor.
1718
*/
1819
class Config implements ConfigInterface
1920
{
2021
/**
21-
* @var \Magento\Framework\App\Config\ScopePool
22+
* @var \Magento\Framework\App\Config
2223
*/
23-
protected $_scopePool;
24+
protected $appConfig;
2425

2526
/**
26-
* @param \Magento\Framework\App\Config\ScopePool $scopePool
27+
* @var array
2728
*/
28-
public function __construct(\Magento\Framework\App\Config\ScopePool $scopePool)
29+
private $data;
30+
31+
/**
32+
* @param \Magento\Framework\App\Config $appConfig
33+
* @return void
34+
*/
35+
public function __construct(\Magento\Framework\App\Config $appConfig)
2936
{
30-
$this->_scopePool = $scopePool;
37+
$this->appConfig = $appConfig;
3138
}
3239

3340
/**
34-
* Retrieve config value by path and scope
35-
*
36-
* @param string $path
37-
* @return mixed
41+
* @inheritdoc
3842
*/
3943
public function getValue($path)
4044
{
41-
return $this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
45+
if (isset($this->data[$path])) {
46+
return $this->data[$path];
47+
}
48+
49+
$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
50+
if ($path) {
51+
$configPath .= '/' . $path;
52+
}
53+
return $this->appConfig->get(System::CONFIG_TYPE, $configPath);
4254
}
4355

4456
/**
45-
* Set config value in the corresponding config scope
46-
*
47-
* @param string $path
48-
* @param mixed $value
49-
* @return void
57+
* @inheritdoc
5058
*/
5159
public function setValue($path, $value)
5260
{
53-
$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->setValue($path, $value);
61+
$this->data[$path] = $value;
5462
}
5563

5664
/**
57-
* Retrieve config flag
58-
*
59-
* @param string $path
60-
* @return bool
65+
* @inheritdoc
6166
*/
6267
public function isSetFlag($path)
6368
{
64-
return !!$this->_scopePool->getScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)->getValue($path);
69+
$configPath = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
70+
if ($path) {
71+
$configPath .= '/' . $path;
72+
}
73+
return (bool) $this->appConfig->get(System::CONFIG_TYPE, $configPath);
6574
}
6675
}

app/code/Magento/Backend/App/ConfigInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface ConfigInterface
1515
/**
1616
* Retrieve config value by path
1717
*
18+
* Path should looks like keys imploded by "/". For example scopes/stores/admin
19+
*
1820
* @param string $path
1921
* @return mixed
2022
* @api
@@ -24,6 +26,7 @@ public function getValue($path);
2426
/**
2527
* Set config value
2628
*
29+
* @deprecated
2730
* @param string $path
2831
* @param mixed $value
2932
* @return void
@@ -34,6 +37,8 @@ public function setValue($path, $value);
3437
/**
3538
* Retrieve config flag
3639
*
40+
* Path should looks like keys imploded by "/". For example scopes/stores/admin
41+
*
3742
* @param string $path
3843
* @return bool
3944
* @api

app/code/Magento/Backend/Test/Unit/App/ConfigTest.php

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
use Magento\Backend\App\Config;
99

10+
/**
11+
* Test reading by path and reading flag from config
12+
*
13+
* @see \Magento\Backend\App\Config
14+
* @package Magento\Backend\Test\Unit\App
15+
*/
1016
class ConfigTest extends \PHPUnit_Framework_TestCase
1117
{
1218
/**
13-
* @var \Magento\Framework\App\Config\ScopePool|\PHPUnit_Framework_MockObject_MockObject
19+
* @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject
1420
*/
15-
protected $sectionPool;
21+
protected $appConfig;
1622

1723
/**
1824
* @var Config
@@ -21,102 +27,64 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
2127

2228
protected function setUp()
2329
{
24-
$this->sectionPool = $this->getMock(
25-
'Magento\Framework\App\Config\ScopePool',
26-
['getScope', 'clean'],
30+
$this->appConfig = $this->getMock(
31+
'Magento\Framework\App\Config',
32+
['get'],
2733
[],
2834
'',
2935
false
3036
);
31-
$this->model = new \Magento\Backend\App\Config($this->sectionPool);
37+
$this->model = new \Magento\Backend\App\Config($this->appConfig);
3238
}
3339

3440
public function testGetValue()
3541
{
3642
$expectedValue = 'some value';
3743
$path = 'some path';
38-
$configData = $this->getConfigDataMock('getValue');
39-
$configData->expects(
40-
$this->once()
41-
)->method(
42-
'getValue'
43-
)->with(
44-
$this->equalTo($path)
45-
)->will(
46-
$this->returnValue($expectedValue)
47-
);
48-
$this->sectionPool->expects(
44+
$this->appConfig->expects(
4945
$this->once()
5046
)->method(
51-
'getScope'
47+
'get'
5248
)->with(
53-
$this->equalTo('default'),
49+
$this->equalTo('system'),
50+
$this->equalTo('default/' . $path),
5451
$this->isNull()
5552
)->will(
56-
$this->returnValue($configData)
53+
$this->returnValue($expectedValue)
5754
);
5855
$this->assertEquals($expectedValue, $this->model->getValue($path));
5956
}
6057

61-
public function testSetValue()
62-
{
63-
$value = 'some value';
64-
$path = 'some path';
65-
$configData = $this->getConfigDataMock('setValue');
66-
$configData->expects($this->once())->method('setValue')->with($this->equalTo($path), $this->equalTo($value));
67-
$this->sectionPool->expects(
68-
$this->once()
69-
)->method(
70-
'getScope'
71-
)->with(
72-
$this->equalTo('default'),
73-
$this->isNull()
74-
)->will(
75-
$this->returnValue($configData)
76-
);
77-
$this->model->setValue($path, $value);
78-
}
79-
8058
/**
59+
* @param string $configPath
8160
* @param mixed $configValue
8261
* @param bool $expectedResult
8362
* @dataProvider isSetFlagDataProvider
8463
*/
85-
public function testIsSetFlag($configValue, $expectedResult)
64+
public function testIsSetFlag($configPath, $configValue, $expectedResult)
8665
{
87-
$path = 'some path';
88-
$configData = $this->getConfigDataMock('getValue');
89-
$configData->expects(
90-
$this->once()
66+
$this->appConfig->expects(
67+
$this->any()
9168
)->method(
92-
'getValue'
69+
'get'
9370
)->with(
94-
$this->equalTo($path)
71+
$this->equalTo('system'),
72+
$this->equalTo('default/' . $configPath)
9573
)->will(
9674
$this->returnValue($configValue)
9775
);
98-
$this->sectionPool->expects(
99-
$this->once()
100-
)->method(
101-
'getScope'
102-
)->with(
103-
$this->equalTo('default'),
104-
$this->isNull()
105-
)->will(
106-
$this->returnValue($configData)
107-
);
108-
$this->assertEquals($expectedResult, $this->model->isSetFlag($path));
76+
$this->assertEquals($expectedResult, $this->model->isSetFlag($configPath));
10977
}
11078

11179
public function isSetFlagDataProvider()
11280
{
11381
return [
114-
[0, false],
115-
[true, true],
116-
['0', false],
117-
['', false],
118-
['some string', true],
119-
[1, true]
82+
['a', 0, false],
83+
['b', true, true],
84+
['c', '0', false],
85+
['d', '', false],
86+
['e', 'some string', true],
87+
['f', 1, true]
12088
];
12189
}
12290

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Eav\Model\Config;
1212
use Magento\Framework\DB\Select;
1313
use Magento\Framework\EntityManager\MetadataPool;
14+
use Magento\Store\Api\StoreResolverInterface;
15+
use Magento\Store\Model\Store;
1416

1517
/**
1618
* Class StatusBaseSelectProcessor
@@ -27,16 +29,24 @@ class StatusBaseSelectProcessor implements BaseSelectProcessorInterface
2729
*/
2830
private $metadataPool;
2931

32+
/**
33+
* @var StoreResolverInterface
34+
*/
35+
private $storeResolver;
36+
3037
/**
3138
* @param Config $eavConfig
3239
* @param MetadataPool $metadataPool
40+
* @param StoreResolverInterface $storeResolver
3341
*/
3442
public function __construct(
3543
Config $eavConfig,
36-
MetadataPool $metadataPool
44+
MetadataPool $metadataPool,
45+
StoreResolverInterface $storeResolver
3746
) {
3847
$this->eavConfig = $eavConfig;
3948
$this->metadataPool = $metadataPool;
49+
$this->storeResolver = $storeResolver;
4050
}
4151

4252
/**
@@ -48,13 +58,23 @@ public function process(Select $select)
4858
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
4959
$statusAttribute = $this->eavConfig->getAttribute(Product::ENTITY, ProductInterface::STATUS);
5060

51-
$select->join(
61+
$select->joinLeft(
62+
['status_global_attr' => $statusAttribute->getBackendTable()],
63+
"status_global_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
64+
. ' AND status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
65+
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID,
66+
[]
67+
);
68+
69+
$select->joinLeft(
5270
['status_attr' => $statusAttribute->getBackendTable()],
53-
sprintf('status_attr.%s = %s.%1$s', $linkField, self::PRODUCT_TABLE_ALIAS),
71+
"status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
72+
. ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
73+
. ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(),
5474
[]
55-
)
56-
->where('status_attr.attribute_id = ?', $statusAttribute->getAttributeId())
57-
->where('status_attr.value = ?', Status::STATUS_ENABLED);
75+
);
76+
77+
$select->where('IFNULL(status_attr.value, status_global_attr.value) = ?', Status::STATUS_ENABLED);
5878

5979
return $select;
6080
}

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
namespace Magento\Catalog\Model\Template;
1616

17+
/**
18+
* Work with catalog(store, website) urls
19+
*
20+
* @package Magento\Catalog\Model\Template
21+
*/
1722
class Filter extends \Magento\Framework\Filter\Template
1823
{
1924
/**

0 commit comments

Comments
 (0)