Publish Ubercart Product to Google Base using Views

By dzieyzone

To setup a google base feed xml using views, you first need to install the following modules:

  • Views
  • Ubercart
  • Views Bonus
  • CCK

First, import the following code to your views.

$view = new view;
$view->name = 'google_products';
$view->description = 'Google Merchant Feeds';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'product' => 'product',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'field_googlebase_value' => array(
'operator' => 'not empty',
'value' => '',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'case' => 1,
'id' => 'field_googlebase_value',
'table' => 'node_data_field_googlebase',
'field' => 'field_googlebase_value',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'relationship' => 'none',
'build_mode' => 'full',
'links' => 1,
'comments' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed_1');
$handler->override_option('style_plugin', 'views_xml');
$handler->override_option('style_options', array(
'mission_description' => FALSE,
'description' => '',
'provide_file' => 0,
'filename' => 'view-%view.xml',
));
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array());
$handler->override_option('path', 'google-base.xml');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler->override_option('displays', array());
$handler->override_option('sitename_title', 1);

Second, upload the attached file to your theme folder ensuring that we have a custom display for our feed or xml.

Note that I created a separate CCK field (googlebase) for the content of the google base because of its strict implementation of words. In this way, you can control your content and prevent errors by google. If you prefer to use your body then it's up to you but like I said, body is the place for html contents and google don't accept html codes or even words.

Your rating: None Average: 3.9 (11 votes)