├── 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 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ProgrammingAtKstark/CatewithimgWidget/etc/widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Store Default 1st level Category List Widget 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Category must have image uploaded 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ProgrammingAtKstark/CatewithimgWidget/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ProgrammingAtKstark/CatewithimgWidget/view/frontend/templates/widget/categorywidget.phtml: -------------------------------------------------------------------------------- 1 | getCategoryCollection(); 3 | $categoryHelper = $this->getCategoryHelper(); 4 | ?> 5 |
6 |
7 |
8 |

getMainTitle(); ?>

9 |

getTagLine(); ?>

10 |
11 |
12 | getCategorymodel($category->getId()); 15 | $image = $cat->getImageUrl(); 16 | ?> 17 | 18 | 24 | 25 | 26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /ProgrammingAtKstark/CatewithimgWidget/view/frontend/web/css/widget.css: -------------------------------------------------------------------------------- 1 | .cwiw{ 2 | width: 100%; 3 | clear: both; 4 | float: none; 5 | text-align: center; 6 | } 7 | .cwiw .row{ 8 | margin-bottom: 20px; 9 | margin-right: -15px; 10 | margin-left: -15px; 11 | } 12 | .cwiw .row:before, 13 | .cwiw .row:after{ 14 | display: table; 15 | content: " "; 16 | } 17 | 18 | .cwiw .row .col-md-4{ 19 | width: 33.33333333%; 20 | float: left; 21 | } 22 | 23 | .cwiw a:hover{ 24 | text-decoration: none; 25 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Category with image widget for Magento 2 2 | 3 | ###Features 4 | 8 | 9 | ### How to use this widget 10 | Link : https://youtu.be/RLN1A200MII 11 | 12 | [![ScreenShot](https://i.ytimg.com/vi/RLN1A200MII/hqdefault.jpg)](http://youtu.be/RLN1A200MII) 13 | 14 | 15 | ###Mannual Installation Instructions 16 | Go to Magento2 Project 17 | root/app/code (create code folder if not exist) 18 | 19 | Paste downloaded/cloned folder. 20 | 21 | So folder strucuture will be as following 22 | 23 |
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 | 50 | 51 | ### Notes 52 | 55 | 56 | ### Contributing 57 | 64 | 65 | ### License 66 | 67 | By contributing your code, you agree to license your contribution under the MIT License. 68 | 69 | --------------------------------------------------------------------------------