You are here:  » Sort with shipping

Active Forum Topics


Sort with shipping

Submitted by sirmanu on Wed, 2019-07-03 06:53 in

Hi David. I hope summer is going great!

I am wondering how can I sort results based on price + shipping (products.php).

I have added a column for shipping, and it is usually well formatted, but it would be nice if before SUM we can check if it is a valid number.

Thanks

Submitted by support on Wed, 2019-07-03 10:16

Hi,

What I would suggest - in order to handle FREE for example, would be a new totalprice column. The following dbmod.php will add the new field with type DECIMAL(10,2)

<?php
  set_time_limit
(0);
  require(
"includes/common.php");
  
$config_databaseDebugMode TRUE;
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `totalprice` DECIMAL(10,2) NOT NULL"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

Then in includes/admin.php look for the following code at line 465:

    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);

...and REPLACE with:

    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
    $importRecord["totalprice"] = $importRecord["price"];
    $shipping = tapestry_decimalise($importRecord["shipping"]);
    if ($shipping != "0.00")
    {
      $importRecord["totalprice"] += $shipping;
    }

Finally, in search.php do a search and replace as follows;

Search:
MIN(price)

Replace:
MIN(totalprice)

(7 instances in each of the different query type SELECT statements)

Cheers,
David.
--
PriceTapestry.com