Let’s initiate a discussion!!
For any custom module we can add category drop down selection in system configuration.
Let’s start with creating a module names Magemonkeys_Categorydropdown
in adminhtml we can create file system.xml
Here is code for call category selection
1 2 3 4 5 6 7 |
<group id="categoryselection_setting" translate="label" type="text" default="1" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Setting</label> <field id="categorylist" translate="label" type="multiselect" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Please Select Category</label> <source_model>Magemonkeys\Categorydropdown\Model\Config\Source\Categorylist</source_model> </field> </group> |
and then we can create file Categorylist.php in Magemonkeys\Categorydropdown\Model\Config\Source
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 |
<?php namespace Magemonkeys\Categorydropdown\Model\Config\Source; use Magento\Framework\Option\ArrayInterface; class Categorylist implements ArrayInterface { protected $_categoryHelper; public function __construct(\Magento\Catalog\Helper\Category $catalogCategory) { $this->_categoryHelper = $catalogCategory; } public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true) { return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad); } public function toOptionArray() { $arr = $this->toArray(); $ret = []; foreach ($arr as $key => $value) { $ret[] = [ 'value' => $key, 'label' => $value ]; } return $ret; } public function toArray() { $categories = $this->getStoreCategories(true,false,true); $catagoryList = array(); foreach ($categories as $category){ $catagoryList[$category->getEntityId()] = __($category->getName()); } return $catagoryList; } } |
That’s it.
[crayon-641fade9c5647640367342/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.