Jump to content
Crezzur

[FREE MODULE] DataSwitchPro - Automatic on/off switch for (sub)categories and products

Recommended Posts

DataSwitchPro - Automatic on/off switch for categories and products
free module by crezzur

Update 16/05: we are considering adding a cronjob to this module (fires automatically every x time and disable and enable categories). For this we want feedback from the users to know if this update is needed.

Features
< This module will automatically search for (sub)categories with no products and automatically disable them. >
<
This module will automatically search for (sub)categories with products and  automatically enable them. >
<
This module will automatically search for products with no quantity's and automatically disable them. >
<
This module will automatically search for products with quantity's and automatically enable them. >
<
You can choose the time frame of the DataSwitchpro (how many times a day it has to check to enable/disable products) >
<
You can disable (sub)categories or products if you don't want to use this feature. >

How does this work?
Every time a customer visit your site a query will run to see when was the last time the DataSwitchPro was active.
If this is longer then the time frame you have selected, a update query will run.
Products and (sub)Categories with no products/quantity's will automatically disable.
Products and (sub)Categories that are updated with new products/quantity's will automatically be re-activated.

This product works with Prestashop versions
1.6.+ / 1.7+

Back office configuration

2.thumb.jpg.e63a00f4d9c4f72442c2487fae3d2218.jpg

Setup
Install the zip file, change the settings if you want, and your ready!

Download this FREE module NOW!

V1.0.4 (26/05/2019)* Click here to download OR dataswitchpro.zipdataswitchpro.zip
Contributors: PrestaMake

V1.0.3 (16/12/2018)* DOWNLOAD REMOVED

 

V1.0.2 (09/10/2017)* DOWNLOAD REMOVED
* We have updated our module to the prestashop 1.7 codding requirments.
Products which allow ordering when out of stock will not be disabled anymore

V1.0.1 (08/11/2016)* DOWNLOAD REMOVED
* Version 1.0.0 has to be uninstalled first.

V1.0.0 (17/02/2015) DOWNLOAD REMOVED

---------------- PS: a like and a thank you for my work is appreciated ----------------

Edited by Crezzur (see edit history)
  • Like 11
  • Thanks 2

Share this post


Link to post
Share on other sites

Thanks! Much appreciated!

PS> New feature

In {$HOOK_HEADER} insert something like this

{if $page_name == 'product'}
			{if $product->active != 1}
				{foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat name=cats}
					{if $smarty.foreach.cats.last}
						{assign var="cat_url" value="{$link->getCategoryLink({$cat.id_category})}"}
					{/if}    
				{/foreach}
				<meta http-equiv="refresh" content="0; url={$cat_url}" />
			{/if}
		{/if}

to redirect disabled product to their parent category. For better user experience. Product not available but the traffic is not wasted :)

Best regards! :)

Share this post


Link to post
Share on other sites

Hi,

 

worked fine until I updated to 1.6.1.8
 

After the upgrade i have this error:  (I think that is due to the module) :mellow:

[PrestaShopDatabaseException]

Db->executeS() must be used only with select, show, explain or describe queries
at line 638 in file classes/db/Db.php

633.         }
634. 
635.         // This method must be used only with queries which display results
636.         if (!preg_match('#^\s*\(?\s*(select|show|explain|describe|desc)\s#i', $sql)) {
637.             if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_) {
638.                 throw new PrestaShopDatabaseException('Db->executeS() must be used only with select, show, explain or describe queries');
639.             }
640.             return $this->execute($sql, $use_cache);
641.         }
642. 
643.         $this->result = $this->query($sql);

    DbCore->executeS - [line 90 - modules/DataSwitchPro/DataSwitchPro.php] - [1 Arguments]
    DataSwitchPro->hookFooter - [line 587 - classes/Hook.php] - [1 Arguments]
    HookCore::coreCallHook - [line 544 - classes/Hook.php] - [3 Arguments]
    HookCore::exec - [line 1022 - classes/controller/FrontController.php] - [1 Arguments]
    FrontControllerCore->initFooter - [line 195 - classes/controller/Controller.php]
    ControllerCore->run - [line 367 - classes/Dispatcher.php]
    DispatcherCore->dispatch - [line 28 - index.php]

Share this post


Link to post
Share on other sites

 

Hi,

 

worked fine until I updated to 1.6.1.8

 

After the upgrade i have this error:  (I think that is due to the module) :mellow:

 

Hello,

 

That is correct there was some codding issues with v1.0.0.

I had some spare time and cleaned up all the codding to the PSR-2 coding standard

 

Your issue should be solved now.

 

Kind regards!

Jaimy A

Share this post


Link to post
Share on other sites

He probado este módulo en prestashop 1.6.1.15 y me ha funcionado perfectamente. Muchas gracias.

 

Este módulo sirve para: 

Módulo gratis Activa-desactiva un producto cuando el stock cambia

 

