简体   繁体   中英

How to sort products into categories Magento

I have toons of products in a magento store thats need to be sorted into new categories based on diffrent attributes any one knows how to do this with a script.

example:

if the product attribute "COLOR" has a value of Blue the product should be in cat 10 and so on

Once you iterate over your products you can use the setCategoryIds method (this code is meant to be used for a dropdown attribute as it uses the getAttributeTextMethod):

$product->load($productId);
if( strcmp($product->getAttributeText('COLOR') , 'Blue') == 0 ){
    $product->setCategoryIds(array('cat1Id' ,'cat2Id'));
}
$product->save();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM