You are here:  » Set New Content Fields


Set New Content Fields

Submitted by shaunmac on Thu, 2012-04-19 14:29 in

I am trying to find a way to add new fields to the content area so I can add different fields for the seed comparison site I started. I would need things like Quantity, Type, Climate, Yield, Height, Flowering period, Harvest, ect. I would like for it to appear with the product content on the comparison page. To give an example go to the link below and select grow info to see how I need it.
{link saved}

I have about 9 custom field I will be using but I do not use all of them all the time so I would need to show only the fields that have content.

Submitted by support on Thu, 2012-04-19 14:37

Hi Shaun,

No problem - having added new fields to your database (see http://www.pricetapestry.com/node/3094 ) you can access those fields within the Product / Main and Prices / Each templates (wp-admin > Settings > PriceTapestry.org ) using %DB_fieldname% e.g:

%DB_climate%

Cheers,
David.
--
PriceTapestry.com

Submitted by shaunmac on Thu, 2012-04-19 20:02

Ok is there a way I can have it list the spec only once instead of however many merchant there are? Since all the seeds being compared are the same. Also when I tried it but all it reads out is %DB_thc% I added the tables like in the link above. Exp. {link saved} any thoughts?

Submitted by support on Fri, 2012-04-20 07:52

Hi Shaun,

Sure - if you only use %DB_thc% once in the Product / Main template it will be displayed within the main content section rather than per product in the price comparison table. However, I do notice that it has been displayed literally on your site at the moment - that could mean that you're running an early beta version of the plugin in which case if you update to the latest version that should do the trick - if it's still appearing literally in the Product / Main area let me know and I'll check it out further...

Cheers,
David.
--
PriceTapestry.com

Submitted by shaunmac on Fri, 2012-04-20 14:16

I just install this about 2 weeks ago so I should have the latest version (version 1.0) of the plugin. I also deleted %DB_thc% in the prices/each and kept it in product/main and now it is not showing on the page at all even though I have data for. I'm kinda at a stand still with this not sure how to fix it.

Submitted by support on Fri, 2012-04-20 14:23

Hi Shaun,

I've just followed up by email...

Cheers,
David.
--
PriceTapestry.com

Submitted by lisbali12 on Mon, 2012-05-28 11:45

Hi David,

Along the same sort of lines, I'm trying to add a number of additional fields to my comparison tables. Following the instructions at http://www.pricetapestry.com/node/3094 and http://www.pricetapestry.com/node/3138 and then using your instructions at http://www.pricetapestry.org/node/28 for modifying the html, I have successfully added delivery price, delivery time and in-stock fields to the comparison tables and re-registered my feeds OK.

What I'm still trying to work out is how to get a total price field working. I used the instructions in the above links to make amendments to the includes/admin.php and html/prices.html files but am aware that this is for the standalone version and not the WP plugin. How would I manage to do this? Do I need to create a field and then use something like %DB_totalprice% in the settings options? Would the changes made above then be able to calculate this from the feeds? I'm too novice to know where to start!

Many thanks in advance.

Lisette

Submitted by support on Mon, 2012-05-28 11:56

Hi Lisette,

Very close - there would actually be 2 ways to do this; but to keep the changes entirely within the plugin; so corresponding to the instructions elsewhere, look for the following code in pto_product.php around line 134:

    $each = trim(preg_replace('/[ ]{2,}/',' ',$each));

...and REPLACE with:

    $each = str_replace("%CALC_totalprice%",pto_common_decimalise($product->price+$product->delivery),$each);
    $each = trim(preg_replace('/[ ]{2,}/',' ',$each));

The above assumes that you have used a field named "delivery" - simply replace in the above code as required; and then in your HTML > Product > Prices > Each template, use %CALC_totalprice%....

Cheers,
David.
--
PriceTapestry.com

Submitted by lisbali12 on Mon, 2012-05-28 12:31

Hi David,

Many thanks for your reply. I've just amended the code in pto_product.php and then in the HTML template as above, but it's not working yet - I'm just getting %CALC_totalprice% showing in the comparison table rather than a value. Could I be missing something?

Submitted by support on Mon, 2012-05-28 12:39

Hi,

Please could you email me your modified pto_product.php and copy in the email the contents of the current HTML > Prices > Each template and I'll check it all out...

Thanks,
David.
--
PriceTapestry.com

Submitted by allanch on Tue, 2013-10-29 08:42

Hi David, I'm currently learning to integrate PT to WP. I've followed the instructions set out above and all works fine for new fields such as stock and delivery cost. Can you tell me the best way of changing any displayed values ie for delivery cost when it is quoted by merchant as '0.00' or '0' change to 'free'? Thanks

Allan

Submitted by support on Tue, 2013-10-29 09:27

Hi Allan,

I assume you're pulling these values in using something like %DB_delivery% so the easiest way would be a simple search and replace in the code at the point where there DB_ placeholders are swapped out. In pto_product.php, for the case of Prices / Each, look for the following code at line 154:

  $each = str_replace("%DB_".$field."%",$product->$field,$each);

...and REPLACE with:

  $product->$field = preg_replace("(^0.00$|^0$)","Free",$product->$field);
  $each = str_replace("%DB_".$field."%",$product->$field,$each);

And for the case of Product / Main, look for the following code at line 495:

  $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);

...and REPLACE with:

  $product->$field = preg_replace("(^0.00$|^0$)","Free",$product->$field);
  $html_product = str_replace("%DB_".$field."%",$product->$field,$html_product);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by allanch on Tue, 2013-10-29 09:59

Thanks David, that's correct I'm using %DB_delivery_cost% and %DB_stock% in WP, can you also tell me how I change the display value of stock if they come up as '1' or any other similar value to a 'yes'?

Submitted by support on Tue, 2013-10-29 11:31

Hello Allan,

In this instance, it's probably best to add the new Search and Replace RegExp filter to your site, and then you'll be able to add a new Search and Replace RegExp filter to the Stock field, and in the Search box, something like:

(^1$|^In Stock$|^Available$)

...and replace with your preferred value e.g.

Yes

The same filter would also work in place of the previously described mod, searching on

(^0.00$|^0$)

...and replace with "Free".

Just to explain this regular expression format, the brackets enclose a pipe separated list of individual expressions, either one of which will trigger the match. The ^ and $ characters in each expression are the beginning and end of line anchors respectively, meaning that the text in between is considered an exact match only against the entire field.

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Tue, 2013-10-29 14:00

Hi David,

I'm trying to display my custom field info in the Search results as I've already done in the product pages. Thought it would just be a case of inserting Author: %DB_author% in to Search Results/Each template but I'm obviously missing something !!!

Any ideas?

Thanks

Adrian

Submitted by support on Tue, 2013-10-29 14:15

Hi Adrian,

As part of the performance improvements in the latest version the search results "re-query" only SELECTs the minimum required fields, however you can add additional fields easily - in pto_search.php look for the following code at line 357:

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

...and REPLACE with:

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

...and that will give you %DB_author% to use in Search Results / Each.

Cheers,
David.
--
PriceTapestry.com

Submitted by paddyman on Tue, 2013-10-29 14:26

Hi David,

Just had to change code below in pto_search.php

$pto_searchResults[$k]->rating = $rows3[$product->id]->rating;

to

$pto_searchResults[$k]->rating = $rows3[$product->id]->rating;

$pto_searchResults[$k]->author = $rows3[$product->id]->author;

Thanks again :)

Adrian

Submitted by allanch on Tue, 2013-10-29 18:38

Thanks David, that works perfectly!