You are here:  » Selecting products to display


Selecting products to display

Submitted by JasonG on Thu, 2013-05-02 14:40 in

David

Is there any code where we would have the ability when you go into a category to select what product appears first

i.e. in this category {link saved} select certain products to show on maybe 2-3 pages?

Regards
Stuart

Submitted by support on Thu, 2013-05-02 15:14

Hi Stuart,

Manipulating the actual search results can tend to be inefficient, it is much better to define "promoted products" under certain conditions and display them as a separate instance of search results above the normal query based search results.

To try this, create the following new file as html/promoted.php:

<?php
  $promoted
["category1"] = array("Product 1","Product 2","Product 3");
  
$promoted["category2"] = array("Product 4","Product 5","Product 6");
  if (
     
$parts[0]=="category"
     
&&
     isset(
$promoted[$parts[1]])
     )
  {
    
$prmoted_SavedSearchResults $searchresults;
    
$ins = array();
    foreach(
$promoted[$parts[1]] as $productName)
    {
      
$ins[] = "'".database_safe($productName)."'";
    }
    
$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);
    
$searchresults["products"] = $rows;
    foreach(
$searchresults["products"] as $k => $product)
    {
      
$searchresults["products"][$k]["productHREF"] = tapestry_productHREF($product);
    }
    require(
"html/searchresults.php");
    
$searchresults $prmoted_SavedSearchResults;
  }
?>

Edit the $promoted array as required, replacing "category1", "category2" etc. and the product names exactly as required, and then to include, in your search.php look for the following code around line 362:

  require("html/searchresults.php");

...and REPLACE with:

  require("html/promoted.php");
  require("html/searchresults.php");

Should be close!

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Thu, 2013-05-02 16:33

Thank you wil give this a try

Similar question, probably related. Can we limit the nuber of products in a category, but still have them show in search results?

Cheers
Stuart

Submitted by support on Fri, 2013-05-03 09:06

Hi Stuart,

If you wanted to cap the number of search results pages for categories then you could do this as follows; in search.php, look for the following code around line 275:

  $resultCount = $rowsResultCount[0]["resultcount"];

...and REPLACE with:

  $resultCount = $rowsResultCount[0]["resultcount"];
  $resultCountCategoryMax = 1000;
  if (($parts[0]=="category") && ($resultCount > $resultCountCategoryMax))
  {
    $resultCount = $resultCountCategoryMax;
  }

...simply change the value of $resultCountCategoryMax as required!

This won't remove anything from the database of course, so products will still show up if they match a non-category based search.

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Fri, 2013-05-03 09:59

Hi David, The cap results works brilliant thank you

I have done the promoted.php and changed the code in search.php

Can't see anything displaying on the site, any ideas?

{link saved}

Cheers
Stuart

Submitted by JasonG on Fri, 2013-05-03 11:13

Not sure if you saw my last reply, have nearly got them displaying now but no pictures and they "promoted" don't link through to the product

{link saved}

Can promoted be added to the admin area, like "featured"

Thanks
Stuart

Submitted by support on Fri, 2013-05-03 11:15

Hi Stuart,

"*" was missing from the SELECT, that should be all it is - this line:

    $sql = "SELECT MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants

...should be:

    $sql = "SELECT *,MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants

(corrected above also)

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Fri, 2013-05-03 11:40

Brilliant thanks