You are here:  » How to add price used?


How to add price used?

Submitted by sirmanu on Mon, 2019-03-18 17:39 in

Hi David.

Some of my feeds (maybe the 20%) have price used, besides price (new). I am considering create a new field to show this data.

I have added several fields before, like colour or size. But I don't know if I need to take into account additional steps because this is a numeric value.

Should it be decimal(10,2) with default 0.0 on MySQL?

Thank you

Submitted by support on Thu, 2019-03-21 11:42

Hi,

Yes - use DECIMAL(10,2) so the dbmod.php:

<?php
  
require("includes/common.php");
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."feeds`
            ADD `field_price_used` VARCHAR(255) NOT NULL default ''"
;
  
database_queryModify($sql,$result);
  
$sql "ALTER TABLE `".$config_databaseTablePrefix."products`
            ADD `price_used` DECIMAL(10,2) NOT NULL default '0.00'"
;
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

And you could also use the tapestry_decimalise() function just to make sure correct format; so if you edit includes/admin.php and look for the following code at line 465:

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

...and REPLACE with:

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

If not all products have a used price then you might want use a conditional where used throughout the html/ files, for example if you add a column to the price comparison table then instead of simply:

<?php
 
print $product["price_used"]; 
?>

...use something like:

<?php
 
print ($product["price_used"]!="0.00"?$product["price_used"]:""); 
?>

- that's PHP's handy "ternary", effectively a shorthand IF/THEN/ELSE:

(condition?then:else)

Cheers,
David.
--
PriceTapestry.com