/
yandex.php
233 lines (178 loc) · 7.46 KB
/
yandex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
ini_set('max_execution_time', '320');
$rDB = mysql_connect(
'127.0.0.1',
'lindero_rel',
'c2lVM442') or die( 'error connect to DB' );
mysql_select_db('lindero_rel');
mysql_query('set names windows-1251');
function _exportToYandexMarket( $f, $rate, $export_product_name )
{
$spArray = array(
'exprtUNIC'=>array(
'mode' =>'toarrays',
'expProducts' =>array()
)
);
$exportCategories = array(array(),array());
_exportBegin( $f );
_exportAllCategories( $f, $spArray['exprtUNIC']['expProducts'] );
_exportProducts( $f, $rate, $export_product_name, $spArray['exprtUNIC']['expProducts'] );
_exportEnd( $f );
}
function _deleteHTML_Elements( $str )
{
$str = str_replace( "<","<", $str );
$str = str_replace( ">",">", $str );
$str = str_replace( "&","&", $str );
$str = str_replace( "\"",""", $str );
$str = str_replace( "'","'", $str );
return $str;
}
function _exportBegin( $f )
{
fputs( $f, "<?xml version=\"1.0\" encoding=\"windows-1251\"?>\n" );
fputs( $f, "<!DOCTYPE yml_catalog SYSTEM \"shops.dtd\">\n" );
fputs( $f, "<yml_catalog date=\"".date("Y-m-d H:i")."\">\n" );
fputs( $f, " <shop>\n" );
fputs( $f, " <name>Lindero</name>\n");
fputs( $f, " <company>Lindero</company>\n");
fputs( $f, " <url>http://www.lindero.ru</url>\n");
fputs( $f, " <currencies>\n");
fputs( $f, " <currency id=\"RUR\" rate=\"1\" plus=\"0\"/>\n");
fputs( $f, " </currencies>\n");
}
function _exportAllCategories( $f, &$_ProductIDs )
{
$Cats = array();
$execCats = array();
$sql = "
SELECT catt.category_id, cdes.category, catt.parent_id FROM cscart_categories catt
LEFT JOIN cscart_category_descriptions cdes on cdes.lang_code=\"RU\" and cdes.category_id=catt.category_id order by catt.parent_id
";
$q = mysql_query($sql);
fputs($f," <categories>\n");
while ($row = mysql_fetch_array($q))
{
if (strlen($row[1])>4){
if(!in_array($row[0], $execCats)){
$execCats[] = $row[0];
}
if(!in_array($row[2], $Cats) && $row[2]>1){
$Cats[] = $row[2];
}
$row[1] = _deleteHTML_Elements( $row[1] );
if ($row[2] <= 1)
{
fputs($f," <category id=\"".$row[0]."\">".$row[1]."</category>\n");
}
else
{
fputs($f," <category id=\"".$row[0]."\" parentId=\"".$row[2]."\">".$row[1]."</category>\n");
}
}
}
while (count($Cats)) {
$sql = "
SELECT catt.category_id, cdes.category, catt.parent_id FROM cscart_categories catt
LEFT JOIN cscart_category_descriptions cdes on cdes.lang_code=\"RU\" and cdes.category_id=catt.category_id order by catt.parent_id
";
$q = mysql_query($sql);
$Cats = array();
while ($row = mysql_fetch_array($q))
{
if (strlen($row[1])>4){
$Disp = false;
if(!in_array($row[0], $execCats)){
$execCats[] = $row[0];
$Disp = true;
}
if( !in_array($row[2], $execCats) && !in_array($row[2], $Cats) && $row[2]>1){
$Cats[] = $row[2];
}
$row[1] = _deleteHTML_Elements( $row[1] );
if ($row[2] <= 1 && $Disp)
{
fputs($f," <category id=\"".$row[0]."\">".$row[1]."</category>\n");
}
elseif($Disp)
{
fputs($f," <category id=\"".$row[0]."\" parentId=\"".$row[2]."\">".$row[1]."</category>\n");
}
}
}
}
fputs($f," </categories>\n");
}
function _exportProducts( $f, $rate, $export_product_name, &$_ProductIDs )
{
fputs( $f, " <offers>\n");
$clause="";
//$clause = " export_visible==1 and amount>0";
$clause = " cp.amount>0 and cp.is_edp=1";
//âûáðàòü òîâàðû
//$proCount = count($_ProductIDs);
//$iter = 0;
//for (; $iter<$proCount;$iter+=100){
$sql = "select cp.product_id, cpd.product, cp.list_price, cpc.category_id, ci.*, cp.amount from cscart_products cp
left join cscart_product_descriptions cpd on cpd.product_id=cp.product_id and cpd.lang_code=\"RU\"
left join cscart_products_categories cpc on cpc.product_id=cp.product_id
left join cscart_images_links cil on cil.object_id=cp.product_id
left join cscart_images ci on ci.image_id=cil.image_id
where ".$clause;
$q = mysql_query($sql);
$store_url = "http://www.lindero.ru";
while ($product = mysql_fetch_assoc($q))
{
$product["product"]=str_replace("&","&",$product["product"]);
fputs( $f, " <offer available=\"".(($product['amount'])?'true':'false')."\" id=\"".$product["product_id"]."\">\n");
fputs( $f, " <url>http://lindero.ru/index.php?dispatch=products.view&product_id=".$product["product_id"]."&from=ya</url>\n" );
fputs( $f, " <price>".preg_replace("/\..*/","",$product["list_price"])."</price>\n" );
fputs( $f, " <currencyId>RUR</currencyId>\n" );
fputs( $f, " <categoryId>".$product["category_id"]."</categoryId>\n" );
$q1 = mysql_query("select ci.image_path as filename from cscart_images_links cil
join cscart_images ci on ci.image_id=cil.image_id
and cil.object_id=".$product["product_id"]);
$pic_row = mysql_fetch_assoc($q1);
$pix=glob("/home/aqq7507/public_html/lindero.ru/images/*/*/*/".$pic_row["filename"]);
$pix[0]=str_replace("&","&",$pix[0]);
//var_dump($pix);
//echo " ".$product["product_id"]." ".$pic_row["filename"]." ".$pix[0]."<br>\n";
// var_dump(str_replace('/home/aqq7507/public_html/', 'http://',$pix[0]));exit();
if ($pic_row) //ýêñïîðòèðîâàòü ôîòîãðàôèþ
{
//if ( strlen($pic_row["filename"]) && file_exists("./products_pictures/".$pic_row["filename"]) )
fputs( $f, " <picture>".str_replace('/home/aqq7507/public_html/', 'http://',$pix[0])."</picture>\n" );
}
//$product["product"] = $_NameAddi._deleteHTML_Elements( $product["product"] );
fputs( $f, " <name>".$product["product"]."</name>\n" );
if ( strlen($dsc)>0 )
{
// $product[$dsc] = _deleteHTML_Elements( $product[$dsc] );
$product["product"] = strip_tags( $product["product"] );
fputs( $f, " <description>".$product["product"].
"</description>\n" );
}
else
{
fputs( $f, " <description></description>\n" );
}
fputs( $f, " </offer>\n");
}
//}
fputs( $f, " </offers>\n");
}
function _exportEnd( $f )
{
fputs( $f, " </shop>\n" );
fputs( $f, " </yml_catalog>\n" );
}
$rurrate = 30;
$yandex_export_product_name = 'only_name';
$f = fopen("/home/aqq7507/public_html/lindero.ru/temp/yandex.xml","w");
if ($f)
{
_exportToYandexMarket( $f, $rurrate, $yandex_export_product_name );
fclose($f);
}
?>