You are here:  » Ads Product

Active Forum Topics


Ads Product

Submitted by Tobix on Sun, 2020-01-12 14:15 in

I created a niche comparator. How can I put a product before the list and highlighted on the search page?

Submitted by support on Mon, 2020-01-13 09:22

Hello Tobix,

Search results list is generated by html/searchresults.php so one thing you could do is to specify some products to be displayed based on certain search keywords and display them using the Featured Products code. To give this a go, add the following PHP section to the top of the file:

<?php
  
if ($page==1)
  {
    switch(
strtolower($q))
    {
      case 
"query 1":
        
$adProducts = array("Product 1","Product 2");
        break;
      case 
"query 2":
        
$adProducts = array("Product 3","Product 4");
        break;
    }
    if (isset(
$adProducts))
    {
      
$ins = array();
      foreach(
$adProducts as $adProduct)
      {
        
$ins[] = "'".database_safe($adProduct)."'";
      }
      
$in implode(",",$ins);
      
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";
      
database_querySelect($sql,$rows);
      
$featured["products"] = $rows;
      foreach(
$featured["products"] as $k => $product)
      {
        
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
        
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
      }
    }
    if (isset(
$featured)) require("html/featured.php");
  }
?>

Edit "query 1", "query 2" etc. to the search terms you want to match and edit the $adProducts results as required / add additional blocks - let me know of course if you are not sure of the syntax at any point.

Use lower case for the keywords to match; and if you wanted to promote products by category or brand you can use

category:category name:

or

brand:brand name:

...as the keywords to match.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Tobix on Mon, 2020-01-13 21:12

this code works perfectly.
Is it possible to see it in the list mode (like the other products) perhaps by adding an adv text?

Submitted by support on Tue, 2020-01-14 09:09

Hi Tobix,

Sure - they can be displayed using the search results HTML module - the same file the code is added to so need to take care that it doesn't run again and also need to save the existing $searchresults variable - try something like this;

<?php
  
if ($page==&& (!isset($featured)))
  {
    switch(
strtolower($q))
    {
      case 
"query 1":
        
$adProducts = array("Product 1","Product 2");
        break;
      case 
"query 2":
        
$adProducts = array("Product 3","Product 4");
        break;
    }
    if (isset(
$adProducts))
    {
      
$ins = array();
      foreach(
$adProducts as $adProduct)
      {
        
$ins[] = "'".database_safe($adProduct)."'";
      }
      
$in implode(",",$ins);
      
$sql "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name";
      
database_querySelect($sql,$rows);
      
$featured["products"] = $rows;
      foreach(
$featured["products"] as $k => $product)
      {
        
$featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
        
$featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
      }
    }
    if (isset(
$featured))
    {
      
$searchresults_save $searchresults;
      
$searchresults $featured;
      require(
"html/searchresults.php");
      
$searchresults $searchresults_save;
    }
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Tobix on Tue, 2020-01-14 19:47

Very Good!
how would you advise me to make the writing small or locked in a "sponsored" box? To make it clear that it is a featured product?

Submitted by support on Thu, 2020-01-16 09:28

A <fieldset> with optional <legend> would work nicely to demarcate the sponsored results - so in the above code where you have the call to searchresults.php:

      require("html/searchresults.php");

...have a go with something like;

      print "<div class='row'>";
      print "<div class='small-12 columns'>";
      print "<fieldset><legend>Sponsored Results</legend>";
      require("html/searchresults.php");
      print "</fieldset>";
      print "</div>";
      print "</div>";

Cheers,
David.
--
PriceTapestry.com