My favorites | Sign in
Project Logo
                
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
<?php

/*
Copyright 2008 Ashant Chalasani
http://code.google.com/p/sosc/
Licenced under GPL2
*/
// echo $_SERVER['SERVER_NAME']; exit;
require ('includes/application_top.php');
require(DIR_WS_INCLUDES . 'meta_tags.php');

# -- Check script input paramters
# - c: country for which feed is being produced. Currently supported UK, US, DE
# - possibly include currency in future
if (trim($HTTP_GET_VARS['feed_name']) == '') die ('Mention name of the feed (feed_name)...!');

# -- Title suffix, to differentiate item titles from clone sites
$title_suffix = preg_replace('/http\:\/\//', '', HTTP_SERVER); # rid of http://
$title_suffix = preg_replace('/www\./', '', $title_suffix); # rid of www.
$title_suffix = preg_replace('/\/$/', '', $title_suffix); # rid of trailing slash (/)

# -- Some prelim definitions
$output_file = DIR_PUB_WEB . "/feeds/" . $HTTP_GET_VARS['feed_name'] . ".xml";
$item_count = 0;

# -- Connect to db using OSC standard methods, and run the query to get item data
tep_db_connect();

$query = "SELECT P.products_id AS p_id, P.products_model AS p_model, P.products_price AS p_price,
P.products_image AS p_image, P.products_quantity AS p_qty,
PD.products_description AS p_desc, PD.products_name AS p_name
FROM products P, products_description PD
WHERE P.products_id = PD.products_id
AND P.products_status = 1";

$result = tep_db_query($query);

# -- A new DOM object
$dom = new DomDocument('1.0');

# -- Create the rss 2.0 definition tag

$rss = $dom->appendChild($dom->createElement('rss'));

$xmlns = $dom->createAttribute('xmlns:g');
$xmlns->value = "http://base.google.com/ns/1.0";
$rss->appendChild($xmlns);

$version = $dom->createAttribute('version');
$version->value = "2.0";
$rss->appendChild($version);

# -- Create feed/channel definition tags
$channel= $rss->appendChild($dom->createElement('channel'));

$title = $channel->appendChild($dom->createElement('title'));
$title->appendChild($dom->createTextNode(STORE_NAME));

$link = $channel->appendChild($dom->createElement('link'));
$link->appendChild($dom->createTextNode(HTTP_SERVER));

# -- Loop through table records and construct tags for each item
while ($row = tep_db_fetch_array($result))
{
// print $row['p_id'] . " - " . $row["p_model"] . " - " . $row['p_name'] . ' - ' . $title_suffix . "<br>";

# -- Create <item> root
$item = $channel->appendChild($dom->createElement('item'));

# -- Mandatory tags needed by Google Base

$price = $item->appendChild($dom->createElement('id'));
$price->appendChild($dom->createTextNode($row['p_model'] . '_' . $HTTP_GET_VARS['feed_name']));
# need to append country code,
# Base shows only unique prod ID's
# and skips prods in diff country feeds

$desc = $item->appendChild($dom->createElement('description'));
$desc->appendChild($dom->createTextNode($row['p_desc']));

$price = $item->appendChild($dom->createElement('g:price'));
$price->appendChild($dom->createTextNode($row['p_price']));

$title = $item->appendChild($dom->createElement('title'));
$title->appendChild($dom->createTextNode(utf8_encode($row['p_name']) . ' - ' . $title_suffix));
# We append the site's domain name to the title, so that it appears in
# Google Shopping search result title (ex. "HDF-200 Cable - 10wlan.com")

$link = $item->appendChild($dom->createElement('link'));
$link->appendChild($dom->createTextNode(HTTP_SERVER . DIR_WS_CATALOG . 'product_info.php?products_id=' . $row['p_id'] . "&currency=" . $HTTP_GET_VARS['currency']));

# -- Recommended tags needed by Google Base
$link = $item->appendChild($dom->createElement('g:image_link'));
$link->appendChild($dom->createTextNode(HTTP_SERVER . DIR_WS_CATALOG . DIR_WS_IMAGES . '/' . $row['p_image']));

$condition = $item->appendChild($dom->createElement('g:condition'));
$condition->appendChild($dom->createTextNode('NEW'));

$brand = $item->appendChild($dom->createElement('g:brand'));
$brand->appendChild($dom->createTextNode(utf8_encode($row['p_name']))); # same as title

$mpn = $item->appendChild($dom->createElement('g:mpn'));
$mpn->appendChild($dom->createTextNode($row['p_model'])); # same as model number

$upc = $item->appendChild($dom->createElement('g:upc'));
$upc->appendChild($dom->createTextNode(str_pad($row['p_model'], 12, '0', STR_PAD_LEFT))); # same as model number, left padded with 0. Replace with UPC if your products have them (unfortunately mine don't).

$qty = $item->appendChild($dom->createElement('g:quantity'));
$qty->appendChild($dom->createTextNode($row['p_qty'])); # same as model number, left padded with 0. Replace with UPC if your products have them (unfortunately mine don't).

$p_type = $item->appendChild($dom->createElement('g:product_type'));
$p_type->appendChild($dom->createTextNode(META_TAG_KEYWORDS));
# Modify according to requirement

# -- Payment methods accepted.
# - Add others or delete one/some of these to suit your requirement
$payment_accepted = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_accepted->appendChild($dom->createTextNode('Cash'));

$payment_accepted = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_accepted->appendChild($dom->createTextNode('Visa'));

$payment_accepted = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_accepted->appendChild($dom->createTextNode('Mastercard'));

$payment_accepted = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_accepted->appendChild($dom->createTextNode('Discover'));

$payment_accepted = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_accepted->appendChild($dom->createTextNode('Check'));

$payment_notes = $item->appendChild($dom->createElement('g:payment_accepted'));
$payment_notes->appendChild($dom->createTextNode('Google Checkout accepted and preferable! Wire-transfers accepted for overseas orders. Checks accepted for orders above $350 and goods shipped after clearing. Cash accepted for local pickup. Thank you for shopping at confero24.com'));
# change this payment_note as per your requirement
$item_count++;
}

$dom->formatOutput = true; # some formatting of XML output
// $rss_feed_string = $dom->saveXML(); # store string in variable. Included for demo purposes. Comment if you don't need it.
$bytes_written = $dom->save($output_file) || die; # save as file

print "Google Base XML Feed for " . STORE_NAME . "<p>";
print "Output written to: " . $output_file . " (" . $bytes_written . " bytes written) <br>";
print $item_count . " items included in feed at " . date('Y-m-d G:i:s');
?>
Show details Hide details

Change log

r25 by ashant on Aug 27, 2008   Diff
=included currency (in link) for G-Base
feeds
Go to: 
Project members, sign in to write a code review

Older revisions

r22 by ashant on Jun 28, 2008   Diff
=GCO moved to the top
r16 by ashant on Jun 22, 2008   Diff
=script commit from feather
r15 by ashant on Jun 22, 2008   Diff
=script commit from feather
All revisions of this file

File info

Size: 7770 bytes, 145 lines
Hosted by Google Code