Hi David,
Hope all is well.
Was wondering if you would have a mod some where that grabs the variant names and values, and inserts them into a html table format for display.
Avantlink feeds on some merchants have a variant field, but the Children are not always the same name or order.
Example#1
<variants><variant><sku>87891</sku><upc>0806955492811</upc><size>XL</size><color>Tungsten</color><retail_price>159.00</retail_price><sale_price>143.10</sale_price><action_url>http://www.avantlink.com/click.php?tt=cl&mi=10072&pw=14717&url=http%3A%2F%2F800-ski-shop.com%2FServices%2FBasket%2FAddToShoppingCart%2F87891%3Fquantity%3D1%26redirect%3Dshoppingbag</action_url></variant></variants>
Example#2
<variants><variant><sku>#B04</sku></variant><variant><sku>817749010425</sku></variant></variants>
Example#3
<variants><variant><sku>16695-arcteryx-black</sku></variant></variants>
What I'd like to be able to do is put the child name in a tablehead, and the values in table rows below them.
Thanks in advance.
Bob L.
Hello Bob,
Thanks for the sample feed. I've created a new filter to convert the Avantlink Variants XML field into an HTML table, with the option to exclude certain fields such as "action_url" and limit the number of variants processed.
Firstly, add a new field `variants` to your site following the standard instructions, but instead of the dbmod.php script shown use the following since the variants data could be too large for a standard VARCHAR(255) field:
<?php
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."feeds`
ADD `field_variants` VARCHAR(255) NOT NULL";
database_queryModify($sql,$result);
$sql = "ALTER TABLE `".$config_databaseTablePrefix."products`
ADD `variants` TEXT NOT NULL";
database_queryModify($sql,$result);
print "Done.";
?>
With that in place, edit includes/filter.php and add the following new code at the end of the script, just before the closing PHP tag:
/*************************************************/
/* Variants XML to Table */
/*************************************************/
$filter_names["variantsXMLToTable"] = "Variants XML to Table";
function filter_variantsXMLToTableConfigure($filter_data)
{
print "Exclude Fields:<br />";
print "<input type='text' size='40' name='exclude' value='".widget_safe($filter_data["exclude"])."' />";
print "Limit:<br />";
print "<input type='text' size='40' name='limit' value='".widget_safe($filter_data["limit"])."' />";
}
function filter_variantsXMLToTableValidate($filter_data)
{
}
function filter_variantsXMLToTableExec($filter_data,$text)
{
if (!$text) return "";
$exclude = explode(",",$filter_data["exclude"]);
$limit = intval($filter_data["limit"]);
$html = "";
if ($variants = new SimpleXMLElement($text))
{
$html .= "<table>";
$html .= "<tr>";
foreach($variants->variant[0] as $k => $v)
{
if (in_array($k,$exclude)) continue;
$html .= "<th>".$k."</th>";
}
$html .= "</tr>";
foreach($variants->variant as $variant)
{
$html .= "<tr>";
foreach($variant as $k => $v)
{
if (in_array($k,$exclude)) continue;
$html .= "<td>".$v."</td>";
}
$html .= "</tr>";
}
$html .= "</table>";
$limit--;
if ($limit == 0) break;
}
return $html;
}
Finally, re-register your feed(s) and map the new Variants field to "Variants XML" in the feed.
From the /admin/ home page, click Filters alongside a newly re-registered feed and add a new "Variants XML to Table" filter to the Variants feed. On the configuration page for the filter you can optionally specify a comma separated list of field names to exclude from the table, such as "action_url", and optionally enter a limit value to restrict the number of variants processed by the filter. Save the filter and re-import.
To display the table below the main product description, edit html/product.php and look for the following code at line 13:
<p><?php print $mainProduct["description"]; ?></p>
...and REPLACE with:
<p><?php print $mainProduct["description"]; ?></p>
<?php if ($mainProduct["variants"]) print $mainProduct["variants"]; ?>
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Bob L.
Hi David.
You are quite welcome for the feed.
Your support is the greatest and you rock at programming.
I'll give this a try after I have my 1st. cup of coffee.
I really love your products. They rock.
Bob L.
Really Sweet Mr. David.
My turn to thank you for the Mod.
Hi Bob,
I've got quite a code library for this sort of thing; in particular mods for embellishment of product descriptions from FusePump sourced feeds which contain rich <feature> meta data.
Could you perhaps email me an example feed, either attached /zipped, or link to where I can download (e.g. yoursite.com/feeds/filename.xml) and I'll check it out for you on my test server...
Thanks,
David.
--
PriceTapestry.com