Elxis CMS Forum

Extensions => Components => Topic started by: sophocles on December 17, 2012, 14:45:14

Title: XML for Skroutz (new entry)
Post by: sophocles on December 17, 2012, 14:45:14
Hi all,
What do i need to transform the XML file that is generated by IOSeshop, in the format that is required by Skroutz.
My boss wants to use Skroutz for the company's eshop and the format that is produced from IOSeshop is quite different.
Thanks in advance for your help.
Title: Re: XML for Skroutz
Post by: datahell on December 17, 2012, 19:48:34
IOS Eshop does support exporting products in XML format.
If IOS Eshop's XML format does not match the Skroutz's format you can change the tags by editing the file below:
administrator/components/com_eshop/admin.eshop.php

On lines 2290 to 2307 you will find this:

Code: [Select]
$tags = array(
'master' => 'STOREITEMS',
'time' => 'CREATED',
'product' => 'PRODUCT',
'name' => 'NAME',
'desc' => 'DESCRIPTION',
'price' => 'PRICE',
'manufacturer' => 'MANUFACTURER',
'category' => 'CATEGORY',
'weight' => 'WEIGHT',
'model' => 'MODEL',
'quantity' => 'QUANTITY',
'url' => 'URL',
'image_url' => 'IMAGE_URL',
'added' => 'ADDED',
'modified' => 'MODIFIED',
'available' => 'AVAILABLE'
);

You can change the values (right column in the above array) in order to match your needs. For instance the "master" entry is for the head tag of the XML. By default is "STOREITEMS", So IOS Eshop will create this XML:
<STOREITEMS>
     ......
</STOREITEMS>
If you change "STOREITEMS" to "AnyThing" IOS Eshop will create this:
<AnyThing>
     ......
</AnyThing>
Title: Re: XML for Skroutz
Post by: sophocles on December 18, 2012, 10:56:17
This is a very good start in order to change just the names of the XML output.

But;
1. Since Skroutz requires the full category path (parent category/sub category 1/../subcategory ν ...) Ι suppose that Ι should look and experiment with this part of query, in order to have not only of the subcategory listing, but all parent categories as well?

Code: [Select]
$query .= "\n r.price, r.discount, r.tax, c.title AS ctitle, c.seotitle, i.file AS image";
if ($exmanufacturer) { $query .= ', m.manufacturer'; }
$query .= "\n FROM #__eshop_products p"
."\n LEFT JOIN #__eshop_categories c ON c.cid=p.cid";

and
2. Skroutz also requires on the product page to display what the actual
Code: [Select]
availability field of the XML files contains.
Where should I look for that? 

Thanks
Title: Re: XML for Skroutz
Post by: datahell on December 18, 2012, 19:00:30
To create the link to the category page you should use the "seotitle" from the query. See line 2371 (SEF = 2) on how the link to the product is generated.
The link to the category is the same except the last part (xxx.html).

$category_link = $linkbase.IOSESHOPBASE.'/'.$row['seotitle'].'/';

Code: [Select]
$data .= "\t\t".'<urltocat>'.$category_link."</urltocat>\n";
For the availability the "quantity" (db: in_stock) value gives you the number of available products in store. If greater than 0 the product is available (line 2363).

If you want to add a custom tag do it like this (example):
Code: [Select]
if ($row['in_stock'] > 0)
     $data .= "\t\t<available>YES</available>\n";
} else {
     $data .= "\t\t<available>NO</available>\n";
}

Change the tags above to match Skroutz's requirements.
Title: Re: XML for Skroutz
Post by: sophocles on December 19, 2012, 08:26:52
Wow, thanks.

I'm sure that this works but i will have to wait until Xmas vacation when i would have enough time to start and experiment on where to add what.

You see datahell, there is a big difference between someone that knows his path and someone that tries to find it within bits and pieces of knowledge.
Wish i had 1% of the knowledge that Forest has ;)

Thanks anyway, i will return to the post when i have the results (hope soon). Until then Merry Xmas to all.

