You are here:  » Search outdated products

Support Forum



Search outdated products

Submitted by javigdiaz on Tue, 2011-02-01 09:24 in

Hi David,

Because my merchants dont have products feed, I create manually the products feeds and then upload to the server.
I use to do it once per month, but in the meanwhile some products may be no longer exist in the merchants website.

Cause in the product database is the buy url, is there an script to check all the products database and attempts to connect to each product link? If the destination page does not exist, then delete (or deactivate) the product from the products database.

I think it should have different parameters because each merchant website may identify the no product exist with several ways ( a 404 error, a message showing "product not found", etc)

I remember I have read a post about a similar issue, but I've been unable to find it.

thanks in advance
javier

Submitted by support on Tue, 2011-02-01 09:50

Hello Javier,

It's a straight forward script to write, but I would always make sure the merchants are aware / happy with you running the process. Rather than actually have the script delete the products in the first instance (and accidentally wiping out all your products), what about having it display the URLs of any landing page containing "not found" (this should cover both 404 or more general messages) and then if it's looking OK then move on to make it actually delete the products? The following code will do the above, upload and run from your /admin/ folder:

removed.php

<?php
  
require("../includes/common.php");
  
$sql "SELECT buy_url FROM `".$config_databaseTablePrefix."products`";
  
database_querySelect($sql,$products);
  foreach(
$products as $product)
  {
    
$html file_get_contents($product["buy_url"]);
    if (!
$html)
    {
      die(
"Could not open ".$product["buy_url"]);
    }
    if (
strpos(strtolower($html),"not found")!==FALSE)
    {
      print 
"<p>".$product["buy_url"]."</p>";
    }
  }
?>

If the script aborts with the "Could not open..." message, this probably means that URL Wrappers are not enabled on your PHP installation. It is however becoming more common for CURL to be installed, which is an alternative method for accessing remote URLs. If this appears to be the case, in place of the following line:

    $html = file_get_contents($product["buy_url"]);

...instead use:

    $ch = curl_init($product["buy_url"]);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec($ch);
    curl_close($ch);

Cheers,
David.
--
PriceTapestry.com