Commit 84a0ff77 by wd

分类列表页添加商品图片列

parent afe1e2a1
<?php
namespace Joshine\Category\Block\Adminhtml\Category\Tab;
use Magento\Catalog\Block\Adminhtml\Category\Tab\Product as JoshineProduct;
class Product extends JoshineProduct
{
public function setCollection($collection){
echo 111;
$collection->addAttributeToSelect('thumbnail');
parent::setCollection($collection);
}
protected function _prepareColumns(){
parent::_prepareColumns();
$this->addColumnAfter('image', array(
'header' => __('image'),
'index' => 'thumbnail',
'renderer' =>'Joshine\Category\Block\Adminhtml\Helper\Form\Image'
), 'sku');
$this->sortColumnsByOrder();
return $this;
}
}
\ No newline at end of file
<?php
namespace Joshine\Category\Block\Adminhtml\Helper\Form;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Framework\DataObject;
class image extends AbstractRenderer
{
public function render(DataObject $row)
{
$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');
$imageUrl = $helperImport->init($row, 'thumbnail')
->setImageFile($row->getData('thumbnail')) // image,small_image,thumbnail
->resize(380)
->getUrl();
if (empty($row->getData('thumbnail')) ){
return "<span> No pictures </span>";
}
return "<img src=". $imageUrl ." width='100' >";
}
}
\ No newline at end of file
<?xml version="1.0"?> <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Block\Adminhtml\Category\Tab\Product" type="Joshine\Category\Block\Adminhtml\Category\Tab\Product" />
<type name="Joshine\Category\Controller\Adminhtml\Category\Image\Upload"> <type name="Joshine\Category\Controller\Adminhtml\Category\Image\Upload">
<arguments> <arguments>
<argument name="imageUploader" xsi:type="object">Magento\Catalog\CategoryImageUpload</argument> <argument name="imageUploader" xsi:type="object">Magento\Catalog\CategoryImageUpload</argument>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment