Skip to content

Commit 5560303

Browse files
authored
Merge pull request #5183 from magento-tango/Tango-PR-01-08-2020-23
Tango PR 01-08-2019 Magento 2.3
2 parents 08ed603 + 173b218 commit 5560303

File tree

16 files changed

+474
-304
lines changed

16 files changed

+474
-304
lines changed

app/code/Magento/Catalog/Model/Product/Image/ParamsBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ private function getWatermark(string $type, int $scopeId = null): array
132132
if ($file) {
133133
$size = explode(
134134
'x',
135-
$this->scopeConfig->getValue(
135+
(string) $this->scopeConfig->getValue(
136136
"design/watermark/{$type}_size",
137-
ScopeInterface::SCOPE_STORE
137+
ScopeInterface::SCOPE_STORE,
138+
$scopeId
138139
)
139140
);
140141
$opacity = $this->scopeConfig->getValue(

app/code/Magento/Catalog/Test/Unit/Model/Product/Image/ParamsBuilderTest.php

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Test\Unit\Model\Product\Image;
89

@@ -11,10 +12,15 @@
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
1314
use Magento\Framework\Config\View;
15+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1416
use Magento\Framework\View\ConfigInterface;
1517
use Magento\Store\Model\ScopeInterface;
18+
use PHPUnit\Framework\TestCase;
1619

17-
class ParamsBuilderTest extends \PHPUnit\Framework\TestCase
20+
/**
21+
* Test product image params builder
22+
*/
23+
class ParamsBuilderTest extends TestCase
1824
{
1925
/**
2026
* @var ScopeConfigInterface
@@ -30,10 +36,17 @@ class ParamsBuilderTest extends \PHPUnit\Framework\TestCase
3036
* @var ParamsBuilder
3137
*/
3238
private $model;
39+
/**
40+
* @var array
41+
*/
42+
private $scopeConfigData = [];
3343

44+
/**
45+
* @inheritDoc
46+
*/
3447
protected function setUp()
3548
{
36-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
49+
$objectManager = new ObjectManager($this);
3750
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
3851
$this->viewConfig = $this->createMock(ConfigInterface::class);
3952
$this->model = $objectManager->getObject(
@@ -43,28 +56,37 @@ protected function setUp()
4356
'viewConfig' => $this->viewConfig,
4457
]
4558
);
59+
$this->scopeConfigData = [];
60+
$this->scopeConfig->method('getValue')
61+
->willReturnCallback(
62+
function ($path, $scopeType, $scopeCode) {
63+
return $this->scopeConfigData[$path][$scopeType][$scopeCode] ?? null;
64+
}
65+
);
4666
}
4767

4868
/**
49-
* Test watermark location.
69+
* Test build() with different parameters and config values
70+
*
71+
* @param int $scopeId
72+
* @param array $config
73+
* @param array $imageArguments
74+
* @param array $expected
75+
* @dataProvider buildDataProvider
5076
*/
51-
public function testWatermarkLocation()
77+
public function testBuild(int $scopeId, array $config, array $imageArguments, array $expected)
5278
{
53-
$imageArguments = [
54-
'type' => 'type',
55-
'height' => 'image_height',
56-
'width' => 'image_width',
57-
'angle' => 'angle',
58-
'background' => [1, 2, 3]
79+
$this->scopeConfigData[Image::XML_PATH_JPEG_QUALITY][ScopeConfigInterface::SCOPE_TYPE_DEFAULT][null] = 80;
80+
foreach ($config as $path => $value) {
81+
$this->scopeConfigData[$path][ScopeInterface::SCOPE_STORE][$scopeId] = $value;
82+
}
83+
$imageArguments += [
84+
'type' => 'image',
85+
'height' => '600',
86+
'width' => '400',
87+
'angle' => '45',
88+
'background' => [110, 64, 224]
5989
];
60-
$scopeId = 1;
61-
$quality = 100;
62-
$file = 'file';
63-
$width = 'width';
64-
$height = 'height';
65-
$size = "{$width}x{$height}";
66-
$opacity = 'opacity';
67-
$position = 'position';
6890

6991
$viewMock = $this->createMock(View::class);
7092
$viewMock->expects($this->once())
@@ -77,51 +99,16 @@ public function testWatermarkLocation()
7799
->with(['area' => Area::AREA_FRONTEND])
78100
->willReturn($viewMock);
79101

80-
$this->scopeConfig->expects($this->exactly(5))->method('getValue')->withConsecutive(
81-
[
82-
Image::XML_PATH_JPEG_QUALITY
83-
],
84-
[
85-
"design/watermark/{$imageArguments['type']}_image",
86-
ScopeInterface::SCOPE_STORE,
87-
$scopeId,
88-
],
89-
[
90-
"design/watermark/{$imageArguments['type']}_size",
91-
ScopeInterface::SCOPE_STORE],
92-
[
93-
"design/watermark/{$imageArguments['type']}_imageOpacity",
94-
ScopeInterface::SCOPE_STORE,
95-
$scopeId
96-
],
97-
[
98-
"design/watermark/{$imageArguments['type']}_position",
99-
ScopeInterface::SCOPE_STORE,
100-
$scopeId
101-
]
102-
)->willReturnOnConsecutiveCalls(
103-
$quality,
104-
$file,
105-
$size,
106-
$opacity,
107-
$position
108-
);
109-
110102
$actual = $this->model->build($imageArguments, $scopeId);
111-
$expected = [
103+
$expected += [
112104
'image_type' => $imageArguments['type'],
113105
'background' => $imageArguments['background'],
114106
'angle' => $imageArguments['angle'],
115-
'quality' => $quality,
107+
'quality' => 80,
116108
'keep_aspect_ratio' => true,
117109
'keep_frame' => true,
118110
'keep_transparency' => true,
119111
'constrain_only' => true,
120-
'watermark_file' => $file,
121-
'watermark_image_opacity' => $opacity,
122-
'watermark_position' => $position,
123-
'watermark_width' => $width,
124-
'watermark_height' => $height,
125112
'image_height' => $imageArguments['height'],
126113
'image_width' => $imageArguments['width'],
127114
];
@@ -131,4 +118,50 @@ public function testWatermarkLocation()
131118
$actual
132119
);
133120
}
121+
122+
/**
123+
* Provides test scenarios for
124+
*
125+
* @return array
126+
*/
127+
public function buildDataProvider()
128+
{
129+
return [
130+
'watermark config' => [
131+
1,
132+
[
133+
'design/watermark/small_image_image' => 'stores/1/magento-logo.png',
134+
'design/watermark/small_image_size' => '60x40',
135+
'design/watermark/small_image_imageOpacity' => '50',
136+
'design/watermark/small_image_position' => 'bottom-right',
137+
],
138+
[
139+
'type' => 'small_image'
140+
],
141+
[
142+
'watermark_file' => 'stores/1/magento-logo.png',
143+
'watermark_image_opacity' => '50',
144+
'watermark_position' => 'bottom-right',
145+
'watermark_width' => '60',
146+
'watermark_height' => '40',
147+
]
148+
],
149+
'watermark config empty' => [
150+
1,
151+
[
152+
'design/watermark/small_image_image' => 'stores/1/magento-logo.png',
153+
],
154+
[
155+
'type' => 'small_image'
156+
],
157+
[
158+
'watermark_file' => 'stores/1/magento-logo.png',
159+
'watermark_image_opacity' => null,
160+
'watermark_position' => null,
161+
'watermark_width' => null,
162+
'watermark_height' => null,
163+
]
164+
]
165+
];
166+
}
134167
}

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ private function updateAnchorCategoryConditions(array $condition): array
373373
return $condition;
374374
}
375375

376-
if ($category->getIsAnchor() && $category->getChildren()) {
377-
$children = explode(',', $category->getChildren());
378-
376+
$children = $category->getIsAnchor() ? $category->getChildren(true) : [];
377+
if ($children) {
378+
$children = explode(',', $children);
379379
$condition['operator'] = "()";
380380
$condition['value'] = array_merge([$categoryId], $children);
381381
}

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ define([
214214
this.reload(storageInvalidation.keys(), false);
215215
}
216216
}
217+
218+
if (!_.isEmpty($.cookieStorage.get('section_data_clean'))) {
219+
this.reload(sectionConfig.getSectionNames(), true);
220+
$.cookieStorage.set('section_data_clean', '');
221+
}
217222
},
218223

219224
/**

app/code/Magento/Elasticsearch/Model/ResourceModel/Fulltext/Collection/SearchResultApplier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace Magento\Elasticsearch\Model\ResourceModel\Fulltext\Collection;
88

99
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
10-
use Magento\Framework\Data\Collection;
1110
use Magento\Framework\Api\Search\SearchResultInterface;
11+
use Magento\Framework\Data\Collection;
1212

1313
/**
1414
* Resolve specific attributes for search criteria.
@@ -71,7 +71,7 @@ public function apply()
7171
$this->collection->getSelect()->where('e.entity_id IN (?)', $ids);
7272
$orderList = join(',', $ids);
7373
$this->collection->getSelect()->reset(\Magento\Framework\DB\Select::ORDER);
74-
$this->collection->getSelect()->order("FIELD(e.entity_id,$orderList)");
74+
$this->collection->getSelect()->order(new \Zend_Db_Expr("FIELD(e.entity_id,$orderList)"));
7575
}
7676

7777
/**

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77

88
namespace Magento\Store\Controller\Store;
99

10+
use Magento\Framework\App\Action\Action;
1011
use Magento\Framework\App\Action\Context;
1112
use Magento\Framework\App\Action\HttpGetActionInterface;
1213
use Magento\Framework\App\Action\HttpPostActionInterface;
13-
use Magento\Framework\App\ResponseInterface;
1414
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Framework\Session\Generic;
1516
use Magento\Store\Api\StoreRepositoryInterface;
1617
use Magento\Store\Api\StoreResolverInterface;
18+
use Magento\Store\Model\Store;
1719
use Magento\Store\Model\StoreResolver;
1820
use Magento\Framework\Session\SidResolverInterface;
21+
use Magento\Store\Model\StoreSwitcher\HashGenerator;
1922

2023
/**
2124
* Builds correct url to target store (group) and performs redirect.
2225
*/
23-
class Redirect extends \Magento\Framework\App\Action\Action implements HttpGetActionInterface, HttpPostActionInterface
26+
class Redirect extends Action implements HttpGetActionInterface, HttpPostActionInterface
2427
{
2528
/**
2629
* @var StoreRepositoryInterface
@@ -32,24 +35,32 @@ class Redirect extends \Magento\Framework\App\Action\Action implements HttpGetAc
3235
*/
3336
private $storeResolver;
3437

38+
/**
39+
* @var HashGenerator
40+
*/
41+
private $hashGenerator;
42+
3543
/**
3644
* @param Context $context
3745
* @param StoreRepositoryInterface $storeRepository
3846
* @param StoreResolverInterface $storeResolver
39-
* @param \Magento\Framework\Session\Generic $session
47+
* @param Generic $session
4048
* @param SidResolverInterface $sidResolver
49+
* @param HashGenerator $hashGenerator
4150
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4251
*/
4352
public function __construct(
4453
Context $context,
4554
StoreRepositoryInterface $storeRepository,
4655
StoreResolverInterface $storeResolver,
47-
\Magento\Framework\Session\Generic $session,
48-
SidResolverInterface $sidResolver
56+
Generic $session,
57+
SidResolverInterface $sidResolver,
58+
HashGenerator $hashGenerator
4959
) {
5060
parent::__construct($context);
5161
$this->storeRepository = $storeRepository;
5262
$this->storeResolver = $storeResolver;
63+
$this->hashGenerator = $hashGenerator;
5364
}
5465

5566
/**
@@ -59,7 +70,7 @@ public function __construct(
5970
*/
6071
public function execute()
6172
{
62-
/** @var \Magento\Store\Model\Store $currentStore */
73+
/** @var Store $currentStore */
6374
$currentStore = $this->storeRepository->getById($this->storeResolver->getCurrentStoreId());
6475
$targetStoreCode = $this->_request->getParam(StoreResolver::PARAM_NAME);
6576
$fromStoreCode = $this->_request->getParam('___from_store');
@@ -70,7 +81,7 @@ public function execute()
7081
}
7182

7283
try {
73-
/** @var \Magento\Store\Model\Store $targetStore */
84+
/** @var Store $fromStore */
7485
$fromStore = $this->storeRepository->get($fromStoreCode);
7586
} catch (NoSuchEntityException $e) {
7687
$error = __('Requested store is not found');
@@ -88,6 +99,9 @@ public function execute()
8899
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $encodedUrl,
89100
];
90101

102+
$customerHash = $this->hashGenerator->generateHash($fromStore);
103+
$query = array_merge($query, $customerHash);
104+
91105
$arguments = [
92106
'_nosid' => true,
93107
'_query' => $query

0 commit comments

Comments
 (0)