Editting Google Base Attributes

this is the error I’m receiving in my cs admin panel.



[COLOR=“Red”]Warning: Invalid argument supplied for foreach() in /home/gdosite/public_html/include/admin/exim.php on line 952[/COLOR]



I added the code per tool outfitters in exim_google.php and then in the admin control panel I added the variable product_condition. I ticked on export and received the above error and the error below as well. In the choices of available fields to move over to the left in exported fields I don’t see product_condition.



[COLOR=“Red”]Error

Invalid pattern definition: alternative key missed.[/COLOR]



Is there something I missed?



CS Version 2.x (have not upgraded to new version)

PHP Version 5.2.9



MaryMae

Hi MaryMae, It’s been awhile.



Can you post the code you added? Something is missing because there shouldn’t be an alt key adding the code.

Hi Hi Hi! :wink:



It has been awhile and its nice to hear from you again.



Here is the exim_google.php page info.


/******************************************************************************

* Copyright (c) 2004-2007 CS-Cart.com. All rights reserved. *

//
// $Id: google.php 7502 2009-05-19 14:54:59Z zeke $
//

if ( !defined('AREA') ) { die('Access denied'); }

//
// Schema definition
//
$schema = array (
'#section' => 'products',
'#key' => array('product_id'),
'#enclosure' => '',
'#name' => fn_get_lang_var('google_base'),
'#pattern_id' => 'google',
'#table' => 'products',
'#condition' => array('status' => 'A'),
'#export_only' => true,
'#range_options' => array (
'#selector_url' => INDEX_SCRIPT . '?dispatch=products.manage',
'#object_name' => fn_get_lang_var('products'),
),
'#references' => array (
'product_descriptions' => array (
'#reference_fields' => array ('product_id' => '#key', 'lang_code' => '@lang_code'),
'#join_type' => 'LEFT'
),
'product_prices' => array (
'#reference_fields' => array ('product_id' => '#key', 'lower_limit' => 1, 'membership_id' => 0),
'#join_type' => 'LEFT'
),
'images_links' => array (
'#reference_fields' => array('object_id' => '#key', 'object_type' => 'product', 'type' => 'M'),
'#join_type' => 'LEFT'
),
),
'#options' => array (
'lang_code' => array (
'title' => 'language',
'type' => 'languages'
),
'product_type' => array (
'title' => 'product_type',
'type' => 'select',
'variants_function' => 'fn_exim_google_get_types',
),
'condition' => array (
'title' => 'product_condition',
'type' => 'select',
'variants_function' => 'fn_exim_google_get_conditions',
),
'discounts' => array (
'title' => 'export_discounts',
'type' => 'checkbox'
),
),
'#override_options' => array (
'delimiter' => 'T',
'output' => 'S',
),
'#post_processing' => array ('fn_exim_transfer_google_file', '@filename'),
'#export_fields' => array (
'id' => array (
'#db_field' => 'product_id',
'#required' => true,
'#alt_key' => true
),
'product_type' => array (
'#process_get' => array('fn_exim_google_format_field', '', 'product_type', '', '@product_type'),
'#linked' => false
),
'condition' => array (
'#process_get' => array('fn_exim_google_format_field', '', 'condition', '', '@condition'),
'#linked' => false
),
'quantity' => array (
'#db_field' => 'amount'
),
'weight' => array (
'#db_field' => 'weight'
),
'price' => array (
'#table' => 'product_prices',
'#db_field' => 'price',
'#process_get' => array('fn_exim_google_format_field', '#this', 'price', '#key', '@discounts')
),
'mpn' => array (
'#db_field' => 'product_code'
),
'title' => array (
'#table' => 'product_descriptions',
'#db_field' => 'product',
'#process_get' => array('fn_exim_google_format_field', '#this', 'title'),
),
'description' => array (
'#table' => 'product_descriptions',
'#db_field' => 'full_description',
'#process_get' => array('fn_exim_google_format_field', '#this', 'description'),
),
'link' => array (
'#process_get' => array ('fn_exim_get_product_url', '#key'),
'#linked' => false
),
'image_link' => array (
'#process_get' => array ('fn_exim_get_image_url', '#this', 'product'),
'#db_field' => 'image_id',
'#table' => 'images_links',
),
// Please uncomment this code if you want to export ISBN feature to the google
/* 'ISBN' => array (
'#process_get' => array ('fn_exim_get_feature', '#key', 'ISBN'),
'#linked' => false
),*/
),
);


