Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace NicolasBejean\CategoryWidget\Block\Widget;
class CategoryWidget extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{
/**
* Default value for products count that will be shown
*/
protected $_categoryHelper;
protected $categoryFlatConfig;
protected $topMenu;
protected $_categoryFactory;
protected $widgetTitle;
protected $widgetContent;
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Catalog\Helper\Category $categoryHelper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Helper\Category $categoryHelper,
\Magento\Catalog\Model\Indexer\Category\Flat\State $categoryFlatState,
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
\Magento\Theme\Block\Html\Topmenu $topMenu
) {
$this->_categoryHelper = $categoryHelper;
$this->categoryFlatConfig = $categoryFlatState;
$this->topMenu = $topMenu;
$this->_categoryFactory = $categoryFactory;
parent::__construct($context);
}
/**
* Return categories helper
*/
public function getCategoryHelper()
{
return $this->_categoryHelper;
}
public function getCategoryModel($id)
{
$_category = $this->_categoryFactory->create();
$_category->load($id);
return $_category;
}
/**
* Retrieve current store categories
*
* @param bool|string $sorted
* @param bool $asCollection
* @param bool $toLoad
* @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Category\Collection|array
*/
/**
* Récupère le titre du widget
*/
public function getWidgetTitle()
{

Nicolas
committed
return $this->getData('widget_title');
}
/**
* Récupère le contenu du widget
*/
public function getWidgetContent()
{

Nicolas
committed
return $this->getData('widget_content');
}
/**
* Récupère la sélection de catégories
*/
public function getCategorySelection()
{
$rootCat = $this->getData('category_selection');
$category = $this->_categoryFactory->create();
$collection = $category
->getCollection()
->addAttributeToSelect('image')
->addIdFilter($rootCat);
return $collection;
}
/**
* Récupère le template du widget
*/

Nicolas
committed
public function getTemplate()

Nicolas
committed
return $this->getData('template');