Magento – How to show certain “preferred” products first in search results

attributesfeatured-productmagento-1.9product

I have a Magento 1.9 shop containing ~22000 products. Products are added/updated/deleted every night.

There are certain products that are more attractive for us to sell because the margin is higher. We do not communicate to our customer that certain products are preferred. These products change on a weekly basis.

I have two questions:

  1. How do I internally mark a product as "preferred"?
  2. How do I make sure that a preferred product shows up first in the search results, while not showing the customer it's preferred?

Example:

Let's say I have two products that belong to the same category but have a different brand.

Product A - Category 1 - Brand X 
Product B - Category 1 - Brand Y (Preferred)

If someone searched for products in category 1 at this moment, it would not show a certain preferred product first.

I would like it to show Product B, the preferred product, first. Followed by the rest.

How do I accomplish this?

Best Answer

You cam move preferred product first by changing the search result internal sorting.

For this
1. Create a new attribute, type price, called "Preferred Rate"
2. Add to current attribute set and fill in values. For top product insert, say 99, for next 80 and so on.
4. Override the Mage_Catalog_Block_Product_List_Toolbar block to join this attribute if the current sort order is relevance.
5. Sort by rate DESC, relevance DESC
6. You can import/export this attribute or mass change it value via admin panel

Example code:

public function setCollection($collection)   
{
    parent::setCollection($collection);
    if ($this->getCurrentOrder() != 'relevance'){
        return $this;   
    }

    $collection->addAttributeToSort("rate", "desc"); 

    // move to the first position
    $select = $collection->getSelect(); 
    $orders = $select->getPart(Zend_Db_Select::ORDER);
    if (count($orders) > 1){
        $last = array_pop($orders);
        array_unshift($orders, $last);
        $select->setPart(Zend_Db_Select::ORDER, $orders); 
    }          

    return $this;
}

Customer will only see relevance, and there will be no changes for catalog or sort by price/name.

Also you can consider some search extension that gives priority to some attributes, like product name. So if the search matches the name of product A and description of product B the product A goes first.

Related Topic