Sophocles 
Title: Re: XML for Skroutz
Post by: sophocles on December 20, 2012, 11:50:01
Task No1.
By adding / replacing the proposed line of code, like this:
Code: [Select]
$category_link = $linkbase.IOSESHOPBASE.'/'.$row['seotitle'].'/';
if ($excategory) {
$data .= "\t\t<".$tags['category'].'>'.$category_link.'</'.$tags['category'].">\n";
}
the result that is created is just a part of the page's url.
Code: [Select]
<CATEGORY>
http://www.odesus.gr/eshop/anikhneuse-plaston-khartonomismaton/
</CATEGORY>

when the desired outcome should be something like (sorry about the Greek):
Quote
Συσκευές Μετρητών > Ανίχνευση πλαστών χαρτονομισμάτων
which are the main and the sub category of the product.

This is very similar (in fact a part of it ) to the pathway that is produced by (com_eshop\eshop (elxis\components\com_eshop\eshop.html.php)
Code: [Select]
$path = $eshop->catPathArray($eshopF->cid);at line 2554 (if not mistaken).

I have tried numerous combinations to achieve something that will look like the part of the e_shop pathway that displays the main and any of the sub categories in Greek, but no luck at all.


Task No2.
By adding these lines

Code: [Select]
if ($row['in_stock'] > 0) {
$data .= "\t\t<availability>YES</availability>\n";
} else {
$data .= "\t\t<availability>NO</availability>\n";
}

and this line
Code: [Select]
'availability' => 'AVAILABILITY',the result that i get is
Code: [Select]
<availability>YES</availability>which is just fine.
Title: Re: XML for Skroutz (new entry)
Post by: sophocles on December 28, 2012, 14:41:45
According to "Skroutz" requirments I have added in each product an "Additional info" field, where the AVAILABILITY of the product will be stated (e.g. "In Stock", "1 to 3 days delivery" ... "On Order" etc)

I need to include this "extravalue" field of "elx_eshop_extra_values" table, in the  AVAILABILITY field at the XML file.

I try to query the database by adding
Code: [Select]
e_v.extravalue AS extravalue,  as well as others variations and calling it with
Code: [Select]
if ($row['extravalue']) {
      $data .= "\t\t<".$tags['avilability'].'>'.$row['extravalue'].'</'.$tags['avilability'].">\n";
}
but all i get from is "Nothing to export".

Where am i wrong with the definition of the query?
Title: Re: XML for Skroutz (new entry)
Post by: datahell on December 28, 2012, 20:24:30
No, this is absolutely wrong.
You have to join the table elx_eshop_extra_values in order to fetch values from it on the same query. The join should be performed on productid column, but as extraid can vary you have also to pass the extraid value into the WHERE clause.

WARNING: If you use join wrong the query will not return products that it should...

I think my advise on using the stock value is much easier to implement and much more accurate (as it gets the value directly from the product stock and not from a text string that you may have forgotten to update).

Example:
Stock greater than 0 ? Availability: within 24hours
Stock = 0 ? Availability: within 3-4 days
Title: Re: XML for Skroutz (new entry)
Post by: sophocles on December 28, 2012, 20:43:01
Well, the stock value is out of the question, since it's just there to give availability. There is no real stock, since it's not connected or getting data from the actual stock of the company's warehouse.
I guess i will try to experiment with the first option.
Is there any particular part of the eshop's code that could help me understand better what should i be have as a target?
Title: Re: XML for Skroutz (new entry)
Post by: datahell on December 28, 2012, 20:54:24
SQL queries are platform independent, so it is not a matter of IOS Eshop.
Here is a sample join.

Code: [Select]
SELECT p.id, p.sku, x.extravalue FROM elx_eshop_products p
LEFT JOIN elx_eshop_extra_values x ON x.productid = p.id
WHERE x.extraid = 4;

Note that as extraid (I set as sample value = 4) is now part of the WHERE clause, products missing this availability extra information will not be returned by the query.

You should modify the existing query to add this one more join.
The same thing can be done with a sub-select query but it is a slow method and should be avoided (but it has the advantage of returning products missing this extra information).

Code: [Select]
SELECT p.id, p.sku, (SELECT x.extravalue FROM elx_eshop_extra_values x WHERE x.productid = p.id AND x.extraid = 4) AS extravalue
FROM elx_eshop_products p;