You are here:  » Product Price


Product Price

Submitted by chrisst1 on Thu, 2012-02-23 14:31 in

Hi David

Is it possible to show the pre voucher price and the with voucher price on the products page. I have the site configured for $config_useVoucherCodes = 1;

Thanks

Chris

Submitted by support on Thu, 2012-02-23 15:00

Hi Chris,

Sure- just a little modification required. In products.php look for the following code at line 18:

      if ($config_useVoucherCodes === 1)

...and REPLACE with:

      foreach($rows as $k => $row)
      {
        $rows[$k]["normalprice"] = $row["price"];
      }
      if ($config_useVoucherCodes === 1)

With that in place, $product["normalprice"] will be available wherever there is product variable in context; e.g $mainProduct["normalprice"] in html/product.php or $product["normalprice"] in html/prices.php.

For example, if you wanted to show the normal price with a strikethrough where the discounted price is less, in html/prices.php look for where the price is displayed by this code within line 13:

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

...and REPLACE with:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Thu, 2012-02-23 16:42

Thanks David
That was great.

I've been reading through the forum looking for help on showing the correct merchant logo in the search results page but not found much. I am trying to get the lowest priced merchant logo to show if more than 1 merchant is selling the product. At the moment the result shows non lowest merchant.

Chris

Submitted by support on Thu, 2012-02-23 17:00

Hi Chris,

That's happening because the search results are generated by a summary query; which means that the product record from which the non-summary fields are returned is undefined (although it will be consistent until the next import). What's needed is a re-query at the top of html/searchresults.php to update the merchant field in in each row with the cheapest merchant. To do this, add the following code to the top of html/searchresults.php

<?php
  
foreach($searchresults["products"] as $k => $product)
  {
    
$sql "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."' ORDER BY price LIMIT 1";
    
database_querySelect($sql,$rows);
    
$searchresults["products"][$k]["merchant"] = $rows[0]["merchant"];
  }
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Thu, 2012-02-23 17:19

Brilliant, thanks.

Can that be extended so that the deep link to merchant site would work also.

<?php
   
if (file_exists("logos/".$product["merchant"])):
   print 
"<div class='search-result-logo'>";
   print 
"<a target='_blank' title='View this item on the ".$product["merchant"]." website' href='".tapestry_buyURL($product)."'>";
   print 
"<img alt='View this item on the ".$product["merchant"]." website' style='border: 0px' height='31' src='".$config_baseHREF."logos/".$product["merchant"]."'  width='88' />";
   print 
"</a>";
   print 
"</div>";
endif;
?>

Submitted by support on Fri, 2012-02-24 07:23

Hi Chris,

Sure, you can extend the re-query to include id and buy_url which are the only other fields required by tapestry_buyURL() - have a go with:

<?php
  
