'Ubercart Google Base Integration.',
'page callback' => 'uc_gbase_test',
'access arguments' => array('administer ubercart google base integration'),
'type' => MENU_CALLBACK,
);
$items['uc_gbase/items'] = array(
'description' => 'Ubercart Google Base Integration items feed.',
'page callback' => 'uc_gbase_get_products',
'access arguments' => array('administer ubercart google base integration'),
'type' => MENU_CALLBACK,
);
$items['admin/store/settings/uc_gbase'] = array(
'title' => 'Ubercart Google Base Integration',
'description' => 'Settings for Ubercart Google Base Integration by fred.',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_gbase_store_admin_settings_form'),
'access arguments' => array('administer ubercart google base integration'),
'type' => MENU_NORMAL_ITEM,
);
$items['uc_gbase/submit'] = array(
'title' => 'Ubercart Google Base Product Submit',
'description' => 'Submit Products to Google Merchant',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_gbase_submit_node_form'),
'access arguments' => array('administer ubercart google base integration'),
'type' => MENU_CALLBACK,
);
return $items;
}
function uc_gbase_permission(){
/* return array('administer ubercart google base integration');*/
/* Modified by Fred Loup */
return array(
'administer ubercart google base integration' => array(
'title' => t('View published uc_gbase'),
),
);
/* end of modification */
}
class uc_gbase_xml {
public $xml = NULL;
protected $app = 'http://www.w3.org/2007/app';
protected $gd = 'http://schemas.google.com/g/2005';
protected $sc = 'http://schemas.google.com/structuredcontent/2009';
protected $scp = 'http://schemas.google.com/structuredcontent/2009/products';
function __construct() {
$xmltext = "\n
";
$this->xml = simplexml_load_string($xmltext);
}
function add_element($name, $value, $type = NULL) {
$node = $this->xml->addChild($name, $value);
if (!empty($type)) {
$node->addAttribute('type', $type);
}
}
function add_attribute($name, $value, $type = NULL, $namespace = 'sc') {
$node = $this->xml->addChild($name, $value, $this->$namespace);
if (!empty($type)) {
$node->addAttribute('type', $type);
}
}
function set_draft($draft = FALSE) {
$value = empty($draft) ? 'no' : 'yes';
$control = $this->xml->addChild('app:control', NULL, $this->draftns);
$node = $control->addChild('app:draft', $value, $this->draftns);
}
public function __toString() {
return $this->xml->asXML();
}
public function get_xml() {
return $this->xml->asXML();
}
}
function uc_gbase_update_all_products() {
$form = array();
$result = db_query("SELECT * FROM {node} WHERE type=NODE_TYPE");
$index = 0;
while($row = $result->fetchAssoc()){
$node = node_load($row['nid']);
/*echo '|'.$node->title;*/
$index = $index+1;
$form['titre'.$index] = array(
'#type' => 'textfield',
'#title' => t('node title'),
'#size' => 60,
'#maxlength' => 255,
'#default_value' => $node->title,
);
$form['nid'.$index] = array(
'#type' => 'textfield',
'#title' => t('node nid'),
'#size' => 60,
'#maxlength' => 255,
'#default_value' => $node->nid,
);
}
$form = system_settings_form($form);
return $form;
}
function uc_gbase_store_admin_settings_form() {
$form = array();
$form['uc_gbase_account_id'] = array(
'#type' => 'textfield',
'#title' => t('Account ID'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_account_id', ''),
);
$form['uc_gbase_app_name'] = array(
'#type' => 'textfield',
'#title' => t('App Name'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_app_name', ''),
);
$form['uc_gbase_country'] = array(
'#type' => 'textfield',
'#title' => t('Country'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_country', ''),
);
$form['uc_gbase_currency'] = array(
'#type' => 'textfield',
'#title' => t('Currency'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_currency', 'USD'),
);
$form['uc_gbase_account_email'] = array(
'#type' => 'textfield',
'#title' => t('Account Email'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_account_email', ''),
);
$form['uc_gbase_account_password'] = array(
'#type' => 'textfield',
'#title' => t('Account Password'),
'#size' => 60,
'#maxlength' => 255,
'#required' => TRUE,
'#default_value' => variable_get('uc_gbase_account_password', ''),
);
$form = system_settings_form($form);
return $form;
}
function uc_gbase_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
$node = $form['#node'];
$images_list = uc_gbase_get_images_list($node/*$form['uc_product_image']/*$form['field_image_cache']*/);
if ($form['type']['#value'] == NODE_TYPE) {
$form['uc_gbase'] = array(
'#type' => 'fieldset',
'#title' => t('Ubercart Google Base Integration Settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$uc_gbase = 0;
if(property_exists($node, 'uc_gbase')){
$uc_gbase = $node->uc_gbase;
}
$payment_options = array(
t('Cash'),
t('Check'),
t('Visa'),
t('MasterCard'),
t('Discover'),
t('WireTransfer'),
t('AmericanExpress'),
);
if($uc_gbase != 0){
$defaults['submit_type'] = $uc_gbase['submit_type'];
$defaults['product_name'] = $uc_gbase['product_name'];
$defaults['product_type'] = $uc_gbase['product_type'];
$defaults['product_description'] = $uc_gbase['product_description'];
$defaults['product_condition'] = $uc_gbase['product_condition'];
$defaults['product_brand'] = $uc_gbase['product_brand'];
$payment_methods = explode('$',$uc_gbase['payment_method']);
array_pop($payment_methods);
foreach($payment_options as $payment_index => $payment_method){
if(in_array($payment_method, $payment_methods)){
$defaults['payment_method'][$payment_index] = $payment_index;
}
}
foreach($payment_options as $payment_index => $payment_method){
if(!in_array($payment_method, $payment_methods)){
$defaults['payment_method'][$payment_index] = 0;
}
}
$images = explode('$',$uc_gbase['images']);
array_pop($images);
foreach($images_list as $image_index => $image){
if(in_array($image, $images)){
$defaults['images'][$image_index] = $image_index;
}
}
foreach($images_list as $image_index => $image){
if(!in_array($image, $images)){
$defaults['images'][$image_index] = 0;
}
}
}
else $defaults = array();
$form['uc_gbase']['submit_type'] = array(
'#type' => 'radios',
'#default_value' => isset($defaults['submit_type']) ? $defaults['submit_type'] : 1,
'#options' => array(
t('Do not submit this product item to Google Merchant.'),
t('Submit this product item to Google Merchant'),
),
);
$defaults['product_name'] = $node->title;
$form['uc_gbase']['product_name'] = array(
'#type' => 'textfield',
'#title' => t('Product Name'),
'#description'=>'The product name which will be published on Google Base, If left empty the default product title will be used.',
'#size' => 30,
'#maxlength' => 255,
'#default_value' => isset($defaults['product_name']) ? $defaults['product_name'] : '',
);
$form['uc_gbase']['product_type'] = array(
'#type' => 'textfield',
'#title' => t('Product Type'),
'#description'=>'The category which this Product should be listed under on Google Product Search,
You Can refer to categories on Google Merchant Help,
Or you can find the sheet on Product Taxonomy,
An example of what you should enter in this field is:
Arts & Entertainment > Crafts & Hobbies > Drawing & Painting > Painting',
'#size' => 60,
'#maxlength' => 255,
'#default_value' => isset($defaults['product_type']) ? $defaults['product_type'] : 'Arts & Entertainment > Crafts & Hobbies > Drawing & Painting > Painting',
);
$form['uc_gbase']['product_description'] = array(
'#type' => 'textarea',
'#title' => t('Product Description'),
'#description'=>'The description of the product to be published on Google Base, Must be all text, NO HTML. If you have a wysiwyg editor on your site please click the Switch to plain text editor link.',
'#wysiwyg' => FALSE,
'#maxlength' => 1024,
'#default_value' => isset($defaults['product_description']) ? $defaults['product_description'] : '',
);
$form['uc_gbase']['product_brand'] = array(
'#type' => 'textfield',
'#title' => t('Product Brand'),
'#description'=>'The brand of the product : Valérie Sabban.',
'#size' => 60,
'#maxlength' => 255,
'#default_value' => isset($defaults['product_brand']) ? $defaults['product_brand'] : '',
);
$form['uc_gbase']['product_condition'] = array(
'#type' => 'radios',
'#title' => 'Product Condition',
'#default_value' => isset($defaults['product_condition']) ? $defaults['product_condition'] : 0,
'#options' => array(
t('New'),
t('Used'),
t('Refurbished'),
),
);
$form['uc_gbase']['payment_method'] = array(
'#type' => 'checkboxes',
'#title' => 'Payment Methods',
'#default_value' => isset($defaults['payment_method']) ? $defaults['payment_method'] : array(0),
'#options' => $payment_options,
);
/* Modif Fred :
1/destite all my tests, the original implementation did not work -in my situation- to retrieve the correct image link after submit
2/ I know that there is only one image associated to the node
==> I decided to pass the parameter as a single item, in e text box
*/
/*
$form['uc_gbase']['images'] = array(
'#type' => 'checkboxes',
'#title' => 'Images to submit',
'#default_value' => isset($defaults['images']) ? $defaults['images'] : array(0),
'#options' => $images_list,
);
*/
$form['uc_gbase']['images'] = array(
'#type' => 'textfield',
'#title' => 'Images to submit',
'#size' => 100,
'#maxlength' => 500,
'#default_value' => $images_list[0],
);
}
}
}
function uc_gbase_node_load($nodes, $types) {
foreach($nodes as $nid=>$node){
if($node->type == NODE_TYPE){
$node->uc_gbase_id = uc_gbase_load($node->nid);
$result = db_query('SELECT submit_type, product_name, product_type, product_description, product_condition,product_brand, payment_method, images FROM {uc_gbase} WHERE nid = :nid', array(':nid' => $node->nid))->fetchAssoc();
$node->uc_gbase = $result;
}
}
}
function uc_gbase_node_insert($node){
if($node->type == NODE_TYPE){
$node->uc_gbase_id = uc_gbase_load($node->nid);
$node->uc_gbase_id = uc_gbase_insert_item($node);
}
}
function uc_gbase_node_update($node){
if($node->type == NODE_TYPE){
$node->uc_gbase_id = uc_gbase_load($node->nid);
$node->uc_gbase_id = uc_gbase_insert_item($node);
}
}
function uc_gbase_node_delete($node){
$node->uc_gbase_id = uc_gbase_load($node->nid);
if (!empty($node->uc_gbase_id)) {
$deleted = uc_gbase_delete_item($node);
if (empty($deleted)) {
drupal_set_message(t('@title was not successfully deleted from Google Base.', array('@title' => $node->title)));
}
else {
uc_gbase_delete($node->nid);
}
}
}
function uc_gbase_authenticate(){
$url = 'https://www.google.com/accounts/ClientLogin';
$headers = array(
'Content-Type' => 'application/x-www-form-urlencoded',
);
$email = urlencode(variable_get('uc_gbase_account_email', ''));
$password = urlencode(variable_get('uc_gbase_account_password', ''));
$app_name = urlencode(variable_get('uc_gbase_app_name', ''));
$options = array(
'method' => 'POST',
'data' => "Email=$email&Passwd=$password&service=structuredcontent&source=$app_name",
'headers' => $headers,
);
$result = drupal_http_request($url, $options/*$headers, 'POST' , "Email=$email&Passwd=$password&service=structuredcontent&source=$app_name"*/);
$result = stristr ($result->data, 'Auth=');
return $result;
}
function uc_gbase_load($nid) {
if (is_numeric($nid)) {
$gid = db_query("SELECT gid FROM {uc_gbase} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
return $gid;
}
}
function uc_gbase_delete($nid) {
if (is_numeric($nid)) {
$result = db_query("DELETE FROM {uc_gbase} WHERE nid = :nid", array(':nid' => $nid));
return ($result->rowCount() > 0);
}
}
function uc_gbase_delete_item($node) {
global $language;
$account_id = variable_get('uc_gbase_account_id', '');
$store = variable_get('uc_gbase_country', '');
$item_url = "https://content.googleapis.com/content/v1/$account_id/items/products/schema/online:$language->language:$store:$node->uc_gbase_id";
$auth = uc_gbase_authenticate();
$headers = array(
'Content-Type' => 'application/atom+xml',
'Authorization' => 'GoogleLogin '.trim($auth),
);
$options = array(
'method' => 'DELETE',
'data' => NULL,
'headers' => $headers,
);
$result = drupal_http_request($item_url, $options/*$headers, 'DELETE', NULL*/);
return ($result->code == 200);
}
function uc_gbase_insert_item($node) {
$uc_gbase = $node->uc_gbase;
if($uc_gbase['submit_type'] == 1){
$record['nid'] = $node->nid;
$record['submit_type'] = $uc_gbase['submit_type'];
$record['product_name'] = $uc_gbase['product_name'];
$record['product_type'] = $uc_gbase['product_type'];
$record['product_description'] = $uc_gbase['product_description'];
$record['product_brand'] = $uc_gbase['product_brand'];
$record['product_condition'] = $uc_gbase['product_condition'];
$record['images'] = $uc_gbase['images'];
$record['payment_method'] = '';
$payment = $uc_gbase['payment_method'];
$i = 0;
foreach($payment as $check_item){
if($i == 0 && $check_item == 0){
$record['payment_method'] = $record['payment_method'].'Cash'.'$';
break;
}
$i++;
}
if($payment[1] == 1)
$record['payment_method'] = $record['payment_method'].'Check'.'$';
if($payment[2] == 2)
$record['payment_method'] = $record['payment_method'].'Visa'.'$';
if($payment[3] == 3)
$record['payment_method'] = $record['payment_method'].'MasterCard'.'$';
if($payment[4] == 4)
$record['payment_method'] = $record['payment_method'].'Discover'.'$';
if($payment[5] == 5)
$record['payment_method'] = $record['payment_method'].'WireTransfer'.'$';
if($payment[6] == 6)
$record['payment_method'] = $record['payment_method'].'AmericanExpress'.'$';
/* I use the parameter coming from the submit process rather than extracting from node */
/* That is why I deleted the 11 line starting at (original line 427) */
/* $images_list = uc_gbase_get_images_list */
$images = $uc_gbase['images'];
/* or $images = $uc_gbase['images'].'$'; */
/* depends on how the fiels images is processed with google - not checked yet */
$record['gid'] = _uc_gbase_insert_xml($node, $record['payment_method'], $images);
$nid = db_query("SELECT nid FROM {uc_gbase} WHERE nid = :nid", array(':nid' => $record['nid']))->fetchField();
if (empty($node->uc_gbase_id) && empty($nid)) {
$result = db_query("INSERT INTO {uc_gbase} (nid, gid, submit_type, product_name, product_type, product_description, product_condition,product_brand, payment_method, images)
VALUES (:nid, :gid, :submit_type, :product_name, :product_type, :product_description, :product_condition,:product_brand, :payment_method, :images)", array(
':nid' => $record['nid'], ':gid' => $record['gid'], ':submit_type' => $record['submit_type'], ':product_name' => $record['product_name'], ':product_type' => $record['product_type'],
':product_description' => $record['product_description'], ':product_condition' => $record['product_condition'], ':product_brand' => $record['product_brand'], ':payment_method' => $record['payment_method'], ':images' => $images));
}
else {
$result = db_query("UPDATE {uc_gbase}
SET gid = :gid, submit_type = :submit_type , product_name = :product_name, product_type = :product_type, product_description = :product_description, product_condition = :product_condition ,product_brand = :product_brand,
payment_method = :payment_method, images = :images WHERE nid = :nid",array(':gid' => $record['gid'], ':submit_type' => $record['submit_type'], ':product_name' => $record['product_name'],
':product_type' => $record['product_type'], ':product_description' => $record['product_description'],
':product_condition' => $record['product_condition'], ':product_brand' => $record['product_brand'], ':payment_method' => $record['payment_method'], ':images' => $images, ':nid' => $record['nid'])
);
}
//}
return $record['gid'];
}
}
function uc_gbase_get_images_list($node/*$form_image_fields*/){
global $base_url;
$images = '';
/*modif Fred Loup : I use the field_image of les_toile node */
/* if(property_exists($node, 'original')){*/
if(property_exists($node, 'field_image')){
/*$form_image_fields = $node->original->uc_product_image;*/
$form_image_fields = $node->field_image;
if(is_array($form_image_fields)){
foreach($form_image_fields['und'] as $image){
if(is_array($image)){
if(array_key_exists('uri', $image))
$images = $images.file_create_url($image['uri']).'$';/*$base_url.'/'.$image_item['filepath'].'$';*/
}
}
$images_list = explode('$', $images);
array_pop($images_list);
return $images_list;
}
else{
return array();
}
}else{
/*$form_image_fields = $node->uc_product_image;*/
$form_image_fields = $node->field_image;
if(is_array($form_image_fields)){
foreach($form_image_fields['und'] as $image){
if(is_array($image)){
if(array_key_exists('#default_value', $image)){
$image_item = $image['#default_value'];
if(is_array($image_item)){
if(array_key_exists('uri', $image_item))
$images = $images.file_create_url($image_item['uri']).'$';
}
}
}
}
$images_list = explode('$', $images);
array_pop($images_list);
return $images_list;
}
else{
return array();
}
}
}
function _uc_gbase_insert_xml($node, $encoded_payment_methods, $encoded_images) {
$item = new uc_gbase_xml();
global $base_url;
global $language;
$store = variable_get('uc_gbase_country', '');
$uc_gbase = $node->uc_gbase;
$item->add_attribute('item_type', 'products');
$item->add_element('title', ucwords(substr(strtolower($uc_gbase['product_name']), 0, 69)), 'text');
$item->add_element('content', htmlspecialchars($uc_gbase['product_description']) , 'text');
$node_link = $item->xml->addChild('sc:link');
$node_link->addAttribute('rel','alternate');
$node_link->addAttribute('type','text/html');
$alias = drupal_lookup_path('alias', 'node/'.$node->nid);
if($alias){
$parts = explode('/', $alias);
$parts[1] = urlencode($parts[1]);
$alias = implode($parts, '/');
$node_link->addAttribute('href', $base_url . '/' . $alias);
}else{
$node_link->addAttribute('href', $base_url . '/node/' .$node->nid );
}
$item->add_element('summary', htmlspecialchars($uc_gbase['product_description']));
$item->add_attribute('sc:id', $node->nid.$node->model.$language->language);
$item->add_attribute('scp:product_type', htmlspecialchars($uc_gbase['product_type']), 'text', 'scp');
$item->add_attribute('sc:content_language', $language->language, 'text');
$item->add_attribute('sc:target_country', $store, 'text');
$price_item = $item->xml->addChild('scp:price', $node->sell_price, 'http://schemas.google.com/structuredcontent/2009/products');
$price_item->addAttribute('unit',variable_get('uc_gbase_currency', 'USD'));
$item->add_attribute('scp:brand', $uc_gbase['product_brand']/*$node->field_manufact_name['0']['value']*/, 'text', 'scp');
$item->add_attribute('scp:mpn', $node->model, 'text', 'scp');
$item->add_attribute('scp:gtin', $node->model, 'text', 'scp');
$item->add_attribute('scp:availability', 'available for order', 'text', 'scp');
$item->add_attribute('scp:google_product_category', htmlspecialchars($uc_gbase['product_type']), 'text', 'scp');
$images = explode('$',$encoded_images);
array_pop($images);
foreach($images as $image){
$item->add_attribute('sc:image_link', $image);
}
if($uc_gbase['product_condition'] == 0){
$condition = 'new';
}
else if($uc_gbase['product_condition'] == 1){
$condition = 'used';
}
else{
$condition = 'refurbished';
}
$item->add_attribute('scp:condition', $condition, 'text', 'scp');
$payment_methods = explode('$',$encoded_payment_methods);
array_pop($payment_methods);
foreach($payment_methods as $payment_method){
$item->add_attribute('payment_accepted', $payment_method);
}
if ($node->shippable) {
$item->add_attribute('weight', floatval($node->weight).' '.$node->weight_units);
$item->add_attribute('width', floatval($node->dim_width).' '.$node->length_units);
$item->add_attribute('length', floatval($node->dim_length).' '.$node->length_units);
$item->add_attribute('height', floatval($node->dim_height).' '.$node->length_units);
}
$account_id = variable_get('uc_gbase_account_id', '');
$items_feed_url = "https://content.googleapis.com/content/v1/$account_id/items/products/generic";
$method = 'POST';
if (!empty($node->uc_gbase_id)) {
$items_feed_url .= '/online:'.$language->language.':'.$store.':'. $node->uc_gbase_id;
$method = 'PUT';
}
$uc_gbase_xml = $item->get_xml();
$auth = uc_gbase_authenticate();
$headers = array(
'Content-Type' => 'application/atom+xml',
'Authorization' => 'GoogleLogin '.trim($auth),
);
$options = array(
'method' => $method,
'data' => $uc_gbase_xml,
'headers' => $headers,
);
$result = drupal_http_request($items_feed_url, $options/*$headers, $method, $uc_gbase_xml*/);
watchdog('result', print_r($result, true));
if (($result->code == '200' || $result->code == '201') && !empty($result->headers['Location'])) {
return $node->nid.$node->model.$language->language;
}
elseif ($result->code == '404') {
if (!empty($node->uc_gbase_id)) {
uc_gbase_delete($node->nid);
unset($node->uc_gbase_id);
return _uc_gbase_insert_xml($node);
}
else {
$xml = new SimpleXMLElement($result->data);
foreach ($xml->error as $error) {
if (user_access('administer google base')) {
drupal_set_message(t('Google Base error: @reason', array('@reason' => (string) $error['reason'])), 'error');
}
}
}
}
return FALSE;
}
function uc_gbase_feeds_node_processor_targets_alter(&$targets, $content_type) {
if ($content_type == NODE_TYPE) {
$targets['product_name'] = array(
'name' => t('Product Name on Google Merchant'),
'description' => t('Product Name on Google Merchant'),
'callback' => 'uc_gbase_set_target',
);
$targets['product_description'] = array(
'name' => t('Product Description on Google Merchant'),
'description' => t('Product Description on Google Merchant'),
'callback' => 'uc_gbase_set_target',
);
$targets['images'] = array(
'name' => t('Product Images on Google Merchant'),
'description' => t('Product Images on Google Merchant'),
'callback' => 'uc_gbase_set_target',
);
}
}
function uc_gbase_set_target($node, $target, $value) {
if(!isset($node->uc_gbase)){
$node->uc_gbase = array();
$node->uc_gbase['submit_type'] = 1;
$node->uc_gbase['product_condition'] = 0;
$node->uc_gbase['payment_method'] = array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6);
$node->uc_gbase['images'] = 'http://'.$_SERVER['SERVER_NAME'].'/'.file_create_url($node->uc_product_image['und'][0]['uri']);
$node->uc_gbase[$target] = $value;
}
else{
$node->uc_gbase[$target] = strip_tags($value);
}
}
function uc_gbase_submit_node_form(){
$form = array();
$nodes = variable_get('site_products', array());
if(empty($nodes)){
$result = db_query("SELECT * FROM {node} WHERE type=NODE_TYPE");
while($row = $result->fetchAssoc()){
$node = node_load($row['nid']);
$nodes[$row['nid']] = $row['title'];
variable_set('site_products', $nodes);
}
}
$form['nodes'] = array(
'#type' => 'select',
'#title' => t('Products'),
'#default_value' => 0,
'#options' => $nodes,
'#multiple' => TRUE,
'#description' => t('Site Products'),
);
$form['delete'] = array(
'#type' => 'checkbox',
'#title' => 'Delete from Google Merchant',
'#default_value' => 0,
);
$form['product_type'] = array(
'#type' => 'textfield',
'#title' => t('Product Type'),
'#size' => 100,
'#maxlength' => 128,
'#default_value' => '',
'#description'=> 'The category which this Product should be listed under on Google Product Search,
You Can refer to categories on Google Merchant Help,
Or you can find the sheet on Product Taxonomy,
An example of what you should enter in this field is:
Arts & Entertainment > Crafts & Hobbies > Drawing & Painting > Painting',
'#required' => TRUE,
);
$form['brand'] = array(
'#type' => 'textfield',
'#title' => t('Brand'),
'#size' => 100,
'#maxlength' => 128,
'#default_value' => '',
'#description'=> '',
'#required' => TRUE,
);
$form['product_condition'] = array(
'#type' => 'radios',
'#title' => 'Product Condition',
'#default_value' => 0,
'#options' => array(
t('New'),
t('Used'),
t('Refurbished'),
),
);
$form['payment_method'] = array(
'#type' => 'checkboxes',
'#title' => 'Payment Methods',
'#default_value' => array(0, 1, 2, 3, 4, 5, 6),
'#options' => array(
t('Cash'),
t('Check'),
t('Visa'),
t('MasterCard'),
t('Discover'),
t('WireTransfer'),
t('AmericanExpress'),
),
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit Products'));
return $form;
}
function uc_gbase_submit_node_form_submit($form, &$form_state){
$operations = array('operations' => array(), 'title' => t('Processing Products'));
foreach($form_state['values']['nodes'] as $nid){
$operations['operations'][] = array('uc_gbase_submit_node', array($nid, $form_state['values']['product_type'], $form_state['values']['product_condition'], $form_state['values']['payment_method'], $form_state['values']['brand'], $form_state['values']['delete']) ) ;
}
batch_set($operations);
}
function uc_gbase_submit_node($nid, $type, $condition, $payment_method, $brand, $delete){
$node = node_load($nid);
watchdog('node', dprint_r(array($nid, $node), true));
global $base_url;
global $language;
if($delete){
$account_id = variable_get('uc_gbase_account_id', '');
$store = variable_get('uc_gbase_country', '');
$item_url = "https://content.googleapis.com/content/v1/$account_id/items/products/schema/online:$language->language:$store:$node->uc_gbase_id";
$auth = uc_gbase_authenticate();
$headers = array(
'Content-Type' => 'application/atom+xml',
'Authorization' => 'GoogleLogin '.trim($auth),
);
$options = array(
'method' => 'DELETE',
'data' => NULL,
'headers' => $headers,
);
$result = drupal_http_request($item_url, $options);
}
else{
$node->uc_gbase = array(
'submit_type' => 1,
'product_name' => ucwords(substr(strtolower($node->title), 0, 69)),
'product_type' => $type,
'product_description' => htmlspecialchars(strip_tags($node->body)),
'product_condition' => $condition,
'product_brand' => $brand,
'payment_method' => $payment_method,
'images' => array(file_create_url($node->uc_product_image['und'][0]['uri'])),
);
$node = node_submit($node);
node_save($node);
}
}