(Lo dejo así escrito para que otras personas que hablen español puedan encontrar este módulo más fácilmente)  :)

 

Share this post


Link to post
Share on other sites

I have checked this module in Prestashop version 1.7.2 and is working prefectly.

Share this post


Link to post
Share on other sites

Hi - Is this able to disable products, if the category is disabled.

 

As I have products that are available only during specific dates. And I want to just disable a category, which then automatically disables all of its products.

Share this post


Link to post
Share on other sites

Module works great, But it doesn't take into consideration products that are set to allow ordering when out of stock (Pre-Order Items), Any idea what needs to be changed so it looks at the When out of Stock tick box is set to Allow Orders when out of stock?

Share this post


Link to post
Share on other sites

Hello, I have more than 1000 categories, my catalog connects to the stock of my supplier. I am interested in that the module automatically activate and disable the categories that are without stock (not without products). Does this module work?

Share this post


Link to post
Share on other sites

Hello, I have more than 1000 categories, my catalog connects to the stock of my supplier. I am interested in that the module automatically activate and disable the categories that are without stock (not without products). Does this module work?

 

I think it already works this way? or am i wrong?

Share this post


Link to post
Share on other sites

Module works great, But it doesn't take into consideration products that are set to allow ordering when out of stock (Pre-Order Items), Any idea what needs to be changed so it looks at the When out of Stock tick box is set to Allow Orders when out of stock?

 

You had a point there, i have added it to the new version 1.0.2

 

Kind regards,

Jaimy

Share this post


Link to post
Share on other sites

Please add an option to disable categories if all products there have zero quantities.

And another option if all products are disabled.

It will great if all options can work in any combination of them.

 

Share this post


Link to post
Share on other sites

Thanks, the Out of Stock ordering works great now, But it seems like the subcategory disabling/re-enabling isn't working,

The products within the Subcategory has been disabled by the module, But the Subcategory stays enabled.

 

Quote
On 10/10/2017 at 7:55 AM, Crezzur said:

 

You had a point there, i have added it to the new version 1.0.2

 

Kind regards,

Jaimy

 

 

Edited by Cuball
Adding quote (see edit history)

Share this post


Link to post
Share on other sites

Hello,

I have prestashop 1.7.2.4, the auto switch on/off of the category does not work.

There is any actualisaction?

Share this post


Link to post
Share on other sites
On 3/10/2016 at 8:49 AM, PrestaShark said:

Thanks! Much appreciated!

PS> New feature

In {$HOOK_HEADER} insert something like this


{if $page_name == 'product'}
			{if $product->active != 1}
				{foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat name=cats}
					{if $smarty.foreach.cats.last}
						{assign var="cat_url" value="{$link->getCategoryLink({$cat.id_category})}"}
					{/if}    
				{/foreach}
				<meta http-equiv="refresh" content="0; url={$cat_url}" />
			{/if}
		{/if}

to redirect disabled product to their parent category. For better user experience. Product not available but the traffic is not wasted :)

Best regards! :)

Hi there, Thanks so Much for your work on this module, working great for me!  Just a little question about the great feature you added in for 404 page redirects.. Would it be possible to auto redirect to the set default category opposed to just the parent. Many thanks!

Share this post


Link to post
Share on other sites

Hi,

On Prestashop 1.7.2.5 doesn't work and appaers this error:

" Notice en línea 152 en archivo C:\\xampp71\\htdocs\\presta1725\\modules\\dataswitchpro\\dataswitchpro.php
[8] Undefined variable: products_yes

Notice en línea 155 en archivo C:\\xampp71\\htdocs\\presta1725\\modules\\dataswitchpro\\dataswitchpro.php
[8] Undefined variable: categories_no"

The module is ready to work on this version?

Share this post


Link to post
Share on other sites

this can't bee good for the SEO , have that I mind. 

 

you will have a lot of 404 from google 

Share this post


Link to post
Share on other sites
On 6/9/2018 at 6:31 PM, Sergi said:

Hi,

On Prestashop 1.7.2.5 doesn't work and appaers this error:

" Notice en línea 152 en archivo C:\\xampp71\\htdocs\\presta1725\\modules\\dataswitchpro\\dataswitchpro.php
[8] Undefined variable: products_yes

Notice en línea 155 en archivo C:\\xampp71\\htdocs\\presta1725\\modules\\dataswitchpro\\dataswitchpro.php
[8] Undefined variable: categories_no"

The module is ready to work on this version?

We have added a new version which solve this issue.

Share this post


Link to post
Share on other sites

Bonjour merci pour le partage, petit souci après avoir désinstaller le module plus de produits sur la page d'accueil ? 

Edited by Soyons zen (see edit history)

Share this post


Link to post
Share on other sites

Hello thanks for sharing, small problem after uninstalling the module more products on the homepage?

Share this post


