You are here:  » ref the Price Table, If the price is the same, can I move a prefered merchant to the top

Support Forum



ref the Price Table, If the price is the same, can I move a prefered merchant to the top

Submitted by mally on Thu, 2008-05-15 16:48 in

ref the Price Table, If the price is the same, can I move a prefered merchant to the top? (some products are sold by a few merchants)

better commission from a praticular merchant, the prob is its name starts with a letter later than a other merchant with the same stock.

thanks

Mally

Submitted by support on Fri, 2008-05-16 08:30

Hi Mally,

Sure - here's a trick (one or 2 users have done the same thing)... In products.php, the SQL to select the products, ordered by price is as follows (line 12 in the distribution):

$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;

To "promote" a particular merchant, change this as follows:

$sql = "SELECT *,IF(merchant='Merchant Name',0,1) AS weighting FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price,weighting LIMIT ".$config_resultsPerPage;

...simply changing "Merchant Name" name in the above code the exact name of the merchant you wish to promote. Note how the weighting is zero based as MySQL's default sort order is INCREASING. The format of MySQL's IF construct is IF(condition,then,else)....

Cheers,
David.

Submitted by mally on Fri, 2008-05-16 11:27

Hello David

That part of my site has been modified before with the following code.

    if(count($config_overseas))
    {
      foreach($config_overseas as $k => $v)
      {
        $config_overseas[$k] = "merchant='".$v."'";
      }
      $if = implode(" OR ",$config_overseas);
      $sql = "SELECT *,IF(".$if.",9999,price) as price FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;
    }
    else
    {
      $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;
    }

Is there anyway to combine this with your new suggested code?

Submitted by support on Fri, 2008-05-16 13:55

Hi Mal,

Here's the mod merged into your already modified version....!

    if(count($config_overseas))
    {
      foreach($config_overseas as $k => $v)
      {
        $config_overseas[$k] = "merchant='".$v."'";
      }
      $if = implode(" OR ",$config_overseas);
      $sql = "SELECT *,IF(".$if.",9999,price) as price,IF(merchant='Merchant Name',0,1) AS weighting FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price,weighting LIMIT ".$config_resultsPerPage;
    }
    else
    {
      $sql = "SELECT *,IF(merchant='Merchant Name',0,1) AS weighting FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price,weighting LIMIT ".$config_resultsPerPage;
    }

Cheers,
David.