Version 4 Availability Google Field Automatic In Stock/out Of Stock

Hi,



On version 4 the availability Google field doesn't change dynamically with the quantity field if something goes out of stock or is in stock.



Is it possible to change this so it changes dynamically rather than doing it manually? any code adjustments?



Thank you

James

Anyone? :)

Did this get resolved?

I have been using this in 2.2.5 and I have put something together for 4.x but I have not tested it. Add the following to the designated files. Note: This is modifying core files.



/app/addons/google_export/schemas/exim/products.post.php

$schema['export_fields']['Availability'] = array (
'table' => 'products',
'db_field' => 'amount',
'process_get' => array('fn_exim_google_export_format_availability', '#this', 'availability', '#key', ''),
'export_only' => true,
);




/app/addons/google_export/schemas/exim/products.functions.php

function fn_exim_google_export_format_availability($data, $product_id = 0)
{
$data = db_get_field("SELECT amount FROM ?:products WHERE product_id = ?i", $product_id);

if ($data <= 0) {
$data = 'out of stock';
}

if ($data > 0) {
$data = 'in stock';
}

return $data;
}

Did anyone tested in V4 ?

Did anyone tested in V4 ?

We did not see any reason why it should not work. Note that the first code should be added before the following line:

return $schema;

And do not forget to clear cache after the changes are applied

We did not see any reason why it should not work. Note that the first code should be added before the following line:

return $schema;

And do not forget to clear cache after the changes are applied

Thanks!, I got this error when I try to export the DB:

ErrorInvalid pattern definition: missing table references

ErrorNo data exported

Any ideas? Thanks in advance for your help.

Please remove the following line from the new code:

'table' => 'products',

Then clear the cache and check the result

You use the following setting in schema:

'process_get' => array('fn_exim_google_export_format_availability', '#this', 'availability', '#key', ''),

which expects fn_exim_google_export_format_availability function to have 4 parameters.

But as you can see, it has only 2:

function fn_exim_google_export_format_availability($data, $product_id = 0)

It should not work.

Map the parameters properly.

$product_id is #key.

#this is the current exporting data.

Actually this is not a reason. The table parameter is specified for the new field. But this table is not specified in the references array of the schema. So ligocc just need to delete one line.

Actually this is not a reason. The table parameter is specified for the new field. But this table is not specified in the references array of the schema. So ligocc just need to delete one line.

Which line eComLabs? I´m not a programmer, thanks!

Please remove the following line from the new code:

'table' => 'products',

Then clear the cache and check the result

Thanks, now, it doesn´t show a problem exporting, but the availability table is empty, any suggestions?

Thanks in advance.

You use the following setting in schema:

'process_get' => array('fn_exim_google_export_format_availability', '#this', 'availability', '#key', ''),

which expects fn_exim_google_export_format_availability function to have 4 parameters.

But as you can see, it has only 2:

function fn_exim_google_export_format_availability($data, $product_id = 0)

It should not work.

Map the parameters properly.

$product_id is #key.

#this is the current exporting data.

Thanks, how can I do it?

Thanks, how can I do it?

I think if you use this set of parameters in schema, it will be enough:

'process_get' => array('fn_exim_google_export_format_availability', '#this', '#key'),

You rewrite the $data anyway.

Well, no one of the solutions you gave me works, just show a empty "availability" table in CSV.

I tried with:

function fn_exim_google_export_format_availability($data, $product_id = 0)
{
$data = db_get_field("SELECT amount FROM ?:products WHERE product_id = ?i", $product_id);

if ($data <= 0) {
$data = 'out of stock';
}

if ($data > 0) {
$data = 'in stock';
}

return $data;
}

and:

$schema['export_fields']['Availability'] = array (
'db_field' => 'amount',
'process_get' => array('fn_exim_google_export_format_availability', '#this', '#key'),

(and with too:)

'process_get' => array('fn_exim_google_export_format_availability', '#this', 'availability', '#key', ''),
'export_only' => true,
);

In this last I used the "'table' => 'products'," and without it too.

And the same result, each time I did a change I cleaned the cache (?cc).

So what can I do? I really need this, as Google Merchant have suspended me many time because the stock doesn´t match.

Thanks in advance.

I don't use this nor Google Merchant anymore so unfortunately I am not set up to test it. However, if I can recall correctly, when installing the Google export addon, I believe the availability feature is automatically created. If so, disable or delete the availability feature and try the export again.

Please try

function fn_exim_google_export_format_availability($product_id = 0)
{
    $data = db_get_field("SELECT amount FROM ?:products WHERE product_id = ?i", $product_id);
        if ($data <= 0) {
                $data = 'out of stock';
        }

        if ($data > 0) {
                $data = 'in stock';
        }

        return $data;

}

and:

$schema[‘export_fields’][‘Availability’] = array (
‘linked’ => false,
‘process_get’ => array(‘fn_exim_google_export_format_availability’, ‘#key’),
‘export_only’ => true,
);

Please try

function fn_exim_google_export_format_availability($product_id = 0)
{
    $data = db_get_field("SELECT amount FROM ?:products WHERE product_id = ?i", $product_id);
        if ($data <= 0) {
                $data = 'out of stock';
        }

        if ($data > 0) {
                $data = 'in stock';
        }

        return $data;

}

and:

$schema[‘export_fields’][‘Availability’] = array (
‘linked’ => false,
‘process_get’ => array(‘fn_exim_google_export_format_availability’, ‘#key’),
‘export_only’ => true,
);

Same :(, Availibity appears blank

Please PM me temporary FTP access so that we can check the issue

Very strange. This works in 4.3.4:


$schema['export_fields']['Availability']=> array(
    'linked' => false,
    'process_get' => array('fn_exim_google_export_format_availability', '#key'),
    'export_only' => true,
    'return_result' => true
);

function fn_exim_google_export_format_availability($product_id)
{
$data = db_get_field(“SELECT amount FROM ?:products WHERE product_id = ?i”, $product_id);
return ($data > 0) ? ‘in stock’ : ‘out of stock’;
}
return $schema;