You are here:  » Updating Featured Products from a file

Support Forum



Updating Featured Products from a file

Submitted by Mik3 on Mon, 2010-11-01 21:32 in

I've managed to hack together a php script to scrape my merchants top selling products which I want to use as my featuredproducts.

Is there a way I can update the featured products from a file using php insteaf of having to login? This way I could automate the whole thing.

Thanks
Mike

Submitted by support on Tue, 2010-11-02 09:22

Hello Mike,

Sure! Let's say you create you file in your Price Tapestry installation directory called "featured.txt", with product names one per row.

In index.php, Featured Products are selected from the database by this code, beginning at line 32:

  $sql = "SELECT * FROM `".$config_databaseTablePrefix."featured` ORDER BY sequence";
  if (database_querySelect($sql,$rows))

...simply REPLACE those 2 lines with the following:

  $sequence = 1;
  $rows = array();
  $fp = fopen("featured.txt","r");
  while(!feof($fp))
  {
    $name = trim(fgets($fp));
    if ($name)
    {
      $rows[] = array("name"=>$name,"sequence"=>$sequence++);
    }
  }
  if (count($rows))

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Mik3 on Tue, 2010-11-02 20:31

Sorry David,

Should have said but I'm using featuredexternal.php so would it be possible to modify that or import the products directly? My lines look a bit different in featuredexternal.php

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

Thanks
Mike

Submitted by support on Wed, 2010-11-03 09:25

Hi Mike,

Almost the same; replace the exact section you posted with:

}
else
{
  $sequence = 1;
  $rows = array();
  $fp = fopen($common_path."featured.txt","r");
  while(!feof($fp))
  {
    $name = trim(fgets($fp));
    if ($name)
    {
      $rows[] = array("name"=>$name,"sequence"=>$sequence++);
    }
  }
  if (count($rows))
  {

The subtle difference is $common_path to make sure that the script can find the file whilst being called via the external scripts...

Cheers,
David.
--
PriceTapestry.com