Jump to content

xml export


Recommended Posts

Merhaba Arkadaşlar, ucuzu.com sitesi xml dışa aktarımı yapmam gerekiyor. Bir adet örnek kodlama buldum. Fakat bu 1.4.4 versiyonunda veritabanı tablo yapısı farklı olduğu için hatalar veriyor. Kolama ektedir. Yardımlarınızı bekliyorum. Şimdiden Teşekkür ederim.

 

<?php
/*
 ucuzu.com XML data export v1.0

 $Id$ Y.Y.D.(c) 2009 Şubat

 Prestashop XML Export Modülü, Prestashop mimarisine tam olarak uygun biçimde yazılmıştır.
 Ürün Fiyatı çıktısı Attribute(Özellik), Tax(Vergi) ve reduction(İndirim) desteğiyle olması gereken xml export yöntemidir.
 http://www.duzgun.com

 Copyright (c) 2009 Duzgun.com

 Released under the GNU General Public License
*/

include(dirname(__FILE__).'/config/config.inc.php');
$lang = Configuration::get('PS_LANG_DEFAULT');
$curr = Configuration::get('PS_CURRENCY_DEFAULT');
$currny=Db::getInstance()->getRow('SELECT iso_code FROM `'._DB_PREFIX_.'currency` WHERE `id_currency`='.$curr);
$result=Db::getInstance()->ExecuteS('
 SELECT cp.`id_category`,cl.`name` AS cname, cl.`link_rewrite` AS category, p.`id_product`, pl.`description_short`, pl.`link_rewrite`, pl.`name`, i.`id_image`,m.`name` AS manufacturer_name, p.`id_tax`,t.`rate`,p.`reduction_price`, p.`reduction_percent`, p.`reduction_from`, p.`reduction_to`, p.`price`, p.`quantity`
 FROM `'._DB_PREFIX_.'category_product` cp
	LEFT JOIN `'._DB_PREFIX_.'category` c ON (cp.id_category = c.id_category AND c.active=1)
	LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = cp.`id_category` AND cl.`id_lang` = '.intval($lang).')
 LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = cp.id_product)
 LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.intval($lang).')
 LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
	LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`)
	LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
 WHERE p.`active` = 1 AND p.`id_category_default`=cp.`id_category`');
$link = new Link();
echo '<'.'?xml version="1.0" encoding="ISO-8859-9" standalone="yes" ?'.'>'."\n";
if(count($result)>0)
{
echo "<urunler>\n";
for ($i=0; $i<count($result); $i++)  {
$row = $result[$i];
if(empty($row["id_image"]))
$image_url = "";
else
$image_url = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'img/p/'.$row["id_product"].'-'.$row["id_image"].'.jpg';
$price = round(getReductionValue($row),2);
$products_url = 'http://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').$link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category']);
echo "\t" .  "<urun>\n";
echo "\t\t" . "<id>".$row["id_product"]."</id>\n";
echo "\t\t" . "<url>".htmlspecialchars($products_url)."</url>\n";
echo "\t\t" . "<fiyat>".$price."</fiyat>\n";
echo "\t\t" . "<birim>".$currny["iso_code"]."</birim>\n";
echo "\t\t" . "<kategori>".htmlspecialchars(getPath($row["id_category"],$row["cname"]))."</kategori>\n";
echo "\t\t" . "<resim>".$image_url."</resim>\n";
echo "\t\t" . "<isim>".htmlspecialchars($row["name"])."</isim>\n";
echo "\t\t" . "<marka><![CDATA[".trim($row["manufacturer_name"])."]]></marka>\n";
echo "\t\t" . "<tanim><![CDATA[".trim($row["description_short"])."]]></tanim>\n";
echo "\t\t" . "<action_text>"."Ürünlerimiz üretici firma garantili ve orjinaldir"."</action_text>\n";
echo "\t" .  "</urun>\n";
}
echo "</urunler>\n";
}
function getPath($id_category, $path = '')
{
global $link,$lang;
$category = new Category(intval($id_category), intval($lang));
if (!Validate::isLoadedObject($category))
die (Tools::displayError());
if ($category->id == 1)
return $path;
$category_name = Category::hideCategoryPosition($category->name);
if ($path != $category_name)
$path = $category_name.' > '.$path;
return getPath(intval($category->id_parent), $path);
}
function getReductionValue($result, $wt = true)
{
if (!is_array($result) OR !Validate::isBool($wt))
die(Tools::displayError());
// Avoid an error with 1970-01-01
if (!Validate::isDate($result['reduction_from']) OR !Validate::isDate($result['reduction_to']))
return 0;
$currentDate = date('Y-m-d');
if ($result['reduction_from'] != $result['reduction_to'] AND ($currentDate > $result['reduction_to'] OR $currentDate < $result['reduction_from']))
return 0;
// tax value
$tax = floatval(Tax::getApplicableTax(intval($result['id_tax']), floatval($result['rate'])));
// prices values
$price = floatval($result['price']);
$attribute_price = isset($result['attribute_price']) ? floatval($result['attribute_price']) : 0;
$price_ht = $price + ($attribute_price / (1 + ($tax / 100)));
if ($wt)
$price = $price_ht * (1 + ($tax / 100));
else
$price = $price_ht;
// reduction values
$reduction_price = floatval($result['reduction_price']);
if (!$wt) $reduction_price /= (1 + ($tax / 100));
$reduction_percent = floatval($result['reduction_percent']);
$reductionValue = $price * $reduction_percent / 100;
// make the reduction
if ($reduction_price AND $reduction_price > 0)
{
if ($reduction_price >= $price)
$ret = $price;
else
$ret = $reduction_price;
}
elseif ($reduction_percent AND $reduction_percent > 0)
{
if ($reduction_percent >= 100)
$ret = $price;
else
$ret = $reductionValue ;
}
return isset($ret) ? ($price-$ret) : $price;
}
?>

Link to comment
Share on other sites

  • 2 weeks later...

sorun çözüldü mü, yanıtlar mısınız. çözüldüyse yeni kodu buraya koyar mısınız başkaları da yararlansın.

sorun çözüldü ama yukardaki kodu çalışramadım 1.4'te bunun yerine arkadaşa kendi yazdığım bir scripr'i gönderdim.

kendi yazdığımdada manuel editlemeler olduğu için şuan yayınlamayı düşünmüyorum. stabil hale getirsem yayınlarım.

Link to comment
Share on other sites

  • 3 weeks later...

Selam

Kişisel görüşümü söyleyeyim. Yukarıdaki kod çalışsa bile çok kötü. Aşağıdakini geçenlerde yazmıştım. Deneyebilir misiniz ?

 

$shopUrl = 'http://www.BURAYA SITE ADI.com';	  // site adresi  http://
$prefix = "ps_";				// prefix, veritabanı ön adı
$cfgFile = dirname(__FILE__) . '/config/settings.inc.php';
if (!file_exists($cfgFile))
{
die('Script yapılandırma PrestaShop ve  config/settings.inc.php veritabanı yapılandırılması gerekir yerleştirilmelidir.');
}
require_once($cfgFile);
$db = @MySQL_Connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_);
if (!$db)
{
die('Veritabanına bağlantı kurulamıyor.');
}
MySQL_Select_DB(_DB_NAME_, $db);
MySQL_Query("SET NAMES 'utf8'");
$res = MySQL_Query("
SELECT
	c.id_category,
	c.id_parent,
	c.level_depth,
	l.name
FROM {$prefix}category c
JOIN {$prefix}category_lang l ON l.id_category = c.id_category AND l.id_lang
WHERE active = 1 AND level_depth > 0
ORDER BY level_depth, id_category
");
$categories = array();
while ($row = MySQL_Fetch_Assoc($res))
{
if ($row['level_depth'] == 1)
{
$categories[$row['id_category']] = $row['name'];
}
else
{
$categories[$row['id_category']] = $categories[$row['id_parent']] . " > " . $row['name'];
}
}
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<urunler>\n";
$res = MySQL_Query("
	SELECT
			p.id_product,
			p.reference,
			p.quantity,
			p.price,
			pl.name,
			pl.description_short,
			pl.link_rewrite,
			i.id_image,
	cp.id_category,
	m.name AS manufacturer
	FROM {$prefix}product p
	JOIN {$prefix}product_lang pl USING(id_product)
	JOIN {$prefix}image i USING(id_product)
JOIN {$prefix}category_product cp USING(id_product)
JOIN {$prefix}category c USING(id_category)
JOIN {$prefix}manufacturer m USING(id_manufacturer)
	WHERE p.active = 1
	AND i.cover = 1
	AND cp.id_category > 1
	AND c.level_depth > 1
	ORDER BY p.id_product", $db);
$currentDate = date('Y-m-d');
while ($row = MySQL_Fetch_Assoc($res))
{
$desc = strip_tags(html_entity_decode($row['description_short'], ENT_COMPAT, 'utf-8'));
echo "<urun>\n";
echo "\t<marka>" . $row['manufacturer'] . "</marka>\n";
echo "\t<isim>" . $row['name'] .  "</isim>\n";
echo "\t<fiyat>" . round($row['price']*1.18-$reduction) . "</fiyat>\n";
echo "\t<urun_url>" . $shopUrl . "/" . $row['id_product'] .
		"-" . $row['link_rewrite'] . ".html</urun_url>\n";
echo "\t<kategori>" . $categories[$row['id_category']] . "</kategori>\n";
echo "\t<resim_url>" . $shopUrl . "/img/p/" .$row['id_product'] .
		"-" . $row['id_image'] . "-large.jpg</resim_url>\n";
echo "\t<urun_kodu>" . $row['reference'] . "</urun_kodu>\n";
echo "\t<urun_id>" . $row['id_product'] . "</urun_id>\n";
  echo "</urun>\n";
}
echo "</urunler>\n";

Link to comment
Share on other sites

Merhaba, yukarıda vermiş olduğunuz koda ürün özelliklerini de eklemek istiyorum (renk ve beden, ör: siyah - m gibi) query yaparak özellikleri getirmeyi başardım ancak özellik bilgilerini alt alta getirebiliyorum query ile yanyana getirmeyi başaramadım. Nasıl yan yana getirebileceğim ile ilgili yardımcı olabilirseniz sevinirim. Yukarıdaki koda eklediğim query kısmı aşağıdaki gibidir.

 

 

$res = MySQL_Query("

SELECT`sc_attribute`.* ,`sc_attribute_impact`.* ,`sc_attribute_lang`.*

FROM`sc_attribute` ,`sc_attribute_impact` ,`sc_attribute_lang`

WHERE (

(

`sc_attribute`.id_attribute =`sc_attribute_impact`.id_attribute

)

AND (

`sc_attribute_impact`.id_attribute =`sc_attribute_lang`.id_attribute

))

AND`sc_attribute_lang`.id_lang =6

AND`sc_attribute`.id_attribute_group =1

");

 

$attributes1 = array();

while ($row = MySQL_Fetch_Assoc($res))

{

$attributes1[$row['id_product']] = $row['name'];

}

 

 

$res = MySQL_Query("

 

SELECT`sc_attribute`.* ,`sc_attribute_impact`.* ,`sc_attribute_lang`.*

FROM`sc_attribute` ,`sc_attribute_impact` ,`sc_attribute_lang`

WHERE (

(

`sc_attribute`.id_attribute =`sc_attribute_impact`.id_attribute

)

AND (

`sc_attribute_impact`.id_attribute =`sc_attribute_lang`.id_attribute

))

AND`sc_attribute_lang`.id_lang =6

AND`sc_attribute`.id_attribute_group =2

");

 

$attributes2 = array();

while ($row = MySQL_Fetch_Assoc($res))

{

$attributes2[$row['id_product']] = $row['name'];

}

Link to comment
Share on other sites

genel olarak ürün ve seçeneklerini birleştirme sorgusu böyledir:

 

SELECT p.reference, n.name, at.name, ROUND(p.price+COALESCE(at.price,0),2)
FROM `ps_product` p
LEFT JOIN `ps_product_lang` n ON(n.id_product=p.id_product AND n.id_lang=6)
LEFT JOIN (SELECT id_product, price, GROUP_CONCAT(l.name ORDER BY l.name) name FROM
`ps_product_attribute` a
LEFT JOIN `ps_product_attribute_combination` c USING(id_product_attribute)
LEFT JOIN `ps_attribute_lang` l ON(l.id_attribute=c.id_attribute AND l.id_lang=6)
GROUP BY a.id_product_attribute) at ON(at.id_product=p.id_product)

 

ps_'ler yerine sc_ yazın ve bunu yukarki koda uygulayın.

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

×
×
  • Create New...