Skip to content

Commit

Permalink
Merge pull request #95 from magento-dragons/product-video-PR4
Browse files Browse the repository at this point in the history
[EPAM] Product Video. Bugfixing. PR5
  • Loading branch information
Miniailo, Igor(iminiailo) committed Nov 3, 2015
2 parents 681bc1b + 569c9ff commit 0834cd7
Show file tree
Hide file tree
Showing 21 changed files with 556 additions and 486 deletions.
20 changes: 12 additions & 8 deletions app/code/Magento/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ public function setSize($size)
list($width, $height) = explode('x', strtolower($size), 2);
foreach (['width', 'height'] as $wh) {
${$wh}
= (int)${$wh};
= (int)${$wh};
if (empty(${$wh})) {
${$wh}
= null;
= null;
}
}

Expand All @@ -353,7 +353,8 @@ protected function _checkMemory($file = null)
{
return $this->_getMemoryLimit() > $this->_getMemoryUsage() + $this->_getNeedMemoryForFile(
$file
) || $this->_getMemoryLimit() == -1;
)
|| $this->_getMemoryLimit() == -1;
}

/**
Expand Down Expand Up @@ -939,14 +940,17 @@ protected function _fileExists($filename)
*/
public function getResizedImageInfo()
{
$fileInfo = null;
if ($this->_newFile === true) {
$fileInfo = getimagesize(
$this->_assetRepo->createAsset(
"Magento_Catalog::images/product/placeholder/{$this->getDestinationSubdir()}.jpg"
)->getSourceFile()
$asset = $this->_assetRepo->createAsset(
"Magento_Catalog::images/product/placeholder/{$this->getDestinationSubdir()}.jpg"
);
$img = $asset->getSourceFile();
$fileInfo = getimagesize($img);
} else {
$fileInfo = getimagesize($this->_mediaDirectory->getAbsolutePath($this->_newFile));
if ($this->_mediaDirectory->isFile($this->_mediaDirectory->getAbsolutePath($this->_newFile))) {
$fileInfo = getimagesize($this->_mediaDirectory->getAbsolutePath($this->_newFile));
}
}
return $fileInfo;
}
Expand Down
93 changes: 13 additions & 80 deletions app/code/Magento/ProductVideo/Helper/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

use Magento\Framework\App\Area;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\View\ConfigInterface;
use Magento\Framework\View\DesignInterface;

/**
* Helper to get attributes for video
Expand All @@ -21,81 +19,37 @@ class Media extends \Magento\Framework\App\Helper\AbstractHelper
*/
const MODULE_NAME = 'Magento_ProductVideo';

/**
* Video play attribute
*/
const NODE_CONFIG_PLAY_IF_BASE = 'play_if_base';

/**
* Video stop attribute
*/
const NODE_CONFIG_SHOW_RELATED = 'show_related';

/**
* Video color attribute
*/
const NODE_CONFIG_VIDEO_AUTO_RESTART = 'video_auto_restart';

/**
* Media config node
*/
const MEDIA_TYPE_CONFIG_NODE = 'videos';

/**
* Configuration path
*/
const XML_PATH_YOUTUBE_API_KEY = 'catalog/product_video/youtube_api_key';

/**
* @var ConfigInterface
* Configuration path for video play
*/
protected $viewConfig;
const XML_PATH_PLAY_IF_BASE = 'catalog/product_video/play_if_base';

/**
* Theme
*
* @var DesignInterface
* Configuration path for show related
*/
const XML_PATH_SHOW_RELATED = 'catalog/product_video/show_related';
/**
* Configuration path for video auto restart
*/
protected $currentTheme;
const XML_PATH_VIDEO_AUTO_RESTART = 'catalog/product_video/video_auto_restart';

/**
* Cached video config
* Media config node
*/
protected $cachedVideoConfig;
const MEDIA_TYPE_CONFIG_NODE = 'videos';

/**
* @param ConfigInterface $configInterface
* @param DesignInterface $designInterface
* @param Context $context
*/
public function __construct(
ConfigInterface $configInterface,
DesignInterface $designInterface,
Context $context
) {
parent::__construct($context);
$this->viewConfig = $configInterface;
$this->currentTheme = $designInterface->getDesignTheme();
$this->initConfig();
}

/**
* Cached video config
*
* @return $this
*/
protected function initConfig()
{
if ($this->cachedVideoConfig === null) {
$this->cachedVideoConfig = $this->viewConfig->getViewConfig(
[
'area' => Area::AREA_FRONTEND,
'themeModel' => $this->currentTheme
]
);
}

return $this;
}

/**
Expand All @@ -105,14 +59,7 @@ protected function initConfig()
*/
public function getPlayIfBaseAttribute()
{
$videoAttributes = $this->cachedVideoConfig->getMediaAttributes(
self::MODULE_NAME,
self::MEDIA_TYPE_CONFIG_NODE,
self::NODE_CONFIG_PLAY_IF_BASE
);
if (isset($videoAttributes[self::NODE_CONFIG_PLAY_IF_BASE])) {
return $videoAttributes[self::NODE_CONFIG_PLAY_IF_BASE];
}
return $this->scopeConfig->getValue(self::XML_PATH_PLAY_IF_BASE);
}

/**
Expand All @@ -122,14 +69,7 @@ public function getPlayIfBaseAttribute()
*/
public function getShowRelatedAttribute()
{
$videoAttributes = $this->cachedVideoConfig->getMediaAttributes(
self::MODULE_NAME,
self::MEDIA_TYPE_CONFIG_NODE,
self::NODE_CONFIG_SHOW_RELATED
);
if (isset($videoAttributes[self::NODE_CONFIG_SHOW_RELATED])) {
return $videoAttributes[self::NODE_CONFIG_SHOW_RELATED];
}
return $this->scopeConfig->getValue(self::XML_PATH_SHOW_RELATED);
}

/**
Expand All @@ -139,14 +79,7 @@ public function getShowRelatedAttribute()
*/
public function getVideoAutoRestartAttribute()
{
$videoAttributes = $this->cachedVideoConfig->getMediaAttributes(
self::MODULE_NAME,
self::MEDIA_TYPE_CONFIG_NODE,
self::NODE_CONFIG_VIDEO_AUTO_RESTART
);
if (isset($videoAttributes[self::NODE_CONFIG_VIDEO_AUTO_RESTART])) {
return $videoAttributes[self::NODE_CONFIG_VIDEO_AUTO_RESTART];
}
return $this->scopeConfig->getValue(self::XML_PATH_VIDEO_AUTO_RESTART);
}

/**
Expand Down
Loading

0 comments on commit 0834cd7

Please sign in to comment.