foreach($searchresults["products"] as $k => $product)
  {
    
$sql "SELECT merchant,id,buy_url FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($product["name"])."' ORDER BY price LIMIT 1";
    
database_querySelect($sql,$rows);
    
$searchresults["products"][$k]["merchant"] = $rows[0]["merchant"];
    
$searchresults["products"][$k]["id"] = $rows[0]["id"];
    
$searchresults["products"][$k]["buy_url"] = $rows[0]["buy_url"];
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Wed, 2016-08-31 20:25

Hi David - I'm looking to achieve a similar thing to Chris here, but this was originally posted back in 2012. Please could I check with you how to change your code to achieve a strike through of the old price, and then type the new price with voucher code?

Thanks for all your help here,
Jamie
>>>>>>>>>>>>>>>>>>>>>>>

Hi Chris,

Sure- just a little modification required. In products.php look for the following code at line 18:

<?php
 
if ($config_useVoucherCodes === 1)
?>

...and REPLACE with:

<?php
foreach($rows as $k => $row)
      {
        
$rows[$k]["normalprice"] = $row["price"];
      }
      if (
$config_useVoucherCodes === 1
?>

With that in place, $product["normalprice"] will be available wherever there is product variable in context; e.g $mainProduct["normalprice"] in html/product.php or $product["normalprice"] in html/prices.php.

For example, if you wanted to show the normal price with a strikethrough where the discounted price is less, in html/prices.php look for where the price is displayed by this code within line 13:

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

...and REPLACE with:

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

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by support on Thu, 2016-09-01 07:44

Hello Jamie,

For 15/09A, edit html/prices.php and look for the following code at line 59:

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

...and REPLACE with:

<td class='pt_pr_price'>
<?php  print (($product["normalprice"]!=$product["price"])?"<span style='style='text-decoration:line-through;'>".tapestry_price($product["normalprice"])."</span>&nbsp;":""); ?>
<?php print tapestry_price($product["price"]); ?>
</td>

(if you'd prefer a new line between the normalprice / price rather than a space, replace   with &lr;br /> in the above...)

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Fri, 2016-09-02 13:00

Hi David,

I cannot seem to get the new code to work.

Instead of showing the old strikenthrough un-discounted price, it now shows an empty price and then the new price. So for instance, it shows...

£ £28.99

...where £28.99 is the discounted price.

I've been playing around with the code and from what I can tell the issue is that $product["normalprice"] is not recognised, hence the blank price before the discounted price. Ive checked the database pt_products and there is not a field called "normalprice" so I figured that is a calculated field, but I cant seem to find it anywhere in the rest of the PT code. I also tried replacing "normalprice" with other fields but quickly made things worse, so reverted back.

Alas, my coding abilities need some work! Would you mind taking one more look please?

Thanks very much,
Jamie

Submitted by support on Fri, 2016-09-02 13:17

Hello Jamie,

`normalprice` isn't an "out of the box" field, it this case it is a custom field that would need to be added based on the standard instructions in this thread...

However, being intended to contain a decimal value, it would be best to create the field with a MySQL type of DECIMAL(10,2) rather than the suggested VARCHAR(255) for general purpose custom fields, 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 (and the required changes applied to $config_fieldSet in config.advanced.php) you will then be able to register a field from your feeds as the `normalprice` on Feed Registration Step 2.

This can become slightly tricker because there is no standard sense in which price / normalprice are provided. In some cases you may have an "RRP" (Recommended Retail Price) in feeds, which may or may not be populated if the "Price" field is the same. Similarly, you may come across feeds with a "Sale Price" field, which may only be populated if a product is on sale, and if a product is not on sale, may either contain nothing, or the same as the main price field... so it can get a little tricky!

As a starting point, if you apply the new field `normalprice` as per the above, and populate it by re-registering any feeds that have both price / RRP available, and then if you encounter any of the scenarios above let me know and I'll talk you through a "normalisation" process which is a small mod to the import process to look at the price / normalprice and set them appropriately for consistency at the front-end...

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Fri, 2016-09-02 14:16

Hi David,

So close! Ive actioned the changes you have outlined by mapping the new normalprice field to 'rrp_price' in the datasource - it works perfectly for most of the products, but unfortunately ~9500 products have a rrp_price of £0.00.

Would you mind outlining the normalisation process please?

Thank you very much for your help,
Jamie

Submitted by support on Fri, 2016-09-02 16:10

Hi Jamie,

Nearly there - following the previous replacement to html/prices.php you should now have this code beginning at line 59:

<td class='pt_pr_price'>
<?php  print (($product["normalprice"]!=$product["price"])?"<span style='style='text-decoration:line-through;'>".tapestry_price($product["normalprice"])."</span>&nbsp;":""); ?>
<?php print tapestry_price($product["price"]); ?>
</td>

The IF condition just needs to be extended to ignore "0.00" for `normalprice` have a go with:

<td class='pt_pr_price'>
<?php  print ((($product["normalprice"]!="0.00") && ($product["normalprice"]!=$product["price"]))?"<span style='style='text-decoration:line-through;'>".tapestry_price($product["normalprice"])."</span>&nbsp;":""); ?>
<?php print tapestry_price($product["price"]); ?>
</td>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by jamie on Tue, 2016-09-20 13:32

Hi David,

Apologies for bringing this up again, but I am unfortunately having issues with one merchant which doesnt match all others.

For all merchants I am mapping the RRP to "normalprice" and the actual price to "price"

Thus, when a discount is available, the "normalprice" is striken-through and then the reduced price is displayed next to it.

For this last merchant, they populate the datafeed differently - they will populate "normalprice" if there is a cheaper price, else leave it blank. "price" is always populated. Essentially, this merchant is populating the prices the 'other way around.' (Initially I was going to map this merchant's prices the other way around but this will not work because some of the prices will be blank)

I think to solve this would require code during the import time which says {if merchant = MerchantX then, normalprice=price unless price != 0}

Im struggling to know where to start writing code for this - would you mind taking a look please?

Thanks for all your help,
Jamie

Submitted by support on Tue, 2016-09-20 14:45

Hi Jamie,

This is probably best handled with a generic "catch all" so that if normalprice is empty then just set it to the same as price. 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"]);
    if (!$importRecord["normalprice"])
    {
      $importRecord["normalprice"] = $importRecord["price"];
    }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com