How to get Categories of products In Observer?Restrict products to purchase using Observer not triggerHow to stop process or flow of a event observerHow to call Observer method in controller in Magento?Magento 2 : Event Observer For Payment Method SelectionHow to get product category data from observerCall phtml File in ObserverHow to get the current category name in an observer in magento 1how to trigger observer by rest apiObserver for import productsMagento2: How can call observer function in controller file?Magento 2 - How to call sales_order_save_after Observer manually for testing?
Weird resistor with dots around it
How to gracefully leave a company you helped start?
Attacking the Hydra
What is the most difficult concept to grasp in Calculus 1?
How to prevent criminal gangs from making/buying guns?
Word for an event that will likely never happen again
How to not forget things?
Why aren’t there water shutoff valves for each room?
How would armour (and combat) change if the fighter didn't need to actually wear it?
Doesn't the speed of light limit imply the same electron can be annihilated twice?
Why not demand President's/candidate's financial records instead of tax returns?
What are the odds of rolling specific ability score totals in D&D?
Why won't the Republicans use a superdelegate system like the DNC in their nomination process?
Go to last file in vim
Cycle of actions and voice signals on a multipitch climb
Running code generated in realtime in JavaScript with eval()
Should I leave building the database for the end?
Human with super efficient metabolism
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
Do you "gain" 1st level?
Is Binary Integer Linear Programming solvable in polynomial time?
Finding the shaded region
Why did IBM make the PC BIOS source code public?
How would you translate this? バタコチーズライス
How to get Categories of products In Observer?
Restrict products to purchase using Observer not triggerHow to stop process or flow of a event observerHow to call Observer method in controller in Magento?Magento 2 : Event Observer For Payment Method SelectionHow to get product category data from observerCall phtml File in ObserverHow to get the current category name in an observer in magento 1how to trigger observer by rest apiObserver for import productsMagento2: How can call observer function in controller file?Magento 2 - How to call sales_order_save_after Observer manually for testing?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to add a condition for my category in the observer, how can I call category?
magento-1.9 event-observer
add a comment |
I need to add a condition for my category in the observer, how can I call category?
magento-1.9 event-observer
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23
add a comment |
I need to add a condition for my category in the observer, how can I call category?
magento-1.9 event-observer
I need to add a condition for my category in the observer, how can I call category?
magento-1.9 event-observer
magento-1.9 event-observer
asked Aug 3 at 4:59
zuszus
571 silver badge20 bronze badges
571 silver badge20 bronze badges
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23
add a comment |
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23
add a comment |
2 Answers
2
active
oldest
votes
You can try Something like this
$product = Mage::registry('current_product');
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
$categoryIds = $_product->getCategoryIds();
if($categoryIds[0]==4)
// Do something
else
return;
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
add a comment |
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0)
foreach($_categories as $_category)
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0)
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory)
echo $_subcategory->getName();
echo $_subcategory->getId();
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0)
echo $category->getName();
foreach($subcategories as $subcategory)
echo $subcategory->getName();
?>
for more please visit
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
|
show 1 more 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%2f284284%2fhow-to-get-categories-of-products-in-observer%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
You can try Something like this
$product = Mage::registry('current_product');
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
$categoryIds = $_product->getCategoryIds();
if($categoryIds[0]==4)
// Do something
else
return;
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
add a comment |
You can try Something like this
$product = Mage::registry('current_product');
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
$categoryIds = $_product->getCategoryIds();
if($categoryIds[0]==4)
// Do something
else
return;
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
add a comment |
You can try Something like this
$product = Mage::registry('current_product');
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
$categoryIds = $_product->getCategoryIds();
if($categoryIds[0]==4)
// Do something
else
return;
You can try Something like this
$product = Mage::registry('current_product');
$prodID = $product->getId();
$_product = Mage::getModel('catalog/product')->load($prodID);
$categoryIds = $_product->getCategoryIds();
if($categoryIds[0]==4)
// Do something
else
return;
edited Aug 3 at 5:11
answered Aug 3 at 5:08
Waqar AliWaqar Ali
61616 bronze badges
61616 bronze badges
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
add a comment |
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
I need to give condition for my specific category, like ID : 4, how can i call id 4 category in observer?
– zus
Aug 3 at 5:09
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
check my updaed answer
– Waqar Ali
Aug 3 at 5:11
add a comment |
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0)
foreach($_categories as $_category)
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0)
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory)
echo $_subcategory->getName();
echo $_subcategory->getId();
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0)
echo $category->getName();
foreach($subcategories as $subcategory)
echo $subcategory->getName();
?>
for more please visit
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
|
show 1 more comment
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0)
foreach($_categories as $_category)
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0)
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory)
echo $_subcategory->getName();
echo $_subcategory->getId();
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0)
echo $category->getName();
foreach($subcategories as $subcategory)
echo $subcategory->getName();
?>
for more please visit
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
|
show 1 more comment
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0)
foreach($_categories as $_category)
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0)
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory)
echo $_subcategory->getName();
echo $_subcategory->getId();
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0)
echo $category->getName();
foreach($subcategories as $subcategory)
echo $subcategory->getName();
?>
for more please visit
Get category and subcategory:
<?php
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0)
foreach($_categories as $_category)
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_subcategories = $_category->getChildrenCategories();
if (count($_subcategories) > 0)
echo $_category->getName();
echo $_category->getId();
foreach($_subcategories as $_subcategory)
echo $_subcategory->getName();
echo $_subcategory->getId();
?>
To get only one category: (put category Id as we want)
<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0)
echo $category->getName();
foreach($subcategories as $subcategory)
echo $subcategory->getName();
?>
for more please visit
answered Aug 3 at 5:19
Shafeel ShaShafeel Sha
47315 bronze badges
47315 bronze badges
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
|
show 1 more comment
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How can i use in the observer, my condition: if the selected category of products available in the cart no other products add to cart, and message like restricted products available in the cart you need to place a different order.
– zus
Aug 3 at 5:40
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
How to add more than one category id in Mage::getModel('catalog/category')->load(4); @Shafeel Sha
– zus
Aug 3 at 11:57
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
please use first method , you will get category collection
– Shafeel Sha
Aug 3 at 12:05
How can i assign my selected category id's
– zus
Aug 3 at 12:24
How can i assign my selected category id's
– zus
Aug 3 at 12:24
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
foreach($_categories as $_category) echo $_category->getId();
– Shafeel Sha
Aug 3 at 12:37
|
show 1 more 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%2f284284%2fhow-to-get-categories-of-products-in-observer%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
@ShafeelSha ver : 1.9.2.3
– zus
Aug 3 at 5:18
Please check updated answer
– Shafeel Sha
Aug 3 at 5:23