Link to post
Share on other sites
3 minutes ago, Soyons zen said:

Hello thanks for sharing, small problem after uninstalling the module more products on the homepage?

I am not sure which issue you have?

Share this post


Link to post
Share on other sites
14 hours ago, Crezzur said:

I am not sure which issue you have?

 

Hello, After uninstalling the module, the most sold products are no longer available on the home page

Edited by Soyons zen (see edit history)

Share this post


Link to post
Share on other sites

Hola, tengo PS v.1.7.5.1

Se instala bien pero NO funciona correctamente. a la hora de abrir un producto hace como una marcha atrás y te saca del producto. Es una lastima que no me funcione con mi versión ya que pensé que me funcionaria. 

Gracias

Share this post


Link to post
Share on other sites

it works but has a bug in front end this when i click to see a product it redirects to its categorie making impossible to see the product and for customer to buy the product

Share this post


Link to post
Share on other sites
13 minutes ago, mktm20111 said:

it works but has a bug in front end this when i click to see a product it redirects to its categorie making impossible to see the product and for customer to buy the product

Could you provide me a url where the issue happens?

Share this post


Link to post
Share on other sites

Hi mi friend @Crezzur

Appreciate your help to the community for free ❤️

Here is a quick fix I think that should be implemented in your module:

on the hookHeader() function, find this line:
 

Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product_shop as ps JOIN '._DB_PREFIX_.'stock_available
                as sa ON sa.quantity=0 AND out_of_stock!=1 AND id_product_attribute=0 SET active=0 WHERE ps.id_product=sa.id_product');

sa.quantity<0 should be changed to this sa.quantity<1 as following:

Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product_shop as ps JOIN '._DB_PREFIX_.'stock_available
                as sa ON sa.quantity<1 AND out_of_stock!=1 AND id_product_attribute=0 SET active=0 WHERE ps.id_product=sa.id_product');

Why? I looked at a thread guys were having problem with your module because sometimes their stock when to negative, or they already had negative products, and the behavior was the same as if there was no module.

I hope you understand me and take this in consideration.

Best regards

  • Thanks 1

Share this post


Link to post
Share on other sites
16 hours ago, PrestaMake said:

Hi mi friend @Crezzur

Appreciate your help to the community for free ❤️

Here is a quick fix I think that should be implemented in your module:

on the hookHeader() function, find this line:
 


Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product_shop as ps JOIN '._DB_PREFIX_.'stock_available
                as sa ON sa.quantity=0 AND out_of_stock!=1 AND id_product_attribute=0 SET active=0 WHERE ps.id_product=sa.id_product');

sa.quantity<0 should be changed to this sa.quantity<1 as following:


Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product_shop as ps JOIN '._DB_PREFIX_.'stock_available
                as sa ON sa.quantity<1 AND out_of_stock!=1 AND id_product_attribute=0 SET active=0 WHERE ps.id_product=sa.id_product');

Why? I looked at a thread guys were having problem with your module because sometimes their stock when to negative, or they already had negative products, and the behavior was the same as if there was no module.

I hope you understand me and take this in consideration.

Best regards

Thank you for your contribution!

The requested change is now available in version 1.0.4

Share this post


Link to post
Share on other sites
Posted (edited)
El 26/5/2019 a las 14:58, Crezzur dijo:

¡Gracias por tu contribución!

El cambio solicitado ya está disponible en la versión 1.0.4.

Muchas gracias a @Crezzur  ya @PrestaMake  por intentar ayudarnos en nuestro problema.

Supongamos que usted no ha notado que ahora, en cualquier producto que selecciones de la tienda se saca automáticamente a la categoría de lo que pertenece, no se deja permanecer en la página de producto, no se si me expliqué. gracias de nuevo

 

Edited by MarilóAmAtuMundo (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
On 5/28/2019 at 7:46 AM, MarilóAmAtuMundo said:

Muchas gracias a @Crezzur y a @PrestaMake por intentar ayudarnos en nuestro problema.

supongo que ya habréis notado que ahora, en cualquier producto que selecciones de la tienda te saca automáticamente a la categoría a la que pertenece, no te deja permanecer en la página de producto, no se si me explico. gracias de nuevo.

i had the same issue so deleted the module

Share this post


Link to post
Share on other sites
Posted (edited)
44 minutes ago, mktm20111 said:

i had the same issue so deleted the module

Another fix that should be implemented its to remove the footer hook @Crezzur

Here is the fixed version that solves that issue: dataswitchprov3.zip

Edited by PrestaMake (see edit history)

Share this post


Link to post
Share on other sites

Thanks you for the modules.

About :

"Update 16/05: we are considering adding a cronjob to this module (fires automatically every x time and disable and enable categories). For this we want feedback from the users to know if this update is needed."

I think that it would be a good improvement for people that sincronize DB automatically with diferent data sources or CRMs.

For us it will be perfect.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More