Skip to content

Commit ebee07a

Browse files
authored
Merge pull request #4713 from magento-chaika/Chaika-PR-2019-08-29-2
Chaika-PR-2019-08-29-2
2 parents 0ebdbf1 + 56d9193 commit ebee07a

File tree

11 files changed

+212
-52
lines changed

11 files changed

+212
-52
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ public function __construct(
6868
* Build image params
6969
*
7070
* @param array $imageArguments
71+
* @param int $scopeId
7172
* @return array
7273
* @SuppressWarnings(PHPMD.NPathComplexity)
7374
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7475
*/
75-
public function build(array $imageArguments): array
76+
public function build(array $imageArguments, int $scopeId = null): array
7677
{
7778
$miscParams = [
7879
'image_type' => $imageArguments['type'] ?? null,
@@ -81,7 +82,7 @@ public function build(array $imageArguments): array
8182
];
8283

8384
$overwritten = $this->overwriteDefaultValues($imageArguments);
84-
$watermark = isset($miscParams['image_type']) ? $this->getWatermark($miscParams['image_type']) : [];
85+
$watermark = isset($miscParams['image_type']) ? $this->getWatermark($miscParams['image_type'], $scopeId) : [];
8586

8687
return array_merge($miscParams, $overwritten, $watermark);
8788
}
@@ -117,27 +118,32 @@ private function overwriteDefaultValues(array $imageArguments): array
117118
* Get watermark
118119
*
119120
* @param string $type
121+
* @param int $scopeId
120122
* @return array
121123
*/
122-
private function getWatermark(string $type): array
124+
private function getWatermark(string $type, int $scopeId = null): array
123125
{
124126
$file = $this->scopeConfig->getValue(
125127
"design/watermark/{$type}_image",
126-
ScopeInterface::SCOPE_STORE
128+
ScopeInterface::SCOPE_STORE,
129+
$scopeId
127130
);
128131

129132
if ($file) {
130133
$size = $this->scopeConfig->getValue(
131134
"design/watermark/{$type}_size",
132-
ScopeInterface::SCOPE_STORE
135+
ScopeInterface::SCOPE_STORE,
136+
$scopeId
133137
);
134138
$opacity = $this->scopeConfig->getValue(
135139
"design/watermark/{$type}_imageOpacity",
136-
ScopeInterface::SCOPE_STORE
140+
ScopeInterface::SCOPE_STORE,
141+
$scopeId
137142
);
138143
$position = $this->scopeConfig->getValue(
139144
"design/watermark/{$type}_position",
140-
ScopeInterface::SCOPE_STORE
145+
ScopeInterface::SCOPE_STORE,
146+
$scopeId
141147
);
142148
$width = !empty($size['width']) ? $size['width'] : null;
143149
$height = !empty($size['height']) ? $size['height'] : null;

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,16 @@ protected function _populateForUrlGeneration($rowData)
299299
*/
300300
private function isNeedToPopulateForUrlGeneration($rowData, $newSku, $oldSku): bool
301301
{
302-
if ((empty($newSku) || !isset($newSku['entity_id']))
303-
|| ($this->import->getRowScope($rowData) == ImportProduct::SCOPE_STORE
304-
&& empty($rowData[self::URL_KEY_ATTRIBUTE_CODE]))
305-
|| (array_key_exists($rowData[ImportProduct::COL_SKU], $oldSku)
306-
&& !isset($rowData[self::URL_KEY_ATTRIBUTE_CODE])
307-
&& $this->import->getBehavior() === ImportExport::BEHAVIOR_APPEND)) {
302+
if ((
303+
(empty($newSku) || !isset($newSku['entity_id']))
304+
|| ($this->import->getRowScope($rowData) == ImportProduct::SCOPE_STORE
305+
&& empty($rowData[self::URL_KEY_ATTRIBUTE_CODE]))
306+
|| (array_key_exists(strtolower($rowData[ImportProduct::COL_SKU]), $oldSku)
307+
&& !isset($rowData[self::URL_KEY_ATTRIBUTE_CODE])
308+
&& $this->import->getBehavior() === ImportExport::BEHAVIOR_APPEND)
309+
)
310+
&& !isset($rowData["categories"])
311+
) {
308312
return false;
309313
}
310314
return true;
@@ -477,7 +481,7 @@ protected function currentUrlRewritesRegenerate()
477481
$url = $currentUrlRewrite->getIsAutogenerated()
478482
? $this->generateForAutogenerated($currentUrlRewrite, $category)
479483
: $this->generateForCustom($currentUrlRewrite, $category);
480-
$urlRewrites = array_merge($urlRewrites, $url);
484+
$urlRewrites = $url + $urlRewrites;
481485
}
482486

483487
$this->product = null;

app/code/Magento/MediaStorage/Service/ImageResize.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace Magento\MediaStorage\Service;
99

10+
use Generator;
1011
use Magento\Catalog\Helper\Image as ImageHelper;
1112
use Magento\Catalog\Model\Product\Image\ParamsBuilder;
1213
use Magento\Catalog\Model\View\Asset\ImageFactory as AssertImageFactory;
1314
use Magento\Framework\App\Area;
15+
use Magento\Framework\App\ObjectManager;
1416
use Magento\Framework\Exception\NotFoundException;
1517
use Magento\Framework\Filesystem;
1618
use Magento\Framework\Image;
@@ -19,10 +21,12 @@
1921
use Magento\Framework\App\State;
2022
use Magento\Framework\View\ConfigInterface as ViewConfig;
2123
use \Magento\Catalog\Model\ResourceModel\Product\Image as ProductImage;
24+
use Magento\Store\Model\StoreManagerInterface;
2225
use Magento\Theme\Model\Config\Customization as ThemeCustomizationConfig;
2326
use Magento\Theme\Model\ResourceModel\Theme\Collection;
2427
use Magento\Framework\App\Filesystem\DirectoryList;
2528
use Magento\MediaStorage\Helper\File\Storage\Database;
29+
use Magento\Theme\Model\Theme;
2630

2731
/**
2832
* Image resize service.
@@ -90,6 +94,10 @@ class ImageResize
9094
* @var Database
9195
*/
9296
private $fileStorageDatabase;
97+
/**
98+
* @var StoreManagerInterface
99+
*/
100+
private $storeManager;
93101

94102
/**
95103
* @param State $appState
@@ -103,6 +111,8 @@ class ImageResize
103111
* @param Collection $themeCollection
104112
* @param Filesystem $filesystem
105113
* @param Database $fileStorageDatabase
114+
* @param StoreManagerInterface $storeManager
115+
* @throws \Magento\Framework\Exception\FileSystemException
106116
* @internal param ProductImage $gallery
107117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
108118
*/
@@ -117,7 +127,8 @@ public function __construct(
117127
ThemeCustomizationConfig $themeCustomizationConfig,
118128
Collection $themeCollection,
119129
Filesystem $filesystem,
120-
Database $fileStorageDatabase = null
130+
Database $fileStorageDatabase = null,
131+
StoreManagerInterface $storeManager = null
121132
) {
122133
$this->appState = $appState;
123134
$this->imageConfig = $imageConfig;
@@ -131,7 +142,8 @@ public function __construct(
131142
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
132143
$this->filesystem = $filesystem;
133144
$this->fileStorageDatabase = $fileStorageDatabase ?:
134-
\Magento\Framework\App\ObjectManager::getInstance()->get(Database::class);
145+
ObjectManager::getInstance()->get(Database::class);
146+
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
135147
}
136148

137149
/**
@@ -163,10 +175,10 @@ public function resizeFromImageName(string $originalImageName)
163175
* Create resized images of different sizes from themes.
164176
*
165177
* @param array|null $themes
166-
* @return \Generator
178+
* @return Generator
167179
* @throws NotFoundException
168180
*/
169-
public function resizeFromThemes(array $themes = null): \Generator
181+
public function resizeFromThemes(array $themes = null): Generator
170182
{
171183
$count = $this->productImage->getCountUsedProductImages();
172184
if (!$count) {
@@ -226,7 +238,8 @@ private function getThemesInUse(): array
226238
private function getViewImages(array $themes): array
227239
{
228240
$viewImages = [];
229-
/** @var \Magento\Theme\Model\Theme $theme */
241+
$stores = $this->storeManager->getStores(true);
242+
/** @var Theme $theme */
230243
foreach ($themes as $theme) {
231244
$config = $this->viewConfig->getViewConfig(
232245
[
@@ -236,9 +249,12 @@ private function getViewImages(array $themes): array
236249
);
237250
$images = $config->getMediaEntities('Magento_Catalog', ImageHelper::MEDIA_TYPE_CONFIG_NODE);
238251
foreach ($images as $imageId => $imageData) {
239-
$uniqIndex = $this->getUniqueImageIndex($imageData);
240-
$imageData['id'] = $imageId;
241-
$viewImages[$uniqIndex] = $imageData;
252+
foreach ($stores as $store) {
253+
$data = $this->paramsBuilder->build($imageData, (int) $store->getId());
254+
$uniqIndex = $this->getUniqueImageIndex($data);
255+
$data['id'] = $imageId;
256+
$viewImages[$uniqIndex] = $data;
257+
}
242258
}
243259
}
244260
return $viewImages;
@@ -280,13 +296,13 @@ private function makeImage(string $originalImagePath, array $imageParams): Image
280296
/**
281297
* Resize image.
282298
*
283-
* @param array $viewImage
299+
* @param array $imageParams
284300
* @param string $originalImagePath
285301
* @param string $originalImageName
286302
*/
287-
private function resize(array $viewImage, string $originalImagePath, string $originalImageName)
303+
private function resize(array $imageParams, string $originalImagePath, string $originalImageName)
288304
{
289-
$imageParams = $this->paramsBuilder->build($viewImage);
305+
unset($imageParams['id']);
290306
$image = $this->makeImage($originalImagePath, $imageParams);
291307
$imageAsset = $this->assertImageFactory->create(
292308
[

app/code/Magento/MediaStorage/Test/Unit/Service/ImageResizeTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\View\ConfigInterface as ViewConfig;
1818
use Magento\Framework\Config\View;
1919
use Magento\Catalog\Model\ResourceModel\Product\Image as ProductImage;
20+
use Magento\Store\Model\StoreManagerInterface;
2021
use Magento\Theme\Model\Config\Customization as ThemeCustomizationConfig;
2122
use Magento\Theme\Model\ResourceModel\Theme\Collection;
2223
use Magento\MediaStorage\Helper\File\Storage\Database;
@@ -119,7 +120,15 @@ class ImageResizeTest extends \PHPUnit\Framework\TestCase
119120
* @var string
120121
*/
121122
private $testfilepath;
123+
/**
124+
* @var \PHPUnit\Framework\MockObject\MockObject|StoreManagerInterface
125+
*/
126+
private $storeManager;
122127

128+
/**
129+
* @inheritDoc
130+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
131+
*/
123132
protected function setUp()
124133
{
125134
$this->testfilename = "image.jpg";
@@ -139,6 +148,7 @@ protected function setUp()
139148
$this->themeCollectionMock = $this->createMock(Collection::class);
140149
$this->filesystemMock = $this->createMock(Filesystem::class);
141150
$this->databaseMock = $this->createMock(Database::class);
151+
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
142152

143153
$this->mediaDirectoryMock = $this->getMockBuilder(Filesystem::class)
144154
->disableOriginalConstructor()
@@ -203,6 +213,16 @@ protected function setUp()
203213
->method('getViewConfig')
204214
->willReturn($this->viewMock);
205215

216+
$store = $this->getMockForAbstractClass(\Magento\Store\Api\Data\StoreInterface::class);
217+
$store
218+
->expects($this->any())
219+
->method('getId')
220+
->willReturn(1);
221+
$this->storeManager
222+
->expects($this->any())
223+
->method('getStores')
224+
->willReturn([$store]);
225+
206226
$this->service = new \Magento\MediaStorage\Service\ImageResize(
207227
$this->appStateMock,
208228
$this->imageConfigMock,
@@ -214,7 +234,8 @@ protected function setUp()
214234
$this->themeCustomizationConfigMock,
215235
$this->themeCollectionMock,
216236
$this->filesystemMock,
217-
$this->databaseMock
237+
$this->databaseMock,
238+
$this->storeManager
218239
);
219240
}
220241

app/code/Magento/Paypal/Model/SmartButtonConfig.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\Paypal\Model;
99

10+
use Magento\Checkout\Helper\Data;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\Locale\ResolverInterface;
13+
use Magento\Store\Model\ScopeInterface;
1114

1215
/**
1316
* Smart button config
@@ -34,21 +37,29 @@ class SmartButtonConfig
3437
*/
3538
private $allowedFunding;
3639

40+
/**
41+
* @var ScopeConfigInterface
42+
*/
43+
private $scopeConfig;
44+
3745
/**
3846
* @param ResolverInterface $localeResolver
3947
* @param ConfigFactory $configFactory
48+
* @param ScopeConfigInterface $scopeConfig
4049
* @param array $defaultStyles
4150
* @param array $allowedFunding
4251
*/
4352
public function __construct(
4453
ResolverInterface $localeResolver,
4554
ConfigFactory $configFactory,
55+
ScopeConfigInterface $scopeConfig,
4656
$defaultStyles = [],
4757
$allowedFunding = []
4858
) {
4959
$this->localeResolver = $localeResolver;
5060
$this->config = $configFactory->create();
5161
$this->config->setMethod(Config::METHOD_EXPRESS);
62+
$this->scopeConfig = $scopeConfig;
5263
$this->defaultStyles = $defaultStyles;
5364
$this->allowedFunding = $allowedFunding;
5465
}
@@ -61,14 +72,19 @@ public function __construct(
6172
*/
6273
public function getConfig(string $page): array
6374
{
75+
$isGuestCheckoutAllowed = $this->scopeConfig->isSetFlag(
76+
Data::XML_PATH_GUEST_CHECKOUT,
77+
ScopeInterface::SCOPE_STORE
78+
);
6479
return [
6580
'merchantId' => $this->config->getValue('merchant_id'),
6681
'environment' => ((int)$this->config->getValue('sandbox_flag') ? 'sandbox' : 'production'),
6782
'locale' => $this->localeResolver->getLocale(),
6883
'allowedFunding' => $this->getAllowedFunding($page),
6984
'disallowedFunding' => $this->getDisallowedFunding(),
7085
'styles' => $this->getButtonStyles($page),
71-
'isVisibleOnProductPage' => (int)$this->config->getValue('visible_on_product')
86+
'isVisibleOnProductPage' => $this->config->getValue('visible_on_product'),
87+
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed
7288
];
7389
}
7490

0 commit comments

Comments
 (0)