// ------------- Utility functions ---------------

//
// Get product url
// Parameters:
// @product_id - product ID

function fn_exim_get_product_url($product_id, $options = '')
{
$url = Registry::get('config.http_location') .'/'. Registry::get('config.customer_index') . "?dispatch=products&product_id=$product_id";

fn_set_hook('exim_get_product_url', $url, $product_id, $options);

return $url;
}

//
// This function get the feature value
function fn_exim_get_feature($product_id, $feature_name)
{
$feature = db_get_field("SELECT value FROM ?:product_features_values as a LEFT JOIN ?:product_features_descriptions as b ON a.feature_id = b.feature_id AND b.lang_code = ?s WHERE b.description = ?s AND a.product_id = ?i AND a.lang_code = ?s", CART_LANGUAGE, $feature_name, $product_id, CART_LANGUAGE);

return $feature;
}

//
// Formats field by its type
// Parameters:
// @data - field to be formatted
// @type - field type
function fn_exim_google_format_field($data, $type, $product_id = 0, $option = '')
{
if ($type == 'product') {
return substr(strip_tags($data), 0, 80);

} elseif ($type == 'product_type') {
return (!empty($option)) ? $option : 'other';

} elseif ($type == 'condition') {
return (!empty($option)) ? $option : 'new';

} elseif ($type == 'price') {
$_auth = array('user_id' => 0, 'membership_id' => 0, 'tax_exempt' => 'N');
$_discount = ($option == 'Y') ? fn_get_product_discount($product_id, $data, true, $_auth) : 0;
return fn_format_price($data - $_discount);

} else {
return strip_tags(str_replace( array('
','
', '
', '
'), "\\n", $data));
}
}

//
// Transfers export file to Google base servers
// Parameters:
// @filename - file name to transfer

function fn_exim_transfer_google_file($filename)
{
if (function_exists('ftp_connect')) {
$google_sets = fn_get_settings('Google');
$object = 'google';

$_ftp_host = $google_sets[$object . '_host'];
$ftp_login = $google_sets[$object . '_login'];
$ftp_pass = $google_sets[$object . '_pass'];

$__ftp_host = parse_url($_ftp_host);
$ftp_host = empty($__ftp_host['host']) ? $__ftp_host['path'] : $__ftp_host['host'];

if (empty($ftp_host) || empty($ftp_login) || empty($ftp_pass)) {
$_hl = 'google_host,google_login,google_pass';
$_set = "Google base";
fn_set_notification('W', fn_get_lang_var('warning'), str_replace('[settings]', $_set, fn_get_lang_var('specify_ftp_parameters')));
return false;
}

$ftp = @ftp_connect($ftp_host);
if ($ftp && @ftp_login($ftp, $ftp_login, $ftp_pass)) {
ftp_pasv($ftp, true);
$fp = fopen(DIR_EXIM . $filename, "rb");
if ($fp) {
echo "
Copying file to the google server...";
fn_flush();
if (@ftp_fput($ftp, basename($filename), $fp, FTP_BINARY)) {
fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('file_succ_transfered'));
} else {
fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('file_transfer_failed'));
return false;
}
fclose($fp);
} else {
fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('file_not_found'));

return false;
}

ftp_quit($ftp);
} else {
fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('ftp_connect_failed'));

return false;
}
} else {
fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('php_do_not_support_ftp'));

return false;
}

return true;
}

