1

I want to create you may also interested Section in product detail page. this section create most view product of current product of categories. means view.phtml file product of categories of most view product.

 $categories = $_product->getCategoryCollection()
                          ->addAttributeToSelect('name');
        foreach($categories as $category) {
            $catIds[] = $category->getID();

                }

print_r(catIds);

here i am get category 17,31. i can not undestand how to get this category most view product display here.

How to do it.

1

Here Is possible solution.I am not sure but it should work

// write code in view.phtml 
    $categoryId = $_product->getCategoryIds(); 
    $category = Mage::getModel('catalog/category')->load($categoryId);
    $products = Mage::getResourceModel('reports/product_collection')
        ->addOrderedQty() //total number of quantities ordered
        ->addAttributeToSelect('*') //get all attributes
        ->setOrder('ordered_qty', 'desc') //most ordered quantity products first
        ->addCategoryFilter($category);

        foreach($products as $_products )
        {
         //you code
        }
1
$storeId = Mage::app()->getStore()->getId();
$category_ids = $_product->getCategoryIds(); 

$products = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('category_ids',array('finset'=>$category_ids))
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

foreach($products as $product){
    echo $product->getName();
    echo $product->getPrice();
}
  • Hello how to get product detail like product name,price product detail can you please tell me? – coder Sep 11 '15 at 11:03
  • see my updated code – Pradeep Sanku Sep 11 '15 at 11:34
  • Thanks. Can You Please Same type Work for magento sort product check this question magento.stackexchange.com/questions/82604/… – coder Sep 11 '15 at 12:06
  • if you can help then please tell me – coder Sep 11 '15 at 12:06
  • Sorry i am checking data but it's not filter data using category. – coder Sep 11 '15 at 13:37
1
    $category_ids = $_product->getCategoryIds();   
     $products = Mage::getResourceModel('reports/product_collection')
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('entity_id', array('in' => $product_id))
            ->addViewsCount()
            ->joinField('category_id',
            'catalog/category_product',
            'category_id',
            'product_id=entity_id',
            null,
            'left'
        )
            //->addAttributeToFilter('category_ids',array('finset'=>$category_ids))
            //->addCategoryFilter($category)
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            //
            ->setPageSize(4)
            ->addAttributeToFilter('category_id', array('in' => $category_ids ));

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
foreach($products as $_products )
        {
         //you code
        }

**

main issue is that i have to remove or not display current product in this. then which filter use. if go to xyz product detail page then xyz is most view product it will display here. but i can not display this product in you may also interested Section. What I do Any Suggestion.

**

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.