Skip to content

Commit 3858455

Browse files
author
Aleksandr Osadchyi
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-61725
2 parents bd7eecf + 732d445 commit 3858455

File tree

65 files changed

+4701
-2665
lines changed

Some content is hidden

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

65 files changed

+4701
-2665
lines changed

app/code/Magento/Catalog/Block/Product/View/Gallery.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ public function getGalleryImages()
6363
);
6464
$image->setData(
6565
'medium_image_url',
66-
$this->_imageHelper->init($product, 'product_page_image_medium')
67-
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
66+
$this->_imageHelper->init($product, 'product_page_image_medium_no_frame')
6867
->setImageFile($image->getFile())
6968
->getUrl()
7069
);
7170
$image->setData(
7271
'large_image_url',
73-
$this->_imageHelper->init($product, 'product_page_image_large')
74-
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
72+
$this->_imageHelper->init($product, 'product_page_image_large_no_frame')
7573
->setImageFile($image->getFile())
7674
->getUrl()
7775
);

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ public function init($product, $imageId, $attributes = [])
195195
protected function setImageProperties()
196196
{
197197
$this->_getModel()->setDestinationSubdir($this->getType());
198-
199198
$this->_getModel()->setWidth($this->getWidth());
200199
$this->_getModel()->setHeight($this->getHeight());
201200

@@ -241,25 +240,25 @@ protected function setWatermarkProperties()
241240
{
242241
$this->setWatermark(
243242
$this->scopeConfig->getValue(
244-
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_image",
243+
"design/watermark/{$this->getType()}_image",
245244
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
246245
)
247246
);
248247
$this->setWatermarkImageOpacity(
249248
$this->scopeConfig->getValue(
250-
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity",
249+
"design/watermark/{$this->getType()}_imageOpacity",
251250
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
252251
)
253252
);
254253
$this->setWatermarkPosition(
255254
$this->scopeConfig->getValue(
256-
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_position",
255+
"design/watermark/{$this->getType()}_position",
257256
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
258257
)
259258
);
260259
$this->setWatermarkSize(
261260
$this->scopeConfig->getValue(
262-
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_size",
261+
"design/watermark/{$this->getType()}_size",
263262
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
264263
)
265264
);
@@ -500,10 +499,7 @@ protected function initBaseFile()
500499
protected function isScheduledActionsAllowed()
501500
{
502501
$model = $this->_getModel();
503-
if ($model->isBaseFilePlaceholder()
504-
&& $model->getNewFile() === true
505-
|| $model->isCached()
506-
) {
502+
if ($model->isBaseFilePlaceholder() || $model->isCached()) {
507503
return false;
508504
}
509505
return true;

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Eav\Model\Entity\Type;
1616
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1717
use Magento\Framework\Stdlib\ArrayManager;
18+
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\Filesystem;
1820
use Magento\Store\Model\Store;
1921
use Magento\Store\Model\StoreManagerInterface;
2022
use Magento\Ui\Component\Form\Field;
@@ -126,6 +128,11 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
126128
*/
127129
private $arrayManager;
128130

131+
/**
132+
* @var Filesystem
133+
*/
134+
private $fileInfo;
135+
129136
/**
130137
* DataProvider constructor
131138
*
@@ -483,8 +490,16 @@ private function convertValues($category, $categoryData)
483490
if ($attribute->getBackend() instanceof ImageBackendModel) {
484491
unset($categoryData[$attributeCode]);
485492

486-
$categoryData[$attributeCode][0]['name'] = $category->getData($attributeCode);
487-
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
493+
$fileName = $category->getData($attributeCode);
494+
if ($this->getFileInfo()->isExist($fileName)) {
495+
$stat = $this->getFileInfo()->getStat($fileName);
496+
$mime = $this->getFileInfo()->getMimeType($fileName);
497+
498+
$categoryData[$attributeCode][0]['name'] = $fileName;
499+
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
500+
$categoryData['image'][0]['size'] = isset($stat) ? $stat['size'] : 0;
501+
$categoryData['image'][0]['type'] = $mime;
502+
}
488503
}
489504
}
490505

@@ -605,4 +620,19 @@ private function getArrayManager()
605620

606621
return $this->arrayManager;
607622
}
623+
624+
/**
625+
* Get FileInfo instance
626+
*
627+
* @return FileInfo
628+
*
629+
* @deprecated
630+
*/
631+
private function getFileInfo()
632+
{
633+
if ($this->fileInfo === null) {
634+
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);
635+
}
636+
return $this->fileInfo;
637+
}
608638
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Category;
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\File\Mime;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\Filesystem\Directory\WriteInterface;
12+
13+
/**
14+
* Class FileInfo
15+
*
16+
* Provides information about requested file
17+
*/
18+
class FileInfo
19+
{
20+
/**
21+
* Path in /pub/media directory
22+
*/
23+
const ENTITY_MEDIA_PATH = '/catalog/category';
24+
25+
/**
26+
* @var Filesystem
27+
*/
28+
private $filesystem;
29+
30+
/**
31+
* @var Mime
32+
*/
33+
private $mime;
34+
35+
/**
36+
* @var WriteInterface
37+
*/
38+
private $mediaDirectory;
39+
40+
/**
41+
* @param Filesystem $filesystem
42+
* @param Mime $mime
43+
*/
44+
public function __construct(
45+
Filesystem $filesystem,
46+
Mime $mime
47+
) {
48+
$this->filesystem = $filesystem;
49+
$this->mime = $mime;
50+
}
51+
52+
/**
53+
* Get WriteInterface instance
54+
*
55+
* @return WriteInterface
56+
*/
57+
private function getMediaDirectory()
58+
{
59+
if ($this->mediaDirectory === null) {
60+
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
61+
}
62+
return $this->mediaDirectory;
63+
}
64+
65+
/**
66+
* Retrieve MIME type of requested file
67+
*
68+
* @param string $fileName
69+
* @return string
70+
*/
71+
public function getMimeType($fileName)
72+
{
73+
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');
74+
$absoluteFilePath = $this->getMediaDirectory()->getAbsolutePath($filePath);
75+
76+
$result = $this->mime->getMimeType($absoluteFilePath);
77+
return $result;
78+
}
79+
80+
/**
81+
* Get file statistics data
82+
*
83+
* @param string $fileName
84+
* @return array
85+
*/
86+
public function getStat($fileName)
87+
{
88+
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');
89+
90+
$result = $this->getMediaDirectory()->stat($filePath);
91+
return $result;
92+
}
93+
94+
/**
95+
* Check if the file exists
96+
*
97+
* @param string $fileName
98+
* @return bool
99+
*/
100+
public function isExist($fileName)
101+
{
102+
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');
103+
104+
$result = $this->getMediaDirectory()->isExist($filePath);
105+
return $result;
106+
}
107+
}

0 commit comments

Comments
 (0)