Skip to content

Commit

Permalink
Merge pull request #646 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Bugs:
- MAGETWO-56072 [Performance] Image resize mechanism does not generate images of all necessary sizes
- MAGETWO-59904 [PR][Github] Update AccountLock.php #6952
- MAGETWO-53550 [Github][PR] Fix newsletter queue subscribers adding performance #4088
- MAGETWO-60047 [Porting] Error on adding address during checkout if add custom customer address attribute of file type - 2.2
- MAGETWO-56396 "Go Today" button in filter type date doesn`t apply value
- MAGETWO-59365 Countries list is not loaded if change customer website after country was selected
- MAGETWO-59924 File attribute doesn't have placeholder in admin
  • Loading branch information
slavvka authored Dec 7, 2016
2 parents ea0272d + 1cacbac commit 732d445
Show file tree
Hide file tree
Showing 55 changed files with 4,517 additions and 2,625 deletions.
6 changes: 2 additions & 4 deletions app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ public function getGalleryImages()
);
$image->setData(
'medium_image_url',
$this->_imageHelper->init($product, 'product_page_image_medium')
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
$this->_imageHelper->init($product, 'product_page_image_medium_no_frame')
->setImageFile($image->getFile())
->getUrl()
);
$image->setData(
'large_image_url',
$this->_imageHelper->init($product, 'product_page_image_large')
->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)
$this->_imageHelper->init($product, 'product_page_image_large_no_frame')
->setImageFile($image->getFile())
->getUrl()
);
Expand Down
14 changes: 5 additions & 9 deletions app/code/Magento/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ public function init($product, $imageId, $attributes = [])
protected function setImageProperties()
{
$this->_getModel()->setDestinationSubdir($this->getType());

$this->_getModel()->setWidth($this->getWidth());
$this->_getModel()->setHeight($this->getHeight());

Expand Down Expand Up @@ -241,25 +240,25 @@ protected function setWatermarkProperties()
{
$this->setWatermark(
$this->scopeConfig->getValue(
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_image",
"design/watermark/{$this->getType()}_image",
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkImageOpacity(
$this->scopeConfig->getValue(
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity",
"design/watermark/{$this->getType()}_imageOpacity",
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkPosition(
$this->scopeConfig->getValue(
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_position",
"design/watermark/{$this->getType()}_position",
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
$this->setWatermarkSize(
$this->scopeConfig->getValue(
"design/watermark/{$this->_getModel()->getDestinationSubdir()}_size",
"design/watermark/{$this->getType()}_size",
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
Expand Down Expand Up @@ -500,10 +499,7 @@ protected function initBaseFile()
protected function isScheduledActionsAllowed()
{
$model = $this->_getModel();
if ($model->isBaseFilePlaceholder()
&& $model->getNewFile() === true
|| $model->isCached()
) {
if ($model->isBaseFilePlaceholder() || $model->isCached()) {
return false;
}
return true;
Expand Down
34 changes: 32 additions & 2 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Magento\Eav\Model\Entity\Type;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Filesystem;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Form\Field;
Expand Down Expand Up @@ -126,6 +128,11 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
*/
private $arrayManager;

/**
* @var Filesystem
*/
private $fileInfo;

/**
* DataProvider constructor
*
Expand Down Expand Up @@ -483,8 +490,16 @@ private function convertValues($category, $categoryData)
if ($attribute->getBackend() instanceof ImageBackendModel) {
unset($categoryData[$attributeCode]);

$categoryData[$attributeCode][0]['name'] = $category->getData($attributeCode);
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
$fileName = $category->getData($attributeCode);
if ($this->getFileInfo()->isExist($fileName)) {
$stat = $this->getFileInfo()->getStat($fileName);
$mime = $this->getFileInfo()->getMimeType($fileName);

$categoryData[$attributeCode][0]['name'] = $fileName;
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
$categoryData['image'][0]['size'] = isset($stat) ? $stat['size'] : 0;
$categoryData['image'][0]['type'] = $mime;
}
}
}

Expand Down Expand Up @@ -605,4 +620,19 @@ private function getArrayManager()

return $this->arrayManager;
}

/**
* Get FileInfo instance
*
* @return FileInfo
*
* @deprecated
*/
private function getFileInfo()
{
if ($this->fileInfo === null) {
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);
}
return $this->fileInfo;
}
}
107 changes: 107 additions & 0 deletions app/code/Magento/Catalog/Model/Category/FileInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Category;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\File\Mime;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;

/**
* Class FileInfo
*
* Provides information about requested file
*/
class FileInfo
{
/**
* Path in /pub/media directory
*/
const ENTITY_MEDIA_PATH = '/catalog/category';

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var Mime
*/
private $mime;

/**
* @var WriteInterface
*/
private $mediaDirectory;

/**
* @param Filesystem $filesystem
* @param Mime $mime
*/
public function __construct(
Filesystem $filesystem,
Mime $mime
) {
$this->filesystem = $filesystem;
$this->mime = $mime;
}

/**
* Get WriteInterface instance
*
* @return WriteInterface
*/
private function getMediaDirectory()
{
if ($this->mediaDirectory === null) {
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
}
return $this->mediaDirectory;
}

/**
* Retrieve MIME type of requested file
*
* @param string $fileName
* @return string
*/
public function getMimeType($fileName)
{
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');
$absoluteFilePath = $this->getMediaDirectory()->getAbsolutePath($filePath);

$result = $this->mime->getMimeType($absoluteFilePath);
return $result;
}

/**
* Get file statistics data
*
* @param string $fileName
* @return array
*/
public function getStat($fileName)
{
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');

$result = $this->getMediaDirectory()->stat($filePath);
return $result;
}

/**
* Check if the file exists
*
* @param string $fileName
* @return bool
*/
public function isExist($fileName)
{
$filePath = self::ENTITY_MEDIA_PATH . '/' . ltrim($fileName, '/');

$result = $this->getMediaDirectory()->isExist($filePath);
return $result;
}
}
Loading

0 comments on commit 732d445

Please sign in to comment.