You are here:  » OLD price NEW price


OLD price NEW price

Submitted by wesse249 on Wed, 2017-06-28 09:06 in

Hello David,

I added a new column Fromprice to my database. I'd like to show the price like this OLD PRICE / NEW PRICE when it is discounted. And i'd like to show only products when these are discounted. So normal priced products have to be disabled.

Is this possible?

Thanks Jan Roel

Submitted by support on Wed, 2017-06-28 10:06

Hello Jan,

Sure - the first thing I would suggest, is that if the `fromprice` field was added with the default custom field type of VARCHAR(255), I would change this to DECIMAL(10,2). The following dbmod.php will apply the change:

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

With that in place, next the `fromprice` field should be decimalised at import time (just like the main `price` field) and at the same time, the product can be dropped if the `fromprice` is the same as `price` (i.e. no discount). To do this, edit includes/admin.php and look for the following code at line 466:

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

...and REPLACE with:

    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
    $importRecord["fromprice"] = tapestry_decimalise($importRecord["fromprice"]);
    if ($importRecord["price"] == $importRecord["fromprice"]) return;

Then in the price comparison table, you could display `fromprice` striked out before the actual `price` - to do this, look for where the price is output in html/prices.php around line 59:

<td class='pt_pr_price'><?php print tapestry_price($product["price"]); ?></td>

...and use something like:

<td class='pt_pr_price'>
  <s><?php print tapestry_price($product["fromprice"]); ?></s>
  <?php print tapestry_price($product["price"]); ?>
</td>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Wed, 2017-06-28 11:09

Hello,

Thank you. Is it also possible when from and new price are the same the products also aren't showed? Because some feeds fill in the from price also with the regular price.

Thanks Jan Roel

Submitted by support on Wed, 2017-06-28 14:36

Hello Jan,

That should be the case with the above modification to includes/admin.php because of this line;

     if ($importRecord["price"] == $importRecord["fromprice"]) return;

...but that would only apply from the next full import / CRON. If you have run a full import since applying the changes and you still have products with same price / fromprice showing let me know and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Mon, 2017-07-03 08:54

Hello David,

On my productpage i also another price location. How can i also make here OLD PRICE / NEW PRICE

<p>
<strong><?php print $product_bestPriceText?>:</strong>
<?php print tapestry_price($product_main["price"]); ?> <?php print translate("from"); ?>
<?php print $product_bestPriceMerchants?>
</p>

And also on the category page and featured page?

<span class='pt_sr_price'><?php print tapestry_price($product["minPrice"]); ?></span>

Featured:

<span class='pt_fp_price'><?php print $config_currencyHTML.$product["minPrice"]; ?></span>

Some merchant have the from price filled in with 0.00 What is the way to remove these products? Using a global filter?

Thanks Jan Roel

Submitted by support on Mon, 2017-07-03 10:57

Hello Jan,

For the product page, use:

<p>
<strong><?php print $product_bestPriceText?>:</strong>
<?php print "<s>".tapestry_price($product_main["fromprice"])."</s> ".tapestry_price($product_main["price"]); ?> <?php print translate("from"); ?>
<?php print $product_bestPriceMerchants?>
</p>

Bear in mind that for Featured Products and regular search results, the results come from a summary query, so if you have compared products on this installation it would be necessary to re-query each result to get the `fromprice` for the merchant associated with minPrice. If that's not an issue for this installation, then for distributions prior to 16/10A first add the fromprice to the search results re-query by editing search.php and look for the following code at line 476:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,fromprice FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

And then in your HTML for Featured Products / Search Results, where you have:

<?php print $config_currencyHTML.$product["minPrice"]; ?>

...REPLACE with:

<?php print "<s>".$config_currencyHTML.$product["fromprice"]."</s> ".$config_currencyHTML.$product["minPrice"]; ?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Thu, 2017-12-14 10:15

Hello David,

Would it be possible when discounted products which aren't discounted anymore are placed on a seperared page which isn't searchable from the main site. Now these products will be removed. And these product get instead of price the text: discount over?

But the product needs to keep the same url. So i don't lose them in Google.

Jan Roel

Submitted by support on Thu, 2017-12-14 11:42

Hello Jan,

At the moment it looks like you're dropping prices that are not discounted with this code in includes/admin.php at line 468;

     if ($importRecord["price"] == $importRecord["fromprice"]) return;

...so for products to remain (and now import all products), comment out or delete that line.

Then to exclude all non-discounted products from search edit search.php and look for the following code at line 20:

  $priceWhere = "";

...and REPLACE with:

  $priceWhere = " AND price <> fromprice ";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Sat, 2017-12-30 11:37

Hello David,

With this code all products of the merchant are imported. Is it possible to import only the products with an old/new price to the website/database and when a product with an old/new price isn't discounted anymore on a later moment this product stays in the database only for the people who are finding this product through Google?

Thanks Jan Roel

Submitted by support on Sat, 2017-12-30 11:55

Hello Jan,

That is how the above should be working I think; this line added to search.php;

  $priceWhere = " AND price <> fromprice ";

...will mean that products that are not discounted will never show up in search results; but if the user finds the product page in Google, it will still work...

Apologies if mis-understood, let me know if you're not sure and I'll check it out further with you. If the site is online and you can link to an example (I'll remove before publishing your reply) I'll take a look...

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Sat, 2017-12-30 12:24

Hello David,

Yes that is correct. But when removing this line:

if ($importRecord["price"] == $importRecord["fromprice"]) return;

then all products are imported more then 600.000.

With this line there are 209.000 imported.

What i mean is that i only wan't to import discounted products = 209.000 and when one of these isn't discounted anymore this product is still available on the website but nog anymore in the searchresults.

I hope you understand what i mean.

Thanks Jan Roel

Submitted by support on Sat, 2017-12-30 13:26

Hello Jan,

That is how it should be working - please could you run an import with this line removed;

  if ($importRecord["price"] == $importRecord["fromprice"]) return;

...(so 600.000 imported) and then if you could email me a link to the installation and modified search.php attached I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Tue, 2018-01-02 11:43

Hello David,

How can i load the from price in related.php / searchresults.php

<?php
 
print tapestry_price($product["minPrice"]); 
?>

Submitted by support on Tue, 2018-01-02 12:25

Hello Jan,

Related Products selection already includes all fields so `fromprice` will be available. Since 16/10A so does the re-query in search.php however if you are running an earlier distribution, look for the following code at line 476:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,fromprice FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

In html/searchresults.php, using <s> (strikethru) tags works nicely with previous / non discounted prices - have a go with something like;

Was <s><?php print tapestry_price($product["fromprice"]); ?></s>

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Thu, 2019-05-23 09:01

Hello David,

A question: i can't get the from price activated at the related products section. Do you know how i can fix this?

Greetings Jan Roel

Submitted by support on Thu, 2019-05-23 09:25

Hello Jan,

The SELECT SQL for Related Products is in products.php at line 130:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name ORDER BY NULL";

...REPLACE with:

      $sql2 = "SELECT id,name,normalised_name,image_url,description,price,fromprice,rating,MIN(price) AS minPrice, COUNT(id) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE name IN (".$in.") GROUP BY name ORDER BY NULL";

Cheers,
David.
--
PriceTapestry.com