You are here:  » Product Mapping - Price & Old_Price field


Product Mapping - Price & Old_Price field

Submitted by nanaz on Fri, 2020-01-17 15:56 in

Hi David,

Hope you're well!

For a very small niche site I would like to be able to change 'Price' and the custom field 'Old_Price' for a specific article. Is this possible? I can't get it to work by adding the fields to productsmap_configure.php.

Hope you can help!

Cheers, Marlies

Submitted by support on Sat, 2020-01-18 10:38

Hello Marlies,

You could use the Product Mapping meta data feature with a small mod to do this. First, add the following new lines to config.advanced.php:

  $config_productMeta["price"] = "Price";
  $config_productMeta["old_price"] = "Old Price";

Next, edit includes/admin.php and look for the following code at line 304:

      if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];

...and REPLACE with:

      if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];
      if (isset($admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["price"])) $importRecord["price"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["price"];
      if (isset($admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["old_price"])) $importRecord["old_price"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["old_price"]

...and finally the following code at line 647:

        $admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");

...and REPLACE with:

        $admin_importProductMappingsOverrides[$productsmap["name"]]["image_url"] = (($productsmap["image_url"])?$productsmap["image_url"]:"");
        $admin_importProductMappingsOverrides[$productsmap["name"]]["meta"] = (($productsmap["meta"])?unserialize($productsmap["meta"]):array());

Now on the configuration page for a product mapping entry you'll see boxes to enter an override Price and Old Price for that product (applied at import time)...

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Mon, 2020-01-20 16:14

Hi David,

I've added the mod to admin.php and the Product Mapping form now shows both Custom Price and Custom Old Price fields. I can add a value to both and it will be saved. However, after importing the feed the changed values don't show.

When I look in the database the values I added to a certain product in productmapping only appear in the column 'meta' as a text like this:

a:2:{s:5:"price";s:2:"30";s:9:"old_price";s:2:"42";}

Columns price and old_price are empty.

I have to add I also use the mod from https://www.pricetapestry.com/node/5568 to calculate the discount percentage from price/old_price on the fly.

Hope you can help, thank you!

Cheers, Marlies

Submitted by support on Mon, 2020-01-20 16:44

Hello Marlies,

My apologies the first replacement to includes/admin.php was missing the ["meta"] key:

      if ($admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"]) $importRecord["image_url"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["image_url"];
      if (isset($admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["price"])) $importRecord["price"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["price"];
      if (isset($admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["old_price"])) $importRecord["old_price"] = $admin_importProductMappingsOverrides[$importRecord["name"]]["meta"]["old_price"]

(corrected above)

Cheers,
David.
--
PriceTapestry.com

Submitted by nanaz on Mon, 2020-01-20 19:47

Hi David,

Yes,that did the trick!

Thank you again for your great support - as always,

Cheers, Marlies