Google Sitemap Addon - Include Out of Stock Products in sitemap.xml while hiding them from shop using General Settings...

Hello to all,



The problem, using CS-Cart 2.2.4 Professional, is described as following…

When you hide the Products that are “Out of Stock” using General Settings and specifically the option:

Show out of stock products

they are not included in sitemap.xml using the Google Sitemap Addon.

Of course, someone may wish that behavior, so the following solution is for only those that:

Wish to hide the Out of Stock Products in their e-shop, while in parallel they want those products to be included in the sitemap.xml that is generated from Google Sitemap Addon.







In the CS-Cart file structure and specifically at:



\Your_CSCart_Root_Directory\addons\google_sitemap



exists the file func.php that is controlling the addon's behavior.

At line 182 (CS-Cart 2.2.4 Professional) the code about Inclusion of Products is starting.

The Original Code is:



if ($sitemap_settings['include_products'] == "Y") {
$page = 1;
$total = ITEMS_PER_PAGE;
$params = $_REQUEST;
$params['page'] = $page;
$params['custom_extend'] = array('categories');
$params['sort_by'] = 'null';
$params['only_short_fields'] = true;
while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
list($products, $search, $total) = fn_get_products($params, ITEMS_PER_PAGE);
$params['page']++;
foreach ($products as $product) {
$links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages);
$item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']);
fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
fwrite($file, $item);
}
}
unset($products);
}






Replace this Code with the following one:



if ($sitemap_settings['include_products'] == "Y") {
Registry::set('settings.General.show_out_of_stock_products', 'Y');
$page = 1;
$total = ITEMS_PER_PAGE;
$params = $_REQUEST;
$params['page'] = $page;
$params['custom_extend'] = array('categories');
$params['sort_by'] = 'null';
$params['only_short_fields'] = true;
while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
list($products, $search, $total) = fn_get_products($params, ITEMS_PER_PAGE);
$params['page']++;
foreach ($products as $product) {
$links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages);
$item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']);
fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
fwrite($file, $item);
}
}
unset($products);
Registry::set('settings.General.show_out_of_stock_products', 'N');
}






The only thing that I modified is to add two lines of code.

The first line is in the beginning of the specific section and it is used to set the Setting Variable settings.General.show_out_of_stock_products to Yes (Y). The line is:



Registry::set('settings.General.show_out_of_stock_products', 'Y');




Then the Addon continues and does its job, “thinking” that you show all Products on your e-shop (In Stock and Out of Stock together). After it finishes its work and has written in the sitemap.xml, we revert the change of the setting back, using:



Registry::set('settings.General.show_out_of_stock_products', 'N');




I have tested it and it is working fine, since now I have all the products in the sitemap.xml and not only the In Stock products that I had before.

So, Google will also index your Out of Stock Products which may result to a better Ranking.



Thank you and I wish you all to have a nice weekend,



Lefteris

www.evrima.gr

CS-Cart 2.2.4 Professional

Cool! ;-) In my store (cs-cart 3.0.6 ultimate) I hide all of the old products instead of disabling them so that the SERP for the given product could still generate traffic. Including them in sitemap.xml is a great idea. Do you know if this works for 3.0.6?



Best regards,

Jacek