You are here:  » Featured Product - Merchant Filter

Active Forum Topics


Featured Product - Merchant Filter

Submitted by ChrisNBC on Wed, 2018-10-10 11:08 in

Hi David,

Hope all is going well.

Quite a while back you helped me modify the featured products sections on my site. It’s been working well since but I would now like to add an additional ‘filter’ to the featured sections so that I can optionally filter by merchant. I wondered if you might be able to suggest what I would need to add to tfeaturedproducts.php to include merchant.

The current code is:

{code saved}

Thanks in advance.

Best regards

Chris

Submitted by support on Wed, 2018-10-10 11:51

Hi Chris,

Sure - in the code you posted, where you have the following code beginning at line 63:

    if ($featuredproducts_dbcategory)
    {
      $where .= " AND categoryid='".database_safe($featuredproducts_dbcategory)."'";
    }

...REPLACE with:

    if ($featuredproducts_dbcategory)
    {
      $where .= " AND categoryid='".database_safe($featuredproducts_dbcategory)."'";
    }
    if ($featuredproducts_dbmerchant)
    {
      $where .= " AND merchant='".database_safe($featuredproducts_dbmerchant)."'";
    }

And at (now) line 104:

  $featuredproducts_dbcategory = "";

...REPLACE with:

  $featuredproducts_dbcategory = "";
  $featuredproducts_dbmerchant = "";

And then in your calling code, set $featuredproducts_dbmerchant as required e.g.

  $featuredproducts_dbmerchant = "Merchant Name";

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2018-10-10 14:34

Hi David,

Thanks for the quick response. I made the modifications above but they do not appear to work. I disabled all the lines in the calling code except for the new one I added below:

$featuredproducts_dbmerchant = "spartoo";

The result seems to be a random group of products from all merchants. A random group also appears when I disable the above line.

Wondered if you might be able to suggest what could be going wrong and how I might resolve it.

Thanks in advance.

Best regards
Chris

Submitted by support on Thu, 2018-10-11 08:48

Hi Chris,

As the code stands, if $featuredproducts_category is not set you should be getting 8 random products based on the value of $featuredproducts_gender. If that too is empty you should be getting 8 random products that have no value in the gender field. If you wanted to add the same for a merchant, e.g. 8 random products for the specified merchant then where you currently have the following code beginning at line 4:

  if ($featuredproducts_category)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
  }

...REPLACE with:

  if ($featuredproducts_category)
  {
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` WHERE name LIKE '".$featuredproducts_category."/%' ORDER BY sequence";
  }
  elseif ($featuredproducts_dbmerchant)
  {
    $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($featuredproducts_dbmerchant)."' ORDER BY RAND() LIMIT 8";
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2018-10-11 11:17

Hi David,

Thanks for your message and the mod. I made the change (I assume the latest mod is in addition to the first one?) and set the code in index.php to:

print "NIKE";
$featuredproducts_dbmerchant = "Marks and Spencer";
//$featuredproducts_category = "NIKE";
//$featuredproducts_gender = "BOYS";
//$featuredproducts_dbcategory = "22";
require("featuredproducts.php");

What I had expected to see in the above instance is just 8 random products for that merchant but what I get is 8 random products from all merchants. I also tried:

print "NIKE";
$featuredproducts_dbmerchant = "Marks and Spencer";
//$featuredproducts_category = "NIKE";
$featuredproducts_gender = "BOYS";
//$featuredproducts_dbcategory = "22";
require("featuredproducts.php");

The results reflect the $featuredproducts_gender setting but still not the merchant?

I have taken the merchant name from the merchant column is the pt_products table..I assume this is correct? I also tried a different merchant but got the same result.

The featured settings seem to just ignore the new $featuredproducts_dbmerchant setting.

I wondered if you might have any suggestions why this might be happening.

Thanks in advance.

Best regards
Chris

Submitted by support on Thu, 2018-10-11 11:45

Hi Chris,

That's strange - could you post the full script again as you have it now, I can check it out in the context of the calling code you posted above...

Thanks,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2018-10-11 11:52

Thanks David, I've just e-mailed the file and also index.php.

Best regards
Chris