function fn_exim_google_get_types()
{
return array (
'tools' => 'tools',
'other' => 'other',
'2-way radios' => '2-way radios',
'accessories' => 'accessories',
'adapters' => 'adapters',
'adhesives' => 'adhesives',
'air compressors' => 'air compressors',
'air conditioners' => 'air conditioners',
'air coolers' => 'air coolers',
'air purifiers' => 'air purifiers',
'airsoft' => 'airsoft',
'alarms' => 'alarms',
'am/fm radios' => 'am/fm radios',
'amplifiers' => 'amplifiers',
'analyzers' => 'analyzers',
'antennas' => 'antennas',
'antiques' => 'antiques',
'appliances' => 'appliances',
);
}

function fn_exim_google_get_conditions()
{
return array (
'new' => 'new',
'used' => 'used',
'refurbished' => 'refurbished',
);
}

?>


[B][U]Image of the Admin Panel errors: [/U][/B]

[IMG]http://progroom.com/catalog/images/aascreenshots/gdo_admin_error.gif[/IMG]

Thanks for your help.
MaryMae

I see. You copy & pasted from the thread. The file isn’t complete. I’ve attached the complete file.

exim.google.zip

Is there a way to force CS-Cart to use the Short Description for the “description” instead of using the Full Description?



In some of my Full Descriptions I have videos. Also, some of my Full Descriptions are empty.

/schemas/exim/google.php


'description' => array (
'#table' => 'product_descriptions',
'#db_field' => '[COLOR="Blue"]short[/COLOR]_description',
'#process_get' => array('fn_exim_google_format_field', '#this', 'description'),
),

Thanks! That did it.

Hi



I am trying to add the product title to the product description. I would like the google feed to show the title but then also show the title as part of the product description too. I only want this in the feed though so adding it to the actual description in the database is not an option



Cheers for help in advance.



Steve

[quote name=‘niddocks’]Hi



I am trying to add the product title to the product description. I would like the google feed to show the title but then also show the title as part of the product description too. I only want this in the feed though so adding it to the actual description in the database is not an option



Cheers for help in advance.



Steve[/QUOTE]



change this line…


#process_get' => array('fn_exim_google_format_field', '#this', 'description'),



to…


#process_get' => array('fn_exim_google_format_field', '#this', 'description', '#key'),





add another else if to fn_exim_google_format_field so edit this (add the bolded code)


function fn_exim_google_format_field($data, $type, $product_id = 0, $option = '')
{
if ($type == 'product') {
return substr(strip_tags($data), 0, 80);

} elseif ($type == 'product_type') {
return (!empty($option)) ? $option : 'other';

} elseif ($type == 'condition') {
return (!empty($option)) ? $option : 'new';

} elseif ($type == 'price') {
$_auth = array('user_id' => 0, 'membership_id' => 0, 'tax_exempt' => 'N');
$_discount = ($option == 'Y') ? fn_get_product_discount($product_id, $data, true, $_auth) : 0;
return fn_format_price($data - $_discount);

[B]} elseif($type == 'description'){
$title = fn_get_product_name($product_id);
$data = $title . " " . $data;
return strip_tags(str_replace( array('
','
', '
', '
'), "\\n", $data));[/B]

} else {
return strip_tags(str_replace( array('
','
', '
', '
'), "\\n", $data));
}
}




this will add the title to the start of the description

anyone know how to add the new attribute :



online only



to the google feeds ?

I just discovered that all products exported for Google Base have $0.00 for the price and therefore are not showing up in Google Shopping results. Anyone know why this would happen and how to fix?

Great thread.



Has anyone worked on adding a field that contains the EAN or UPC code. I have it setup as an extra field but no idea the DB format or how to add it.

Find this code and uncomment it and replace ISBN in both instances with UPC in /schemas/exim/google.php


// Please uncomment this code if you want to export ISBN feature to the google
[COLOR="Red"]/*[/COLOR] '[COLOR="Red"]ISBN[/COLOR]' => array (
'process_get' => array ('fn_exim_get_feature', '#key', '[COLOR="Red"]ISBN[/COLOR]'),
'linked' => false
),[COLOR="Red"]*/[/COLOR]
),
);

Thanks :smiley:

Does anyone know how to put the weight type to the end of the weight field output.



ie. so the weight rate would show 12.0 kg instead of 12.0

This code is so old and outdated I would not recommend using it.

It would be best to start a new thread with exactly what you want to do.

1 Like