Jump to content

[SOLVED] script to export productlist as XML


Recommended Posts

Hello!

I am working on php script that would enable mine partners to download my pricelist from certain link...
It is based on this work: http://www.prestashop.com/forums/viewthread/25318/modules_tiers/module_dexport_catalogue_format_xml

I got it working but but have some problems... script generates huge ammount of products becouse it inputs all existing products, active and non active and it create multiple entries of the same product becouse it is in multiple categories even do it is the same product with its unique product ID.
(script is attached)

Any help how to purge that data so that php dont generate xml with multiple product entries and dont collect inactive products?

HELP!

pricelist_xml_generator.php

  • Like 2
Link to comment
Share on other sites

OK,
i'w found some examples on forum and i put together fully functional script so here it is if someone needs it.

<?php
$langHr = 7;
include(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');

error_reporting(0);
$p=Product::getProducts(7, 0, 0, 'id_product', 'desc', false); // number 7 is id of language in database
$products=Product::getProductsProperties(7, $p); // number 7 is id of language in database

header("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>

';
foreach ($products as $row) {
if ($row['active']){

$img=Product::getCover($row['id_product']);
echo '

'.str_replace("&", "&", $row['id_product']).'
'.str_replace("&", "&", $row['name']).'
'.str_replace("&", "and", strip_tags($row['description_short'])).'
'.($row['price']*1).'
'.str_replace("&", "&", $row['quantity']).'
'.str_replace("&", "&", $row['category']).'
   <link>http://www.site.com'.$row['link'].'</link>
http://www.site.com/shop/'.$shopUrl.'img/p/'.$row['id_product'].'-'.$img['id_image'].'.jpg
';
}
}
echo '';
?>



put this php file into your shop folder and thats it... just send that url to your partners and they are ready to receive your data.

  • Like 1
Link to comment
Share on other sites

Huh... still some help needed.

this line

'.str_replace("&", "&", $row['quantity']).'


works correct and returns exact number of products on stock.

But i need to change quantity as number into word "AVAILABLE" when quantity number is more than 0.

Can someone halp?

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 2 weeks later...
  • 2 weeks later...
  • 6 months later...

It's normal for IE to say that before displaying the XML in the browser. That doesn't mean there's a problem with the XML. Open it using Notepad or another editor instead if you don't want to see that text.

Link to comment
Share on other sites

  • 4 weeks later...

Thanks, for category there is an code below but i want to be default category, what must changes be?

// Category
$categoryname = $dom->createElement("Category");
$product->appendChild($categoryname);
$categoryname_text = $dom->createTextNode($category->name);
$categoryname->appendChild($categoryname_text);

Link to comment
Share on other sites

Something like the following should work:

// Default Category
$defaultCategory = new Category($productinfo->id_category_default, $cookie->id_lang);
$categoryname = $dom->createElement("Category");
$product->appendChild($categoryname);
$categoryname_text = $dom->createTextNode($defaultCategory->name); 
$categoryname->appendChild($categoryname_text);

Link to comment
Share on other sites

Can someone please explain to me how to implement the php files that you guys attached. I really need this as I have over 2500 Items on my online store. And i need a quick and easy way of getting a pricelist. With their Categories (All Categories), Their Price (Including if i used a discounted price), their reference number and Product Item/Description. and the image if possible.

I downloaded the attached files and put it in a php but i get an error:



The ERROR:

Warning: include(../../config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

Warning: include(../../config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

Warning: include() [function.include]: Failed opening '../../config/config.inc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

Warning: include(../../init.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3

Warning: include(../../init.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3

Warning: include() [function.include]: Failed opening '../../init.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3
Category ID is missing


Please help me

Link to comment
Share on other sites

  • 1 year later...

Hello,

 

script works just fine, but i get wrong image path because i am using PrestaShop 1.4.8.2 and new image file system.

 

Script generates this image path: http://www.mydomain....57-56-large.jpg

 

But images are located in: http://www.mydomain....17-32-large.jpg

 

What do i need to change in this line: echo "<img>http://www.mydomain.com".__PS_BASE_URI__."img/p/".$image[0]['id_product']."-".$image[0]['id_image']."-large.jpg</img>\n";

 

Thanx!

Edited by sakrafanas (see edit history)
Link to comment
Share on other sites

got it working but but have some problems... script generates huge ammount of products becouse it inputs all existing products, active and non active and it create multiple entries of the same product becouse it is in multiple categories even do it is the same product with its unique product ID.

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...
  • 3 months later...

Can someone please explain to me how to implement the php files that you guys attached. I really need this as I have over 2500 Items on my online store. And i need a quick and easy way of getting a pricelist. With their Categories (All Categories), Their Price (Including if i used a discounted price), their reference number and Product Item/Description. and the image if possible.

 

I downloaded the attached files and put it in a php but i get an error:

 

 

 

The ERROR:

 

Warning: include(../../config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

 

Warning: include(../../config/config.inc.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

 

Warning: include() [function.include]: Failed opening '../../config/config.inc.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kamjocoz/public_html/gct/pricelistproper.php on line 2

 

Warning: include(../../init.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3

 

Warning: include(../../init.php) [function.include]: failed to open stream: No such file or directory in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3

 

Warning: include() [function.include]: Failed opening '../../init.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kamjocoz/public_html/gct/pricelistproper.php on line 3

Category ID is missing

 

 

Please help me

Replace the two firtst rows:

 

include('../../config/config.inc.php');
include('../../init.php');

with these:

 

include(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');
Link to comment
Share on other sites

  • 2 years later...
×
×
  • Create New...