Hi David
I'm on the last furlong to creating my first fully automated site but I,ve hit one final problem.
I'd like to include postage (added to total price) in the PT comparison table. The sort of thing I'm after is explained in node/2410.
Since many merchants dont include postage in their feeds and postage often varies according to price, the following script is what I'd like to impliment:
if ($admin_importFeed["merchant"]=="Some Merchant")
{
$price = $record[$admin_importFeed["field_price"]];
if ($price < 50.00) { $delivery = "7.99"; }
elseif ($price < 100.00) { $delivery = "3.99"; }
else { $delivery = "0.00"; }
$record[$admin_importFeed["field_postage"]] = $delivery; // set postage field to $delivery
}
The thing is I don't know how to go about it. What is the "myRecordHandler" function and where would I put this piece of script to make it work?
Many thanks,
Matt
Hi David
I've tried adding the addition fields modification with little success. The feeds now no longer seeem to import and any new feeds can not be registered.
I'm fairly new to this and I think it's getting a bit above me. What I want is to set the postage rate for a particular merchant according to the price of the product.
For instance:
0.00-50.00, shipping cost: 7.99
50.00-100.00, shipping cost: 3.99
100.00 and above, shipping cost: 0.00 (free).
and then add the shipping and product price to make a total in the comparison table.
Is this easily possible?
Thanks, Matt
Hi Matt,
Could you email me any files you have modified and I'll check it all through for you!
Cheers,
David.
Hi David,
Trying to get this to work with the new distribution but no joy. Have added all code as far as I can see.
Here's the code I have in admin.php
if ($admin_importFeed["merchant"]=="MerchantA")
{
$price = $record[$admin_importFeed["field_price"]];
if ($price < 20.00) { $delivery = "3.95"; }
elseif ($price < 120) { $delivery = "5.25"; }
else { $delivery = "0.00"; }
$record[$admin_importFeed["field_delivery"]] = $delivery;
I can send on relevant files if it will help you diagnose.
Many thanks
Adrian
Hi Adrian,
Slightly different variables will be required with the new distribution. In place of the above, try:
if ($admin_importFeed["merchant"]=="MerchantA")
{
$price = $importRecord["price"];
if ($price < 20.00) { $delivery = "3.95"; }
elseif ($price < 120) { $delivery = "5.25"; }
else { $delivery = "0.00"; }
$importRecord["delivery"] = $delivery;
In general, when manipulating values within the import record handler; the variables are as follows (using the price field as an example)...
0106A (original distribution):
$record[$admin_importFeed["field_price"]]
1109A onwards:
$importRecord["price"]
Hope this helps!
Cheers,
David.
Hi Guys,
Here's a nice little snippet to help with your postage calcs.
Create a field for postage in the feeds and product tables if you haven't already done so. Now, you can either map this to a field in the merchant's data feed or what I've done to handle multiple shipping bands is add the following code to includes/admin.php:
elseif (stripos($admin_importFeed["field_postage"], ":"))
{
$parts = explode(":",$admin_importFeed["field_postage"]);
$wheres = array();
foreach($parts as $k => $part) if (!$part) unset($parts[$k]);
$j = count($parts);
for($i=0;$i<$j-1;$i+=2)
{
$min = explodeExec("-",$parts[$i],0);
$max = explodeExec("-",$parts[$i],1);
if ($total >= $min || $total <= $max)
{
$postage = tapestry_decimalise($parts[$i+1]);
}
}
}
I am doing some other processing hance the 'elseif' so you may just need an 'if' depending on what else you're doing. The '$total' variable can be replaced by $record[$admin_importFeed["field_price"]] - I've just done some more processing beforehand, hence I'm using a different variable.
So, that's the code part which means you can now edit the postage field in your feeds table on a per merchant basis, and what you can put in is something like this:
0-29.99:3.95:29.99-:FREE
The : is the separator so this translates as products costing between £0 and £29.99 have a postage rate of £3.95 but above £29.99 they're free (the hyphen separates the min and max values - where there's no value, there's no max value hence the 29.99- equates to 29.99 and above). This can be expanded for more bands, e.g.
0-15:2.99:15-30:1.99:30-:FREE
i.e. £0-£15 postage is £2.99, £15-£30 postage is £1.99, over £30 it is free. The values are read in literally so you could change 'FREE' to 'No Delivery Charge' or whatever you want to use.
Hope that helps.
Cheers.
Keeop
Hi David
Having a few problems with new price tapestry...
I've placed the above code in admin.php and added new fields as described in node/3094 but I'm having problems getting it to work.
Is there anything else I need to do?
Thanks,
Matt
Hi Matt,
The only difference between the modification to apply to the original distribution compared to the latest is that wherever a field is referred to in this way:
$record[$admin_importFeed["field_delivery"]]
...would now be:
$importRecord["delivery"]
(where delivery is which ever field is being referred to)
If you're not sure, if you could email me your modified config.advanced.php and includes/admin.php I'll check it out for you...
Cheers,
David.
Ah, got it working. Was getting mixed up with postage and delivery. Just set everything to postage and it worked fine.
Hi Matt,
The first stage in going about this would be to implement the addition fields modification (assuming you have not already done so) from this thread:
http://www.pricetapestry.com/node/313
However, it looks like you may have already done this as you refer to $record[$admin_importFeed["field_postage"]], in which case, you could add code almost exactly as you describe (it looks perfect in fact) within the import record handler function which is this function:
function admin__importRecordHandler($record)
...beginning at line 124 of includes/admin.php.
The point at which I would add your code above would be immediately prior to the dupe hash calculation, in otherwords just before this comment on line 248:
/* create dupe_hash value */
Cheers,
David.