0

we have category called "shoes",
we gave discount for that category using promotions > catalog price rules

we have some 500 products in the category and now we are planning to delete the category and create an attribute and give discount for that attribute value.

using category using promotions > catalog price rules....

now we have to move all the products in that category to that attribute.

below @Marius gave solution, but i am missing somewhere

please help me to find my mistake....

2

First create the attribute and the values you need for it if it's a dropdown attribute. Then....

$categoryId = your category id here;
$category = Mage::getModel('catalog/category')->load($categoryId);
$ids = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($category)->getAllIds();
$attributeCode = 'your_attribute_code_here';
$attributeValue = 'the value of the attribute you want to set on all products';
Mage::getSingleton('catalog/product_action')->updateAttributes(
    $ids,
    array($attributeCode => $attributeValue),
    0
);
| improve this answer | |
  • i will try now..... – Baby in Magento Oct 9 '15 at 13:04
  • Was just about to put together this same method! Nice one. – performadigital Oct 9 '15 at 13:04
  • @Marius i copied this file to root of the site : pastebin.com/b2KbS4Mw clone.php, and i ran sitename.com/clone.php in browser, its giving blank page is there anything else i have to do, now i am running index management – Baby in Magento Oct 9 '15 at 13:19
  • 1
    check at least on product in the backend to see if it has the attribute set – Marius Oct 9 '15 at 13:28
  • yes, the attribute is in attribute set. – Baby in Magento Oct 9 '15 at 13:30
1

Create the new attribute, for example Clothing Type with an option of Shoes.

Then in Catalog->Manage Products select all the shoes and use the actions drop down to 'Update Attributes' and apply the attribute in bulk to those products.

You can't actually 'convert' a category into an attribute, but this method will add that attribute label to each of the products. After which you are free to delete the category if you wish.

| improve this answer | |
  • ya, but the problem is that we have some 5000 products in a store, we dont know which and all products we assigned for shoes until we check manually by selecting shoe category and checking the products. – Baby in Magento Oct 9 '15 at 12:50
  • Sorry but what you're asking is actually possible (change a category into an attribute), my answer above is a solution to what you're looking for despite this. There is no way to make a category suddenly become an attribute. Are you looking instead to apply the attribute in bulk to all products in the category? Your question is a little confusing is all. – performadigital Oct 9 '15 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.