You are here:  » Extending dB schema m- issue with monetary field

Active Forum Topics


Extending dB schema m- issue with monetary field

Submitted by ChrisNBC on Fri, 2013-08-30 10:20 in

Hi David,

Hope all is going well.

I wonder if you could help me with an issue I have when I extend the schema. I have added quite a number of fields to the products and feeds tables following the instructions in http://www.pricetapestry.com/node/3094. The majority of the fields work perfectly except for one which should contain a decimal GBP value. I have double checked the fields I created and they look fine (I copied the structure of the original 'price' field since the data will be similar and I want to leave the option of performing calculations on the field). The problem appears to be when loading the data. After the load I checked the dB and the field remains empty.

I have implemented the instructions in http://www.pricetapestry.com/node/3094 to decimalise the field but the problem remains.

In the feeds table the format is VARCHAR (255) and in the products table the format is DECIMAL (10,2).

I wondered if you could suggest what might be going wrong?

Thanks in advance.

Regards
Chris

Submitted by support on Fri, 2013-08-30 10:28

Hi Chris,

Could you post the code you added to includes/admin.php to set / decimalise the field - i'll take a look for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-08-30 10:58

Thanks David,

The code is taken from the post I mention above. This is what I have in my admin.php file:

/* decimalise price */
$importRecord["price"] = tapestry_decimalise($importRecord["price"]);
$importRecord["upfront_cost"] = tapestry_decimalise($importRecord["upfront_cost"]);

Thanks in advance.

Regards
Chris

Submitted by support on Fri, 2013-08-30 11:06

Hi Chris,

That looks fine - I assume every row is importing as 0.00, the first thing I would normally add in this instance is immediately _before_ the modification in includes/admin.php add this code:

  print_r($admin_importFeed);
  print_r($importRecord);
  exit();

Click import for a feed that should be populating the upfront_cost field and verify that in the output of $admin_importFeed you can see the field name that is mapped to it; and that in $importRecord the un-decimalised version of the value is present.

If that all looks fine, if you could email me your config.advanced.php and includes/admin.php I'll check it out for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Fri, 2013-08-30 11:48

Hi David,

I just added the code above and when I registered the feed, I could clearly see the field name mapped and also the un-decimalised value. However, since I could not get beyond registering the feed, I removed the code above and loaded the full data feed and it worked!...In removing the code above, I also deleted a blank line between the new decimalise code for 'upfront_cost' and the code to decimalise the 'price' field. I'm wondering if reformatting this code (deleting the line space and tabbing the new line so it aligned with the existing code) could have resolved the issue as I have not altered anything else since I posted the above.

Anyway, it seems to be working now so thank you once again for your help.

Regards
Chris

Submitted by support on Fri, 2013-08-30 12:15

Hi Chris,

Glad you're up and running!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-09-02 15:49

Hi David,

Hope you had a good weekend.

I wonder if you might be able to help me...I can't get three of the new dB fields to display in the prices.php tables. I have checked in the dB and it contains data for the fields. I originally thought the code I was using might have been wrong but I replaced the field names in the code with others which displayed fine. I wondered if you might have any suggestions of what else I should check or how I might resolve this problem?

Thanks in advance.

Regards
Chris

Submitted by support on Mon, 2013-09-02 15:56

Hi CHris,

At the top of your html/prices.php add this code:

<?php
  
print "<pre>";
  
print_r($prices["products"]);
  print 
"</pre>";
?>

This will generate output something like:

Array
(
    [0] => Array
        (
            [id] => 31745
            [merchant] => Currys
            [filename] => Currys.xml
            [name] => Avanquest Greeting Card Maker
            [description] => {code saved}
            [image_url] => {code saved}
            [buy_url] => {code saved}
            [price] => 9.99
            [category] => Cocette
            [brand] => Avanquest
            [custom_field_1] => "Custom Value 1"
            [custom_field_2] => "Custom Value 2"
            {code saved}

Within the price comparison table loop, each of the variable names in square brackets can be access through the $product array, but bear in mind that PHP variable and array key names are case sensitive. Based on the above output, to display Custom Value 1 you would use:

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

Easiest thing to do is normally to copy and paste from the print_r output into your code!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2013-09-02 16:28

Hi David,

Thanks for your quick response. I did as you suggested above...the field names were fine but I noticed the code I had was slightly different to what you quoted....I was using $mainProduct not $product as in your example.

I have changed it and it's all working perfectly now.

Thanks again for your great support, have a good evening.

Regards
Chris