Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssignProducts.php
Go to the documentation of this file.
1 <?php
8 
10 {
16  protected $_template = 'Magento_Catalog::catalog/category/edit/assign_products.phtml';
17 
21  protected $blockGrid;
22 
26  protected $registry;
27 
31  protected $jsonEncoder;
32 
41  public function __construct(
42  \Magento\Backend\Block\Template\Context $context,
43  \Magento\Framework\Registry $registry,
44  \Magento\Framework\Json\EncoderInterface $jsonEncoder,
45  array $data = []
46  ) {
47  $this->registry = $registry;
48  $this->jsonEncoder = $jsonEncoder;
49  parent::__construct($context, $data);
50  }
51 
58  public function getBlockGrid()
59  {
60  if (null === $this->blockGrid) {
61  $this->blockGrid = $this->getLayout()->createBlock(
62  \Magento\Catalog\Block\Adminhtml\Category\Tab\Product::class,
63  'category.product.grid'
64  );
65  }
66  return $this->blockGrid;
67  }
68 
74  public function getGridHtml()
75  {
76  return $this->getBlockGrid()->toHtml();
77  }
78 
82  public function getProductsJson()
83  {
84  $products = $this->getCategory()->getProductsPosition();
85  if (!empty($products)) {
86  return $this->jsonEncoder->encode($products);
87  }
88  return '{}';
89  }
90 
96  public function getCategory()
97  {
98  return $this->registry->registry('category');
99  }
100 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Json\EncoderInterface $jsonEncoder, array $data=[])