Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
CategoryWidget.php 2.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • Nicolas's avatar
    Nicolas committed
    <?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's avatar
    Nicolas committed
        }
    
        /**
         * Récupère le contenu du widget
         */
        public function getWidgetContent()
        {
    
            return $this->getData('widget_content');
    
    Nicolas's avatar
    Nicolas committed
        }
    
        /**
         * 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's avatar
    Nicolas committed
        {
    
    Nicolas's avatar
    Nicolas committed
        }
    }