2

I am editing "You may also be interested" section (Up-sells products section) in the Product Detail page. I need to remove the current product from "You may also interested" section.

Up-sells products section displays the current product of category product (which most viewed). But I have issue when I go to "You may also be interested" section on product detail page; the current product is also getting displayed on this. I just need to remove the current product from "You may also be interested" section.

Example: I have 4 products in Up-sells section:

Test1, Test2, Test3, Test4

I am getting this but when I go to Test1 product detail page, then I need to not display Test1 under "You may also be interested" section.

Here is the code I've used so far:

$products = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    //->addAttributeToFilter('entity_id', array('neq' => $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);
1

2 Answers 2

1

The methodaddIdFilter() of the product collection has a second parameter "exclude" that inverts the filter:

$collection->addIdFilter([$product->getId()], true);
1

I am Getting answer Without change Query of Magento.

foreach ($products as $_item) {

    $myid =  $_item->getId();

    if ($myid !=  $product_id) {
        <?php echo $_item->getProductUrl() ?>
    }
}

I found this solution here: most view product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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