1

I want to check if product belongs to particular category then that product should be stored in that newly created category named folder.

I tried this code:

$productCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category);
$cats = $productCollection->getCategoryIds(); 
foreach ($cats as $category_id) {
     $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($category_id);
     $catname = $_cat->getName();    
     if (count(array_intersect($catname == 'Camera',$productCats))) {
         $dispretionPath='/Camera';
     } else {               
         $dispretionPath='/images' ;         
     }
} 

--edit--

I tried this code but it is not creating folder

$product = Mage::getModel('catalog/product');

$cats = $product->getCategoryIds();
foreach ($product as $products) {
   if (array_search($category_id == 3,$products) === false ) {
    $dispretionPath='/Camera';
}else {             
            $dispretionPath='/images' ;      
        }
} 
return $dispretionPath;

Any solution?

2

You should not base your search on the category names since they can be changed or different on store views. Use the ids.
You can get the ids of the categories associated to a product like this:

$product->getCategoryIds()

Then check if your category id is in the result of the line above.

| improve this answer | |
  • its not working – Donika Aug 12 '15 at 7:02

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.