Hello,
how can I import additional images? XML looks like this: (stripped)
<product id='108'>
<link>http://...</link>
<name>product name</name>
...
<imgs>
<img default='1'>http://....jpg</img>
<img>http://....jpg</img>
<img>http://....jpg</img>
<img>http://....jpg</img>
</imgs>
</product>
Total in is not specified, it can be 0 or 20 for example. I think right way is create new database table like this:
CREATE TABLE `products_images` (
`id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`image_url` varchar(255) COLLATE utf8_czech_ci NOT NULL
) ENGINE=MyISAM;
(no indexes for now)
The way is in function admin__importRecordHandler call another magicparser with full path to images, it return global variable - array - with images, but it take long time to import, it's like recursive calling.
Is there another solution? I have this fields more:
<delivery>
<dellivery_type>string</delivery_type>
<delivery_cost>decimal</delivery_cost>
</delivery>
<delivery>
<dellivery_type>string</delivery_type>
<delivery_cost>decimal</delivery_cost>
</delivery>
<delivery>
<dellivery_type>string</delivery_type>
<delivery_cost>decimal</delivery_cost>
</delivery>
and params, attributes etc.
I know I can use filters. I can create additional_image in table products and feeds and use filter like this %IMGS/IMG@1%|%IMGS/IMG@2%|%IMGS/IMG@3% (when I want use one db table) - but I don't know how much IMG@ will be. It can be empty.
Is there way...?
Thank for help!
Hi David,
it work perfectly. Thank you!
BTW misclick:
if (!$importRecord["merchant"]) return;
if (isset($record["IMGS/IMG"))
should be
if (!$importRecord["merchant"]) return;
if (isset($record["IMGS/IMG"]))
char ] missed.
Bender
Ooops! All corrected above...!
Cheers,
David.
--
PriceTapestry.com
Hello Bender,
A less complex method than using another database table (as bear in mind the product IDs change at every import) would be add some code to the import record handler to look for the multiple img tags and create a comma separated list of image URLs in the image_url field. Firstly, the field would need to be converted to text, which the following dbmod.php script will do:
<?php
require("includes/common.php");
$sql = "ALTER TABLE `".$config_databaseTablePrefix."products`
CHANGE `image_url` `image_url` TEXT NOT NULL";
database_queryModify($sql,$result);
print "Done.";
?>
With that in place; for a feed that has this style of image URL , leave the field mapping empty on Feed Registration Step 2. Instead, in includes/admin.php look for the following code at line 343:
if (!$importRecord["merchant"]) return;
...and REPLACE with:
if (!$importRecord["merchant"]) return;
if (isset($record["IMGS/IMG"]))
{
$images = array();
$i = 0;
$p = "";
while(1)
{
if ($i) $p = "@".$i;
$k = "IMGS/IMG".$p;
if (!isset($record[$k])) break;
$images[] = $record[$k];
$i++;
}
$importRecord["image_url"] = implode(",",$images);
}
With that in place, throughout the code where images are displayed the list can be exploded() by "," and as many images as required used, for example in html/searchresults.php to display just the first image look for the following code at line 9:
<?php if ($product["image_url"]): ?>
...and REPLACE with:
<?php if ($product["image_url"]): ?>
<?php
$images = explode(",",$product["image_url"]);
$product["image_url"] = $images[0];
?>
Whereas to display all images, in html/product.php, look for the following code at line 7:
<img width='180' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print htmlentities($mainProduct["name"],ENT_QUOTES,$config_charset); ?>' />
...and REPLACE with:
<?php
$images = explode(",",$mainProduct["image_url"];
foreach($images as $mainProduct["image_url"]):
?>
<img width='180' src='<?php print $mainProduct["image_url"]; ?>' alt='<?php print htmlentities($mainProduct["name"],ENT_QUOTES,$config_charset); ?>' />
<?php endforeach; ?>
Regarding multiple delivery options, very similar code could be added to includes/admin.php at the same point as described above. First, add the new field `delivery` to your site according to the instructions in this thread and use something like:
if (isset($record["DELIVERY/DELIVERY_TYPE"]))
{
$delivery = array();
$i = 0;
$p = "";
while(1)
{
if ($i) $p = "@".$i;
$k1 = "DELIVERY/DELIVERY_TYPE".$p;
$k2 = "DELIVERY/DELIVERY_COST".$p;
if (!isset($record[$k])) break;
$type = $record[$k1];
$cost = $record[$k2];
$delivery[] = $type.":".$cost."<br />";
$i++;
}
$importRecord["delivery"] = implode(",",$delivery);
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com