You are here:  » Need to use a different price fields for some products and need assistance


Need to use a different price fields for some products and need assistance

Submitted by ostaveland on Thu, 2008-12-04 22:32 in

Hi David,

When i register my feed i have to choose which price field to use.

The problem is that the data feed for products from the merchant uses 4 different (price) fields. And for some products the price is in the field called (store_prices) and in others (search_prices) etc. And in some there might be a price in both.

But since i only use the price field that i select when i do the register for the lead, i only get the price on some products.

Is it possible to fix this with filters or something else?

Best regards
Ole

Submitted by support on Fri, 2008-12-05 09:51

Hello Ole,

This is a tricky one, but can be sorted quite easily with a little code embedded into the import record handler function. In includes/admin.php, look for this code beginning at line 155:

    /* check product record for minimum required fields */
    if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;

At this point, you could add a check for the price, and if there is no value present look for and use a value from other fields by REPLACING the above code with something like this:

    /* check product record for minimum required fields */
    if (!$record[$admin_importFeed["field_price"]])
    {
      if ($record[$admin_importFeed["search_prices"]])
      {
        $admin_importFeed["field_price"] = "search_prices";
      }
      elseif ($record[$admin_importFeed["other_prices"]])
      {
        $admin_importFeed["field_price"] = "other_prices";
      }
    }
    if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;

So, if you register the most commonly used price field during registration, the above code will change the price field to the first alternative that has a value if the default price field is empty...

Cheers,
David.

Submitted by ostaveland on Fri, 2008-12-05 11:19

Hi again David,

Thanx for a good fast answer!

But it does not seem to show any more prices, could it be that it still uses the 0.00 since it is not empty, i mean, it does contain 0.00?

And if i want to add an additional 2 more places for it to search for the price, would i then just make two more elseif statements like the one above with the new names?

can i use the same approach on the images, if i want to add more places for it too look for images?

Best regards
Ole S.

Submitted by support on Fri, 2008-12-05 11:22

Hi Ole,

Yes - that would be the case if it contains 0.00 instead of being empty (what an awkward feed!). Easily fixed with an = 0 comparison, so use:

    /* check product record for minimum required fields */
    if ($record[$admin_importFeed["field_price"]] = 0)
    {
      if ($record[$admin_importFeed["search_prices"]] > 0)
      {
        $admin_importFeed["field_price"] = "search_prices";
      }
      elseif ($record[$admin_importFeed["other_prices"]] > 0)
      {
        $admin_importFeed["field_price"] = "other_prices";
      }
    }
    if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;

You can keep adding elseif() lines as you mention copying the above to extend the search for a valid price to more fields; and to do the same thing for the image url field use $record["field_image_url"] instead of $record["field_price"] - although in this case use the original code as they will be string rather than numeric values...

Cheers,
David.

Submitted by ostaveland on Sun, 2008-12-07 16:04

Hi again David,

I have tried to do the steps that you tell me above, but when i do and try to "register and trial import" it does not import anything. It is all ok before i edit the includes/admin.php. But after the edit it does not want to import anything.

This is what i changed in includes/admin :

/* check product record for minimum required fields */
if ($record[$admin_importFeed["field_price"]] = 0)
{
if ($record[$admin_importFeed["store_price"]] > 0)
{
$admin_importFeed["field_price"] = "store_price";
}
elseif ($record[$admin_importFeed["search_price"]] > 0)
{
$admin_importFeed["field_price"] = "search_price";
}
elseif ($record[$admin_importFeed["display_price"]] > 0)
{
$admin_importFeed["field_price"] = "display_price";
}
elseif ($record[$admin_importFeed["rrp_price"]] > 0)
{
$admin_importFeed["field_price"] = "rrp_price";
}
}
if (!$record[$admin_importFeed["field_name"]] || !$record[$admin_importFeed["field_buy_url"]] || !$record[$admin_importFeed["field_price"]]) return;

My feed has these 4 places to place their price: store_price, search_price, rrp_price and display_price.

And here is an example of the places where the prices are put.

store_price : 0.00
search_price : 49.95
rrp_price : 0.00
display_price : "49.95"

Any ideas why this does not work?

And btw, thanx for all you help so far, it is really helpfull.

And sorry if my english is hard to understand!

Best regards
Ole S.

Submitted by support on Sun, 2008-12-07 19:42

Hello Ole,

My apologies, there is a typo in my original post; I have used = instead of == to test for zero. The first line instead of:

if ($record[$admin_importFeed["field_price"]] = 0)

...should be:

if ($record[$admin_importFeed["field_price"]] == 0)

Apologies for the inconvenience,

Cheers,
David.

Submitted by ostaveland on Sat, 2008-12-13 22:43

Hi again David,

I tried setting the double ==, but it still does not work. But im currently at work and can't work on this at the moment. If this should work i guess it must be me doing something wrong. And i will look into it when i come home again.

But thanx a lot for your help, i really appreciate it.

Best Regards
Ole

Submitted by support on Sun, 2008-12-14 12:23

Hello Ole,

Feel free to email me any files you have modified that you would like me to check over...

Cheers,
David.