├── ProgrammingAtKstark
└── CatewithimgWidget
│ ├── Block
│ └── Widget
│ │ └── CatewithimgWidget.php
│ ├── Model
│ └── Config
│ │ └── Source
│ │ └── Categorylist.php
│ ├── composer.json
│ ├── etc
│ ├── module.xml
│ └── widget.xml
│ ├── registration.php
│ └── view
│ └── frontend
│ ├── layout
│ └── default.xml
│ ├── templates
│ └── widget
│ │ └── categorywidget.phtml
│ └── web
│ └── css
│ └── widget.css
└── README.md
/ProgrammingAtKstark/CatewithimgWidget/Block/Widget/CatewithimgWidget.php:
--------------------------------------------------------------------------------
1 | _categoryHelper = $categoryHelper;
33 | $this->categoryFlatConfig = $categoryFlatState;
34 | $this->topMenu = $topMenu;
35 | $this->_categoryFactory = $categoryFactory;
36 | parent::__construct($context);
37 | }
38 | /**
39 | * Return categories helper
40 | */
41 | public function getCategoryHelper()
42 | {
43 | return $this->_categoryHelper;
44 | }
45 |
46 | public function getCategorymodel($id)
47 | {
48 | $_category = $this->_categoryFactory->create();
49 | $_category->load($id);
50 | return $_category;
51 | }
52 | /**
53 | * Retrieve current store categories
54 | *
55 | * @param bool|string $sorted
56 | * @param bool $asCollection
57 | * @param bool $toLoad
58 | * @return \Magento\Framework\Data\Tree\Node\Collection|\Magento\Catalog\Model\Resource\Category\Collection|array
59 | */
60 |
61 | /**
62 | * Retrieve collection of selected categories
63 | */
64 | public function getCategoryCollection()
65 | {
66 | $rootCat = $this->getData('parentcat');
67 |
68 |
69 | $category = $this->_categoryFactory->create();
70 | $collection = $category
71 | ->getCollection()
72 | ->addAttributeToSelect('image')
73 | ->addIdFilter($rootCat);
74 | return $collection;
75 | }
76 | /**
77 | * Retrieve tag line for widget
78 | */
79 | public function getTagLine()
80 | {
81 | $tagLine = $this->getData('tagline');
82 | return $tagLine;
83 | }
84 | /**
85 | * Retrieve main title for widget
86 | */
87 | public function getMainTitle()
88 | {
89 | $mainTitle = $this->getData('blocktitle');
90 | return $mainTitle;
91 | }
92 | }
--------------------------------------------------------------------------------
/ProgrammingAtKstark/CatewithimgWidget/Model/Config/Source/Categorylist.php:
--------------------------------------------------------------------------------
1 | _categoryHelper = $catalogCategory;
14 | }
15 |
16 | /*
17 | * Return categories helper
18 | */
19 |
20 | public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
21 | {
22 | return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
23 | }
24 |
25 | /*
26 | * Option getter
27 | * @return array
28 | */
29 | public function toOptionArray()
30 | {
31 |
32 |
33 | $arr = $this->toArray();
34 | $ret = [];
35 |
36 | foreach ($arr as $key => $value)
37 | {
38 |
39 | $ret[] = [
40 | 'value' => $key,
41 | 'label' => $value
42 | ];
43 | }
44 |
45 | return $ret;
46 | }
47 |
48 | /*
49 | * Get options in "key-value" format
50 | * @return array
51 | */
52 | public function toArray()
53 | {
54 |
55 | $categories = $this->getStoreCategories(true,false,true);
56 |
57 | $catagoryList = array();
58 | foreach ($categories as $category){
59 |
60 | $catagoryList[$category->getEntityId()] = __($category->getName());
61 | }
62 |
63 | return $catagoryList;
64 | }
65 |
66 | }
67 | ?>
--------------------------------------------------------------------------------
/ProgrammingAtKstark/CatewithimgWidget/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ProgrammingAtKstark/CatewithimgWidget",
3 | "description": "ProgrammingAtKstark Category List Widget with images",
4 | "require": {
5 | "php": "7.0.2|7.0.4|~7.0.6|~7.1.0"
6 | },
7 | "type": "magento2-module",
8 | "version": "1.0.0",
9 | "license": [
10 | "Commercial"
11 | ],
12 | "autoload": {
13 | "files": [ "registration.php" ],
14 | "psr-4": {
15 | "ProgrammingAtKstark\\CatewithimgWidget\\": ""
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ProgrammingAtKstark/CatewithimgWidget/etc/module.xml:
--------------------------------------------------------------------------------
1 |
2 |
24 |
25 | Magento2
26 | └── app
27 | └── code
28 | └── ProgrammingAtKstark
29 | └──CatewithimgWidget
30 | ├──Block
31 | ├──etc
32 | ├──Model
33 | ├──view
34 | ├──composer.json
35 | └──registration.php
36 |
37 |
38 |
39 |
40 |
41 | ###Enable this widget
42 | to Enable this widget simply follow these steps:
43 | php bin/magento setup:upgrade
php bin/magento cache:flush
bin/magento setup:di:compile
48 | view/frontend/web/css/widget.css