You are here:  » Price and sale Price


Price and sale Price

Submitted by blogmaster2003 on Sun, 2013-05-12 13:09 in

Hi

some of my feeds have price and sale price

How can i display when the product has a sale price the price striked and show the sale price?

thx

Submitted by support on Mon, 2013-05-13 08:33

Hi,

The first step is to add the normal price as a new a field to your site. Note the "sense" here, because in feeds that have a "sale" price, you would want to register that as the Price field...

Do this by following the standard instructions for adding a custom field in this thread. I suggest using a field name of "normalprice".

However, rather than create the new field as VARCHAR(255), instead use DECIMAL(10,2) as per the existing `price` field, so your dbmod.php script would be as follows:

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

With that in place, edit includes/admin.php and look for where the existing `price` field is cleaned by the tapestry_decimalise() function around line 325:

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

...and REPLACE with:

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

With that all in place, and any feeds containing a sale and normal price re-registered, wherever a price is displayed you can check for a `normalprice` that is not zero and > `price` and display with strikethru as required. For example, in the price comparison table look for where the price column is displayed by the following code within line 13:

<strong><?php print $config_currencyHTML.$product["price"]; ?></strong>

...and REPLACE with something like:

<?php if (($product["normalprice"]!="0.00") && ($product["normalprice"]>$product["price"])): ?>
<span style='text-decoration: line-through;'><?php print $config_currencyHTML.$product["normalprice"]; ?></span>
<?php endif; ?>
<strong><?php print $config_currencyHTML.$product["price"]; ?></strong>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sydney880 on Wed, 2014-07-02 09:05

Hi,

I am having some problems doing this. When registered the feed, I put:
Price = sale price
Normal price = normal price

But then only half the products in the feed will be imported because only half of them have sale prices and I guess the others are not imported because the price field is required for products and can't be empty.

If I reverse it:
Price = normal price
Normal price = sale price

Then all the products will still show at the normal price instead of the sale price.

Submitted by support on Wed, 2014-07-02 09:33

Hi Sydney,

This can be handled by adding a check in the import record handler to use the normal price field if sale price is empty. To try this, in includes/admin.php look for the following code at line 327:

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

...and REPLACE with;

  $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
  $importRecord["normalprice"] = tapestry_decimalise($importRecord["normalprice"]);
  if ($importRecord["price"]=="0.00") $importRecord["price"] = $importRecord["normalprice"];

(so with this in place, continue to register the sale price as the price field - or in other words, whichever field a merchant uses as the current cheapest price - in some feeds you will find "rrp" for example which would then be registered as the normalprice field).

The logic sounds a bit awkward but I think it's the most straight forward way to handle any variation in price/saleprice where either or both may be populated.

Cheers,
David.
--
PriceTapestry.com

Submitted by sydney880 on Wed, 2014-07-02 12:57

Thanks for the reply. I updated my admin.php with your code, but when I re-register the datafeed, it still only imports half the products (those that have are not missing the sale price).

Do you know what may be wrong?

Submitted by support on Wed, 2014-07-02 13:29

Hi Sydney,

Please could you email me your current versions of config.advanced.php and includes/admin.php and I'll re-structure the way it works slightly which should make it more logical...

Thanks,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2014-09-25 10:20

Hi David,

Hope all is going well.

I have implemented the above on one of my sites and it works perfectly on the search results pages but not on product pages. I have tried a few variations of the code but nothing is displayed at all.

Would be grateful if you could confirm if the code above should work on a product page or if it needs to be modified in some way?

Thanks in advance.

Regards
Chris

Submitted by support on Thu, 2014-09-25 10:54

Hi Chris,

Above should work fine in search results and in the price comparison table (html/prices.php) where the product record in scope is $product. For the main product page body (html/product.php) replace each instance of $product with $mainproduct (13/03A and earlier) or $product_main (14/06A)...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by HJW on Wed, 2015-05-27 18:50

Hi David,

I'm trying to implement this using the following code;

includes/admin.php

/* decimalise price */
$importRecord["price"] = tapestry_decimalise($importRecord["price"]);
$importRecord["normalprice"] = tapestry_decimalise($importRecord["normalprice"]);
if ($importRecord["price"]=="0.00") $importRecord["price"] = $importRecord["normalprice"];

But any price field with 0.00 is not being imported. Only the products with prices in both 'normalprice' and 'price' are being imported.

Thanks
Hayden

Submitted by support on Thu, 2015-05-28 06:50

Hello Hayden,

It sounds like the initial value in $importRecord["price"] may evaluate to zero before being processed by tapestry_decimalise() in which case, it should just be case of moving the code to above slightly higher up in the process. In includes/admin.php look for the following comment at line 441:

    /* check product record for minimum required fields */

...and move the code in your post from where you made the modification to immediately _above_ that comment, and that should be all it is.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by HJW on Thu, 2015-05-28 15:01

Bravo Sir.

Many thanks,
Hayden.