How to get All Active Categories in Custom Module Admin Form Dropdown in Magento 2?Add category tree structure in custom module formHow to show bundle products on custom module admin grid in magento 2Magento 2: store selector for custom module in admin formmagento 2 : Display Uploaded image in admin form custom moduleMagento 2 : How to Create Product Attribute With All Active Categories DropDownMagento 2 : How to Show All Active Categories in Layered Navigation With Its Sub-categories?Created a custom module (custom admin-form)Magento2 Filters custom module dropdown in adminMagento 2 Get Shipping Rates of All active shipping methodshow to active/deactive a module for each store by admin in magento 2.2
Suggested order for Amazon Prime Doctor Who series
.NET executes a SQL query and Active Monitor shows multiple rows blocking each other
How do I set an alias to a terminal line?
How many people are necessary to maintain modern civilisation?
Parameterize chained calls to a utility program in Bash
Should I prioritize my 401k over my student loans?
Do I have any obligations to my PhD supervisor's requests after I have graduated?
What does "play with your toy’s toys" mean?
Why don't countries like Japan just print more money?
Greeting with "Ho"
When to remove insignificant variables?
What was the Shuttle Carrier Aircraft escape tunnel?
How does a pilot select the correct ILS when the airport has parallel runways?
How do I professionally let my manager know I'll quit over smoking in the office?
Can White Castle?
How dangerous are set-size assumptions?
What did River say when she woke from her proto-comatose state?
Relationship between woodwinds and brass in a marching band?
Is a single radon-daughter atom in air a solid?
Is it illegal to withhold someone's passport and green card in California?
Dates on degrees don’t make sense – will people care?
Old sci-fi story: radiation mutated the animals, a boy loses a limb, but it's okay because "humans used to do great with only two arms"
Impossible darts scores
Is "qch. est à mourir" considered an anglicism calqued from "sth is to die for"? How commonly is it used?
How to get All Active Categories in Custom Module Admin Form Dropdown in Magento 2?
Add category tree structure in custom module formHow to show bundle products on custom module admin grid in magento 2Magento 2: store selector for custom module in admin formmagento 2 : Display Uploaded image in admin form custom moduleMagento 2 : How to Create Product Attribute With All Active Categories DropDownMagento 2 : How to Show All Active Categories in Layered Navigation With Its Sub-categories?Created a custom module (custom admin-form)Magento2 Filters custom module dropdown in adminMagento 2 Get Shipping Rates of All active shipping methodshow to active/deactive a module for each store by admin in magento 2.2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am implementing a custom module in magento 2.In that module I want to show all active categories in admin form dropdown.How can I show them please help me on this.Thanks in Advance.
magento2 adminform drop-downs category-listing
add a comment |
I am implementing a custom module in magento 2.In that module I want to show all active categories in admin form dropdown.How can I show them please help me on this.Thanks in Advance.
magento2 adminform drop-downs category-listing
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49
add a comment |
I am implementing a custom module in magento 2.In that module I want to show all active categories in admin form dropdown.How can I show them please help me on this.Thanks in Advance.
magento2 adminform drop-downs category-listing
I am implementing a custom module in magento 2.In that module I want to show all active categories in admin form dropdown.How can I show them please help me on this.Thanks in Advance.
magento2 adminform drop-downs category-listing
magento2 adminform drop-downs category-listing
asked Jul 7 '17 at 6:39
shankar bossshankar boss
59431230
59431230
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49
add a comment |
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49
add a comment |
2 Answers
2
active
oldest
votes
In Block Put the code to get category collection
<?php
namespace SampleExampleBlock;
class Categorydata extends MagentoFrameworkViewElementTemplate
public function getCategories()
$categoryFactory = $_objectManager->create('MagentoCatalogModelResourceModelCategoryCollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')->addFieldToFilter('is_active', 1);
return $categories;
?>
Next You can call Block function in your Template file
<?php
$collection = $block->getCategories();
foreach ($collection as $categorycollection)
$categorycollection->getName();
?>
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
add a comment |
Any custom module get the collection and shown in the select form field
- First, add the below code in your block
protected $_categoryModal;
public function __construct(
MagentoCatalogModelCategory $categoryModal,
)
$this->_categoryModal = $categoryModal;
public function toOptionArray()
$productCategorys = $this->_categoryModal->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active', 1);
$productCategory = [];
foreach ($productCategorys as $category)
$productCategory[] = [ 'value' => $category->getId(), 'label' => $category->getName() ];
return $productCategory;
2.form field add into your _prepareForm method
$fieldset->addField(
'cat_id',
'select',
array(
'label' => $this->__("category"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'cat_id',
'values' => $this->toOptionArray()
)
);
Now please remove the generated and var folder using below command line
rm -rf generated var/
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f182506%2fhow-to-get-all-active-categories-in-custom-module-admin-form-dropdown-in-magento%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In Block Put the code to get category collection
<?php
namespace SampleExampleBlock;
class Categorydata extends MagentoFrameworkViewElementTemplate
public function getCategories()
$categoryFactory = $_objectManager->create('MagentoCatalogModelResourceModelCategoryCollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')->addFieldToFilter('is_active', 1);
return $categories;
?>
Next You can call Block function in your Template file
<?php
$collection = $block->getCategories();
foreach ($collection as $categorycollection)
$categorycollection->getName();
?>
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
add a comment |
In Block Put the code to get category collection
<?php
namespace SampleExampleBlock;
class Categorydata extends MagentoFrameworkViewElementTemplate
public function getCategories()
$categoryFactory = $_objectManager->create('MagentoCatalogModelResourceModelCategoryCollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')->addFieldToFilter('is_active', 1);
return $categories;
?>
Next You can call Block function in your Template file
<?php
$collection = $block->getCategories();
foreach ($collection as $categorycollection)
$categorycollection->getName();
?>
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
add a comment |
In Block Put the code to get category collection
<?php
namespace SampleExampleBlock;
class Categorydata extends MagentoFrameworkViewElementTemplate
public function getCategories()
$categoryFactory = $_objectManager->create('MagentoCatalogModelResourceModelCategoryCollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')->addFieldToFilter('is_active', 1);
return $categories;
?>
Next You can call Block function in your Template file
<?php
$collection = $block->getCategories();
foreach ($collection as $categorycollection)
$categorycollection->getName();
?>
In Block Put the code to get category collection
<?php
namespace SampleExampleBlock;
class Categorydata extends MagentoFrameworkViewElementTemplate
public function getCategories()
$categoryFactory = $_objectManager->create('MagentoCatalogModelResourceModelCategoryCollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')->addFieldToFilter('is_active', 1);
return $categories;
?>
Next You can call Block function in your Template file
<?php
$collection = $block->getCategories();
foreach ($collection as $categorycollection)
$categorycollection->getName();
?>
answered Jul 7 '17 at 7:10
Learing_CoderLearing_Coder
649317
649317
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
add a comment |
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
If i use ui component means how do i get category collcetion
– Jaisa
Mar 23 '18 at 5:31
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
Can you post the file location where you wann display so that i can help out.please post the code,how you have tried. @Sri
– Learing_Coder
Mar 23 '18 at 5:57
add a comment |
Any custom module get the collection and shown in the select form field
- First, add the below code in your block
protected $_categoryModal;
public function __construct(
MagentoCatalogModelCategory $categoryModal,
)
$this->_categoryModal = $categoryModal;
public function toOptionArray()
$productCategorys = $this->_categoryModal->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active', 1);
$productCategory = [];
foreach ($productCategorys as $category)
$productCategory[] = [ 'value' => $category->getId(), 'label' => $category->getName() ];
return $productCategory;
2.form field add into your _prepareForm method
$fieldset->addField(
'cat_id',
'select',
array(
'label' => $this->__("category"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'cat_id',
'values' => $this->toOptionArray()
)
);
Now please remove the generated and var folder using below command line
rm -rf generated var/
add a comment |
Any custom module get the collection and shown in the select form field
- First, add the below code in your block
protected $_categoryModal;
public function __construct(
MagentoCatalogModelCategory $categoryModal,
)
$this->_categoryModal = $categoryModal;
public function toOptionArray()
$productCategorys = $this->_categoryModal->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active', 1);
$productCategory = [];
foreach ($productCategorys as $category)
$productCategory[] = [ 'value' => $category->getId(), 'label' => $category->getName() ];
return $productCategory;
2.form field add into your _prepareForm method
$fieldset->addField(
'cat_id',
'select',
array(
'label' => $this->__("category"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'cat_id',
'values' => $this->toOptionArray()
)
);
Now please remove the generated and var folder using below command line
rm -rf generated var/
add a comment |
Any custom module get the collection and shown in the select form field
- First, add the below code in your block
protected $_categoryModal;
public function __construct(
MagentoCatalogModelCategory $categoryModal,
)
$this->_categoryModal = $categoryModal;
public function toOptionArray()
$productCategorys = $this->_categoryModal->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active', 1);
$productCategory = [];
foreach ($productCategorys as $category)
$productCategory[] = [ 'value' => $category->getId(), 'label' => $category->getName() ];
return $productCategory;
2.form field add into your _prepareForm method
$fieldset->addField(
'cat_id',
'select',
array(
'label' => $this->__("category"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'cat_id',
'values' => $this->toOptionArray()
)
);
Now please remove the generated and var folder using below command line
rm -rf generated var/
Any custom module get the collection and shown in the select form field
- First, add the below code in your block
protected $_categoryModal;
public function __construct(
MagentoCatalogModelCategory $categoryModal,
)
$this->_categoryModal = $categoryModal;
public function toOptionArray()
$productCategorys = $this->_categoryModal->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('is_active', 1);
$productCategory = [];
foreach ($productCategorys as $category)
$productCategory[] = [ 'value' => $category->getId(), 'label' => $category->getName() ];
return $productCategory;
2.form field add into your _prepareForm method
$fieldset->addField(
'cat_id',
'select',
array(
'label' => $this->__("category"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'cat_id',
'values' => $this->toOptionArray()
)
);
Now please remove the generated and var folder using below command line
rm -rf generated var/
answered Jun 13 at 18:54
Rasik MiyaniRasik Miyani
1329
1329
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f182506%2fhow-to-get-all-active-categories-in-custom-module-admin-form-dropdown-in-magento%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you using UI form?
– Prince Patel
Jul 7 '17 at 9:35
no, normal xml way only.
– shankar boss
Jul 7 '17 at 11:42
Can you share the code of admin form?
– Prince Patel
Jul 7 '17 at 11:49