Version Notes
The First Release - added ability to show product image at product listing grid.
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | Lanot_GridImage |
| Version | 1.0.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0.0
- app/code/community/Lanot/GridImage/Block/Adminhtml/Grid/Renderer/Image.php +109 -0
- app/code/community/Lanot/GridImage/Helper/Data.php +47 -0
- app/code/community/Lanot/GridImage/Model/Handler.php +110 -0
- app/code/community/Lanot/GridImage/Model/Mysql4/Attribute.php +51 -0
- app/code/community/Lanot/GridImage/Model/Observer.php +138 -0
- app/code/community/Lanot/GridImage/etc/adminhtml.xml +26 -0
- app/code/community/Lanot/GridImage/etc/config.xml +75 -0
- app/code/community/Lanot/GridImage/etc/system.xml +71 -0
- app/etc/modules/Lanot_GridImage.xml +12 -0
- package.xml +18 -0
app/code/community/Lanot/GridImage/Block/Adminhtml/Grid/Renderer/Image.php
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Lanot
|
| 16 |
+
* @package Lanot_GridImage
|
| 17 |
+
* @copyright Copyright (c) 2012 Lanot
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Lanot_GridImage_Block_Adminhtml_Grid_Renderer_Image
|
| 22 |
+
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
|
| 23 |
+
{
|
| 24 |
+
/**
|
| 25 |
+
* @var bool
|
| 26 |
+
*/
|
| 27 |
+
protected $_canClick = false;
|
| 28 |
+
/**
|
| 29 |
+
* @var string
|
| 30 |
+
*/
|
| 31 |
+
protected $_imageClass = '';
|
| 32 |
+
/**
|
| 33 |
+
* @var null
|
| 34 |
+
*/
|
| 35 |
+
protected $_imageSizeWidth = null;
|
| 36 |
+
/**
|
| 37 |
+
* @var null
|
| 38 |
+
*/
|
| 39 |
+
protected $_imageSizeHeight = null;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
*
|
| 43 |
+
*/
|
| 44 |
+
public function _construct()
|
| 45 |
+
{
|
| 46 |
+
parent::_construct();
|
| 47 |
+
|
| 48 |
+
/** @var $helper Lanot_GridImage_Helper_Data */
|
| 49 |
+
$helper = Mage::helper('lanot_gridimage');
|
| 50 |
+
|
| 51 |
+
//define configuration
|
| 52 |
+
$this->_canClick = $helper->canClick();
|
| 53 |
+
$this->_imageClass = $helper->getImageClass();
|
| 54 |
+
$size = $helper->getImageSize();
|
| 55 |
+
|
| 56 |
+
if (isset($size[0]) && !empty($size[0])) {
|
| 57 |
+
$this->_imageSizeWidth = $size[0];
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (isset($size[1]) && !empty($size[1])) {
|
| 61 |
+
$this->_imageSizeHeight = $size[1];
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @param Varien_Object $row
|
| 67 |
+
* @return string
|
| 68 |
+
*/
|
| 69 |
+
public function render(Varien_Object $row)
|
| 70 |
+
{
|
| 71 |
+
$value = $row->getData($this->getColumn()->getIndex());
|
| 72 |
+
if (empty($value)) {
|
| 73 |
+
return '';
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
/** @var $imageHelper Mage_Catalog_Helper_Image */
|
| 77 |
+
$imageHelper = Mage::helper('catalog/image')->init($row, 'lanot_gridimage', $value);
|
| 78 |
+
|
| 79 |
+
$widthAndHeightTags = '';
|
| 80 |
+
if($this->_imageSizeWidth && $this->_imageSizeHeight) {
|
| 81 |
+
$imageHelper->resize($this->_imageSizeWidth, $this->_imageSizeHeight);
|
| 82 |
+
$widthAndHeightTags .= ' width="' . $this->_imageSizeWidth . '"';
|
| 83 |
+
$widthAndHeightTags .= ' heigth="' . $this->_imageSizeHeight . '"';
|
| 84 |
+
} else if ($this->_imageSizeWidth) {
|
| 85 |
+
$imageHelper->resize($this->_imageSizeWidth);
|
| 86 |
+
$widthAndHeightTags .= ' width="' . $this->_imageSizeWidth . '"';
|
| 87 |
+
} elseif ($this->_imageSizeHeight) {
|
| 88 |
+
$imageHelper->resize(null, $this->_imageSizeHeight);
|
| 89 |
+
$widthAndHeightTags .= ' heigth="' . $this->_imageSizeHeight . '"';
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
if ($this->_canClick) {
|
| 93 |
+
$href = Mage::getSingleton('catalog/product_media_config')->getMediaUrl($value);
|
| 94 |
+
return sprintf('<a href="%s" class="%s" target="_blank"><img src="%s" border="0" alt="" %s />',
|
| 95 |
+
$href,
|
| 96 |
+
$this->_imageClass,
|
| 97 |
+
$imageHelper,
|
| 98 |
+
$widthAndHeightTags
|
| 99 |
+
);
|
| 100 |
+
} else {
|
| 101 |
+
return sprintf('<img src="%s" class="%s" border="0" alt="" %s />',
|
| 102 |
+
$imageHelper,
|
| 103 |
+
$this->_imageClass,
|
| 104 |
+
$widthAndHeightTags
|
| 105 |
+
);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
}
|
app/code/community/Lanot/GridImage/Helper/Data.php
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Lanot
|
| 16 |
+
* @package Lanot_GridImage
|
| 17 |
+
* @copyright Copyright (c) 2012 Lanot
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Lanot_GridImage_Helper_Data extends Mage_Core_Helper_Abstract
|
| 22 |
+
{
|
| 23 |
+
/**
|
| 24 |
+
* @return bool
|
| 25 |
+
*/
|
| 26 |
+
public function canClick()
|
| 27 |
+
{
|
| 28 |
+
return (bool) Mage::getStoreConfig('lanot_gridimage/view/image_click', 0);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* @return bool
|
| 33 |
+
*/
|
| 34 |
+
public function getImageClass()
|
| 35 |
+
{
|
| 36 |
+
return (string) Mage::getStoreConfig('lanot_gridimage/view/image_class', '');
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* @return array
|
| 41 |
+
*/
|
| 42 |
+
public function getImageSize()
|
| 43 |
+
{
|
| 44 |
+
$size = Mage::getStoreConfig('lanot_gridimage/view/image_size', 0);
|
| 45 |
+
return @explode('x', strtolower($size));
|
| 46 |
+
}
|
| 47 |
+
}
|
app/code/community/Lanot/GridImage/Model/Handler.php
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Lanot
|
| 16 |
+
* @package Lanot_GridImage
|
| 17 |
+
* @copyright Copyright (c) 2012 Lanot
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Lanot_GridImage_Model_Handler
|
| 22 |
+
{
|
| 23 |
+
/**
|
| 24 |
+
*
|
| 25 |
+
*/
|
| 26 |
+
const ATTRIBUTE_CODE = 'image';
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* @param Mage_Adminhtml_Block_Widget_Grid $block
|
| 30 |
+
* @param array $extraColumnsData
|
| 31 |
+
* @return Lanot_GridImage_Model_Handler
|
| 32 |
+
*/
|
| 33 |
+
public function addColumnsToBlock(Mage_Adminhtml_Block_Widget_Grid $block, $extraColumnsData = array())
|
| 34 |
+
{
|
| 35 |
+
//#1. Add attribute to collection
|
| 36 |
+
$this->_addImagesToCollectionResult($block->getCollection());
|
| 37 |
+
|
| 38 |
+
//#2.Add new column
|
| 39 |
+
$this->_addImageColumn($block, $extraColumnsData);
|
| 40 |
+
|
| 41 |
+
//#3. Reorder columns
|
| 42 |
+
$block->sortColumnsByOrder();
|
| 43 |
+
|
| 44 |
+
return $this;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* @param Mage_Adminhtml_Block_Widget_Grid $grid
|
| 49 |
+
* @return Lanot_GridImage_Model_Observer
|
| 50 |
+
*/
|
| 51 |
+
protected function _addImageColumn($grid, $enabledData)
|
| 52 |
+
{
|
| 53 |
+
$size = Mage::helper('lanot_gridimage')->getImageSize();
|
| 54 |
+
$width = !empty($size[0]) ? ((int) $size[0] + 10) . 'px' : null;
|
| 55 |
+
|
| 56 |
+
$grid->addColumn('image', array(
|
| 57 |
+
'header' => Mage::helper('lanot_gridimage')->__('Image'),
|
| 58 |
+
'width' => $width,
|
| 59 |
+
'index' => 'image',
|
| 60 |
+
'sortable' => false,
|
| 61 |
+
'filter' => false,
|
| 62 |
+
'renderer' => 'lanot_gridimage/adminhtml_grid_renderer_image'
|
| 63 |
+
));
|
| 64 |
+
|
| 65 |
+
if (isset($enabledData['after'])) {
|
| 66 |
+
$grid->addColumnsOrder('image', $enabledData['after']);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
return $this;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* @return mixed
|
| 74 |
+
*/
|
| 75 |
+
protected function _getStoreId()
|
| 76 |
+
{
|
| 77 |
+
return Mage::app()->getRequest()->getParam('store', 0);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
|
| 82 |
+
* @return bool
|
| 83 |
+
*/
|
| 84 |
+
protected function _addImagesToCollectionResult(Mage_Catalog_Model_Resource_Product_Collection $collection)
|
| 85 |
+
{
|
| 86 |
+
$productIds = $collection->getColumnValues('entity_id');
|
| 87 |
+
if (empty($productIds)) {
|
| 88 |
+
return false;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
/** $var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
|
| 92 |
+
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', self::ATTRIBUTE_CODE);
|
| 93 |
+
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
|
| 94 |
+
if (!$attribute) {
|
| 95 |
+
return false;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/** @var $resourceModel Lanot_GridImage_Model_Mysql4_Attribute */
|
| 99 |
+
$resourceModel = Mage::getModel('lanot_gridimage/mysql4_attribute');
|
| 100 |
+
$productsImages = $resourceModel->getAttributeEntityValues($attribute, $productIds, $this->_getStoreId());
|
| 101 |
+
|
| 102 |
+
foreach ($collection as $product) {
|
| 103 |
+
if (isset($productsImages[$product->getId()])) {
|
| 104 |
+
$product->setData(self::ATTRIBUTE_CODE, $productsImages[$product->getId()]);
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return true;
|
| 109 |
+
}
|
| 110 |
+
}
|
app/code/community/Lanot/GridImage/Model/Mysql4/Attribute.php
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Banner Category item resource model
|
| 4 |
+
*
|
| 5 |
+
* @author Lanot
|
| 6 |
+
*/
|
| 7 |
+
class Lanot_GridImage_Model_Mysql4_Attribute
|
| 8 |
+
//extends Mage_Core_Model_Resource_Db_Abstract
|
| 9 |
+
extends Mage_Core_Model_Mysql4_Abstract
|
| 10 |
+
{
|
| 11 |
+
/**
|
| 12 |
+
* Initialize connection and define main table and primary key
|
| 13 |
+
*/
|
| 14 |
+
protected function _construct()
|
| 15 |
+
{
|
| 16 |
+
$this->_init('catalog/product', 'entity_id');
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
public function getAttributeEntityValues(Mage_Catalog_Model_Resource_Eav_Attribute $attribute, $entityIds, $storeId = 0)
|
| 20 |
+
{
|
| 21 |
+
$attributeValues = array();
|
| 22 |
+
if (!is_array($entityIds)) {
|
| 23 |
+
$entityIds = array();
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
if (empty($entityIds)) {
|
| 27 |
+
return $attributeValues;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
$attributeId = (int) $attribute->getAttributeId();
|
| 31 |
+
$storeId = (int) $storeId;
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
$read = $this->getReadConnection();
|
| 35 |
+
$select = $read->select()
|
| 36 |
+
->from(array('a' => $attribute->getBackendTable()), array('entity_id', 'value'))
|
| 37 |
+
->where('a.attribute_id = ' . $attributeId)
|
| 38 |
+
->where('a.`entity_id` IN (' . implode(',', $entityIds) .')')
|
| 39 |
+
->where('a.store_id IN (0, ?)', $storeId)
|
| 40 |
+
->where("a.value != 'no_selection'")
|
| 41 |
+
->order('a.store_id');
|
| 42 |
+
|
| 43 |
+
//update data
|
| 44 |
+
$rowSet = $read->fetchAll($select);
|
| 45 |
+
foreach ($rowSet as $row) {
|
| 46 |
+
$attributeValues[$row['entity_id']] = $row['value'];
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
return $attributeValues;
|
| 50 |
+
}
|
| 51 |
+
}
|
app/code/community/Lanot/GridImage/Model/Observer.php
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Lanot
|
| 16 |
+
* @package Lanot_GridImage
|
| 17 |
+
* @copyright Copyright (c) 2012 Lanot
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Lanot_GridImage_Model_Observer
|
| 22 |
+
{
|
| 23 |
+
/**
|
| 24 |
+
* @var null|array
|
| 25 |
+
*/
|
| 26 |
+
protected $_rulesEnabled = null;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* @var null|array
|
| 30 |
+
*/
|
| 31 |
+
protected $_rulesDisabled= null;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* @param Varien_Object $observer
|
| 35 |
+
*/
|
| 36 |
+
public function adminhtmlBlockHtmlBefore($observer)
|
| 37 |
+
{
|
| 38 |
+
if (!$this->_isViewEnabled()) {
|
| 39 |
+
return $this;
|
| 40 |
+
}
|
| 41 |
+
/** @var $block Mage_Adminhtml_Block_Widget_Grid */
|
| 42 |
+
$block = $observer->getEvent()->getBlock();
|
| 43 |
+
if (!$block) {
|
| 44 |
+
return $this;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
if (null === $this->_rulesEnabled) {
|
| 48 |
+
$this->_initRules();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
$enabledData = $this->_isEnabled($block);
|
| 52 |
+
if ((false === $enabledData) ||
|
| 53 |
+
$this->_isDisabled($block) ||
|
| 54 |
+
!$block->getCollection()->isLoaded() //fix for export - do not export images
|
| 55 |
+
) {
|
| 56 |
+
return $this;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
Mage::getModel('lanot_gridimage/handler')->addColumnsToBlock($block, $enabledData);
|
| 61 |
+
|
| 62 |
+
return $this;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @return bool
|
| 67 |
+
*/
|
| 68 |
+
protected function _isViewEnabled()
|
| 69 |
+
{
|
| 70 |
+
return (bool) Mage::getStoreConfig('lanot_gridimage/view/enabled', 0);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Init rules from configuration
|
| 75 |
+
*
|
| 76 |
+
* @return Lanot_GridImage_Model_Observer
|
| 77 |
+
*/
|
| 78 |
+
protected function _initRules()
|
| 79 |
+
{
|
| 80 |
+
$this->_rulesEnabled = array();
|
| 81 |
+
|
| 82 |
+
/** @var $ruleNode Mage_Core_Model_Config_Element */
|
| 83 |
+
if (Mage::getConfig()->getNode('default/lanot_gridimage/rules/enabled')) {
|
| 84 |
+
foreach(Mage::getConfig()->getNode('default/lanot_gridimage/rules/enabled')->children() as $ruleClass => $ruleNode) {
|
| 85 |
+
$ruleClass = trim($ruleClass);
|
| 86 |
+
$this->_rulesEnabled[$ruleClass] = array('after' => $ruleNode->getAttribute('after'));
|
| 87 |
+
}
|
| 88 |
+
} else {
|
| 89 |
+
$this->_rulesEnabled = array();
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
if (Mage::getConfig()->getNode('default/lanot_gridimage/rules/disabled')) {
|
| 93 |
+
foreach(Mage::getConfig()->getNode('default/lanot_gridimage/rules/disabled')->children() as $ruleClass => $ruleNode) {
|
| 94 |
+
$ruleClass = trim($ruleClass);
|
| 95 |
+
$this->_rulesDisabled[$ruleClass] = $ruleClass;
|
| 96 |
+
}
|
| 97 |
+
} else {
|
| 98 |
+
$this->_rulesDisabled = array();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
return $this;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* Check if is block mathed by rules
|
| 106 |
+
*
|
| 107 |
+
* @param Mage_Adminhtml_Block_Template $block
|
| 108 |
+
* @return bool|array
|
| 109 |
+
*/
|
| 110 |
+
protected function _isEnabled($block)
|
| 111 |
+
{
|
| 112 |
+
//just verify block instance of widget grid and instance of rules
|
| 113 |
+
foreach($this->_rulesEnabled as $ruleClass => $ruleData) {
|
| 114 |
+
//print get_class($block);
|
| 115 |
+
if (($block instanceof Mage_Adminhtml_Block_Widget_Grid) && ($block instanceof $ruleClass)) {
|
| 116 |
+
return $ruleData;
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
return false;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Check if is block mathed by rules
|
| 124 |
+
*
|
| 125 |
+
* @param Mage_Adminhtml_Block_Template $block
|
| 126 |
+
* @return bool
|
| 127 |
+
*/
|
| 128 |
+
protected function _isDisabled($block)
|
| 129 |
+
{
|
| 130 |
+
//just verify block instance of widget grid and instance of rules
|
| 131 |
+
foreach($this->_rulesDisabled as $ruleClass) {
|
| 132 |
+
if (($block instanceof Mage_Adminhtml_Block_Widget_Grid) && ($block instanceof $ruleClass)) {
|
| 133 |
+
return true;
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
return false;
|
| 137 |
+
}
|
| 138 |
+
}
|
app/code/community/Lanot/GridImage/etc/adminhtml.xml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
|
| 4 |
+
<acl>
|
| 5 |
+
<resources>
|
| 6 |
+
<admin>
|
| 7 |
+
<children>
|
| 8 |
+
|
| 9 |
+
<system>
|
| 10 |
+
<children>
|
| 11 |
+
<config>
|
| 12 |
+
<children>
|
| 13 |
+
<lanot_gridimage translate="title" module="lanot_gridimage">
|
| 14 |
+
<title>Lanot Grid Image Settings</title>
|
| 15 |
+
</lanot_gridimage>
|
| 16 |
+
</children>
|
| 17 |
+
</config>
|
| 18 |
+
</children>
|
| 19 |
+
</system>
|
| 20 |
+
|
| 21 |
+
</children>
|
| 22 |
+
</admin>
|
| 23 |
+
</resources>
|
| 24 |
+
</acl>
|
| 25 |
+
|
| 26 |
+
</config>
|
app/code/community/Lanot/GridImage/etc/config.xml
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
|
| 4 |
+
<modules>
|
| 5 |
+
<Lanot_GridImage>
|
| 6 |
+
<version>1.0.0.0</version>
|
| 7 |
+
</Lanot_GridImage>
|
| 8 |
+
</modules>
|
| 9 |
+
|
| 10 |
+
<global>
|
| 11 |
+
<helpers>
|
| 12 |
+
<lanot_gridimage>
|
| 13 |
+
<class>Lanot_GridImage_Helper</class>
|
| 14 |
+
</lanot_gridimage>
|
| 15 |
+
</helpers>
|
| 16 |
+
|
| 17 |
+
<blocks>
|
| 18 |
+
<lanot_gridimage>
|
| 19 |
+
<class>Lanot_GridImage_Block</class>
|
| 20 |
+
</lanot_gridimage>
|
| 21 |
+
</blocks>
|
| 22 |
+
|
| 23 |
+
<models>
|
| 24 |
+
<lanot_gridimage>
|
| 25 |
+
<class>Lanot_GridImage_Model</class>
|
| 26 |
+
<resourceModel>lanot_gridimage_resource</resourceModel>
|
| 27 |
+
</lanot_gridimage>
|
| 28 |
+
</models>
|
| 29 |
+
|
| 30 |
+
<lanot_gridimage_resource>
|
| 31 |
+
<class>Lanot_GridImage_Model_Mysql4</class>
|
| 32 |
+
</lanot_gridimage_resource>
|
| 33 |
+
|
| 34 |
+
<!-- OBSERVER EVENTS -->
|
| 35 |
+
<events>
|
| 36 |
+
<!-- ADMIN HTML BLOCK EVENTS -->
|
| 37 |
+
<adminhtml_block_html_before>
|
| 38 |
+
<observers>
|
| 39 |
+
<lanot_gridimage>
|
| 40 |
+
<type>singleton</type>
|
| 41 |
+
<class>lanot_gridimage/observer</class>
|
| 42 |
+
<method>adminhtmlBlockHtmlBefore</method>
|
| 43 |
+
</lanot_gridimage>
|
| 44 |
+
</observers>
|
| 45 |
+
</adminhtml_block_html_before>
|
| 46 |
+
<!--/ADMIN HTML BLOCK EVENTS -->
|
| 47 |
+
</events>
|
| 48 |
+
<!--/OBSERVER EVENTS -->
|
| 49 |
+
|
| 50 |
+
</global>
|
| 51 |
+
|
| 52 |
+
<default>
|
| 53 |
+
<lanot_gridimage>
|
| 54 |
+
<view>
|
| 55 |
+
<enabled>1</enabled>
|
| 56 |
+
<image_click>1</image_click>
|
| 57 |
+
<image_class>product_thumbnail</image_class>
|
| 58 |
+
<image_size>120x120</image_size>
|
| 59 |
+
</view>
|
| 60 |
+
|
| 61 |
+
<!-- rules for matching -->
|
| 62 |
+
<rules>
|
| 63 |
+
<enabled>
|
| 64 |
+
<Mage_Adminhtml_Block_Catalog_Product_Grid after="entity_id" />
|
| 65 |
+
</enabled>
|
| 66 |
+
|
| 67 |
+
<disabled>
|
| 68 |
+
<Mage_Adminhtml_Block_Review_Product_Grid />
|
| 69 |
+
<Mage_Adminhtml_Block_Urlrewrite_Product_Grid />
|
| 70 |
+
</disabled>
|
| 71 |
+
</rules>
|
| 72 |
+
<!-- /rules for matching -->
|
| 73 |
+
</lanot_gridimage>
|
| 74 |
+
</default>
|
| 75 |
+
</config>
|
app/code/community/Lanot/GridImage/etc/system.xml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<lanot translate="label">
|
| 5 |
+
<label>Lanot Extensions</label>
|
| 6 |
+
<sort_order>200</sort_order>
|
| 7 |
+
</lanot>
|
| 8 |
+
</tabs>
|
| 9 |
+
<sections>
|
| 10 |
+
<lanot_gridimage>
|
| 11 |
+
<class>separator-top</class>
|
| 12 |
+
<label>Grid Image</label>
|
| 13 |
+
<tab>lanot</tab>
|
| 14 |
+
<frontend_type>text</frontend_type>
|
| 15 |
+
<sort_order>800</sort_order>
|
| 16 |
+
<show_in_default>1</show_in_default>
|
| 17 |
+
<show_in_website>0</show_in_website>
|
| 18 |
+
<show_in_store>0</show_in_store>
|
| 19 |
+
<groups>
|
| 20 |
+
<view translate="label">
|
| 21 |
+
<label>Easy Grid Image Settings</label>
|
| 22 |
+
<frontend_type>text</frontend_type>
|
| 23 |
+
<sort_order>10</sort_order>
|
| 24 |
+
<show_in_default>1</show_in_default>
|
| 25 |
+
<show_in_website>0</show_in_website>
|
| 26 |
+
<show_in_store>0</show_in_store>
|
| 27 |
+
<fields>
|
| 28 |
+
<enabled translate="label">
|
| 29 |
+
<label>Enabled at Products Grid</label>
|
| 30 |
+
<frontend_type>select</frontend_type>
|
| 31 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 32 |
+
<sort_order>10</sort_order>
|
| 33 |
+
<show_in_default>1</show_in_default>
|
| 34 |
+
<show_in_website>0</show_in_website>
|
| 35 |
+
<show_in_store>0</show_in_store>
|
| 36 |
+
</enabled>
|
| 37 |
+
|
| 38 |
+
<image_click translate="label">
|
| 39 |
+
<label>Allow open image by on click</label>
|
| 40 |
+
<frontend_type>select</frontend_type>
|
| 41 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 42 |
+
<sort_order>20</sort_order>
|
| 43 |
+
<show_in_default>1</show_in_default>
|
| 44 |
+
<show_in_website>0</show_in_website>
|
| 45 |
+
<show_in_store>0</show_in_store>
|
| 46 |
+
</image_click>
|
| 47 |
+
|
| 48 |
+
<image_class translate="label">
|
| 49 |
+
<label>Image CSS class</label>
|
| 50 |
+
<frontend_type>text</frontend_type>
|
| 51 |
+
<sort_order>30</sort_order>
|
| 52 |
+
<show_in_default>1</show_in_default>
|
| 53 |
+
<show_in_website>0</show_in_website>
|
| 54 |
+
<show_in_store>0</show_in_store>
|
| 55 |
+
</image_class>
|
| 56 |
+
|
| 57 |
+
<image_size translate="label">
|
| 58 |
+
<label>Image size</label>
|
| 59 |
+
<comment>Size (Ex. 100x100) for Product Image</comment>
|
| 60 |
+
<frontend_type>text</frontend_type>
|
| 61 |
+
<sort_order>40</sort_order>
|
| 62 |
+
<show_in_default>1</show_in_default>
|
| 63 |
+
<show_in_website>0</show_in_website>
|
| 64 |
+
<show_in_store>0</show_in_store>
|
| 65 |
+
</image_size>
|
| 66 |
+
</fields>
|
| 67 |
+
</view>
|
| 68 |
+
</groups>
|
| 69 |
+
</lanot_gridimage>
|
| 70 |
+
</sections>
|
| 71 |
+
</config>
|
app/etc/modules/Lanot_GridImage.xml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Lanot_GridImage>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
<depends>
|
| 8 |
+
<Mage_Adminhtml />
|
| 9 |
+
</depends>
|
| 10 |
+
</Lanot_GridImage>
|
| 11 |
+
</modules>
|
| 12 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Lanot_GridImage</name>
|
| 4 |
+
<version>1.0.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>OSL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Extension allows admin to show product main image at product grid at admin page.</summary>
|
| 10 |
+
<description>Extension allows admin to show product main image at product grid at admin page.</description>
|
| 11 |
+
<notes>The First Release - added ability to show product image at product listing grid.</notes>
|
| 12 |
+
<authors><author><name>Lanot</name><user>auto-converted</user><email>lanot.biz@gmail.com</email></author></authors>
|
| 13 |
+
<date>2012-10-21</date>
|
| 14 |
+
<time>14:09:10</time>
|
| 15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Lanot_GridImage.xml" hash="4b81807f005ed89af286c4741a294c42"/></dir></target><target name="magecommunity"><dir name="Lanot"><dir name="GridImage"><dir name="Block"><dir name="Adminhtml"><dir name="Grid"><dir name="Renderer"><file name="Image.php" hash="7d6413134e6a8549582fb0c088479c98"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="8c633be70e107c166450d7a8d08023f6"/></dir><dir name="Model"><dir name="Mysql4"><file name="Attribute.php" hash="1270912696d2c598495c59605deefcbd"/></dir><file name="Handler.php" hash="93959c2ec955fb37906bbfae33c6baa6"/><file name="Observer.php" hash="4eed1c221091ce485cc7de34b5ab648b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d4c3ef81446e9ac37f3b4256ca66e63b"/><file name="config.xml" hash="489452c49c906d3221b4772f6f3a4086"/><file name="system.xml" hash="9673a12788657635225b9c791556f506"/></dir></dir></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies/>
|
| 18 |
+
</package>
|
