8mete8 Posted May 12, 2016 Share Posted May 12, 2016 (edited) Could you help me little with a cron job please. I managed to get a working cron php file for putting my shop to catalog mode but there is a little problem and i searched for weeks now nd could not find a sollution. I am runnig multistore on prestashop 1.6.5 and i would like to define specific shop ID in my cron php so it would put only one of my shops to catalog mode. I found a article where is a code for slecting a shop ID but does not work for. My php script look like this:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <?php //Create the connection $con = mysqli_connect("***********", "*************", "***************", "**************") or die("Some error occurred during connection ".mysqli_error($con)); // Write query $strSQL = "UPDATE `"._DB_PREFIX_."configuration` SET `value` = 1 where `name` = 'PS_CATALOG_MODE';"; // Execute the query. $query = mysqli_query($con, $strSQL); while ($result = mysqli_fetch_array($query)) { echo (string)$result["************"]; } // Close the connection mysqli_close($con); --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------This code is working fine but it is putting all shops to catalog mode. This is a code witch i found in older forum:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <?php // placed in /override/classes/Configuration.php class Configuration extends ConfigurationCore { public static function get($key, $id_lang = null, $id_shop_group = null, $id_shop = null) { if (defined('_PS_DO_NOT_LOAD_CONFIGURATION_') && _PS_DO_NOT_LOAD_CONFIGURATION_) { return false; } // If conf if not initialized, try manual query if (!isset(self::$_cache[self::$definition['table']])) { Configuration::loadConfiguration(); if (!self::$_cache[self::$definition['table']]) { return Db::getInstance()->getValue('SELECT `value` FROM `'._DB_PREFIX_.bqSQL(self::$definition['table']).'` WHERE `name` = "'.pSQL($key).'"'); } } $id_lang = (int)$id_lang; if ($id_shop === null || !Shop::isFeatureActive()) { $id_shop = Shop::getContextShopID(true); } if ($id_shop_group === null || !Shop::isFeatureActive()) { $id_shop_group = Shop::getContextShopGroupID(true); } if (!isset(self::$_cache[self::$definition['table']][$id_lang])) { $id_lang = 0; } if ($id_shop && Configuration::hasKey($key, $id_lang, null, $id_shop)) { if($key == 'PS_CATALOG_MODE') // Add your time condition { return !Context::getContext()->customer->isLogged() || self::$_cache[self::$definition['table']][$id_lang]['shop'][$id_shop][$key]; } else { return self::$_cache[self::$definition['table']][$id_lang]['shop'][$id_shop][$key]; } } elseif ($id_shop_group && Configuration::hasKey($key, $id_lang, $id_shop_group)) { if($key == 'PS_CATALOG_MODE') // Add your time condition { return !Context::getContext()->customer->isLogged() || self::$_cache[self::$definition['table']][$id_lang]['group'][$id_shop_group][$key]; } else { return self::$_cache[self::$definition['table']][$id_lang]['group'][$id_shop_group][$key]; } } elseif (Configuration::hasKey($key, $id_lang)) { if($key == 'PS_CATALOG_MODE') // Add your time condition { return !Context::getContext()->customer->isLogged() || self::$_cache[self::$definition['table']][$id_lang]['global'][$key]; } else { return self::$_cache[self::$definition['table']][$id_lang]['global'][$key]; } } return false; } } ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------I was trying to copy the line with shop_id to my php file but it gives me arrors and wont work.Could anyone help me to implemet the shop selection code from the above script to my php file? Edited May 21, 2016 by mdekker Formatted the code for ya, to make it readable. (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted May 16, 2016 Share Posted May 16, 2016 The Configuration class provide method for you yo update, why you need to write your own SQL? have you tried following method? Configuration::updateValue("PS_CATALOG_MODE", 0 , false, null, $id_shop); 1 Link to comment Share on other sites More sharing options...
8mete8 Posted May 16, 2016 Author Share Posted May 16, 2016 I tried this but no luck. <?phpinclude(dirname(__FILE__).'/config/config.inc.php');include(dirname(__FILE__).'/init.php');if (!Configuration::get('PS_CATALOG_MODE')) { Configuration::updateValue("PS_CATALOG_MODE", 1 , false, null, $id_shop = 2);} else { Configuration::updateValue("PS_CATALOG_MODE", 0 , false, null, $id_shop = 2);}?> WHAT DO YOU THINK? Link to comment Share on other sites More sharing options...
8mete8 Posted May 16, 2016 Author Share Posted May 16, 2016 Sorry it is working but i am too fast with refreshing the page at least it looks like it. Will test it further and come back. Thanks a lot. :-) Link to comment Share on other sites More sharing options...
8mete8 Posted May 16, 2016 Author Share Posted May 16, 2016 Yes its definitely working. Thanks a million. Link to comment Share on other sites More sharing options...
shokinro Posted May 17, 2016 Share Posted May 17, 2016 Please try this $id_shop = 2; if (!Configuration::get('PS_CATALOG_MODE', null, null, $id_shop)) { Configuration::updateValue("PS_CATALOG_MODE", 1 , false, null, $id_shop); } else { Configuration::updateValue("PS_CATALOG_MODE", 0 , false, null, $id_shop); } 1 Link to comment Share on other sites More sharing options...
8mete8 Posted May 17, 2016 Author Share Posted May 17, 2016 Even better its working well. One more question. There is some problem but i dont know what exactly because the script is working 100% when executed manualy, but when i set a cron task for it nothing is happening and i tried my server cron and prestashop build in cron tab and cron module from samdbha and non of them is running the script. So the question is does the script php file need some extra lines or something? Link to comment Share on other sites More sharing options...
shokinro Posted May 18, 2016 Share Posted May 18, 2016 if it is always changes for shop with ID =2, then it should be fine. otherwise, you will need to get correct shop ID. make sure your cron job is set and running correctly Link to comment Share on other sites More sharing options...
8mete8 Posted May 19, 2016 Author Share Posted May 19, 2016 Well i contacted my hosting provider and they will check the cron functionality and let me know. Thank for help. Link to comment Share on other sites More sharing options...
shokinro Posted May 19, 2016 Share Posted May 19, 2016 good to to know, hope they will help you solve the problem. Link to comment Share on other sites More sharing options...
8mete8 Posted May 19, 2016 Author Share Posted May 19, 2016 Allright the final words. The script is working perfect. in prestashop i am using GEO IP RESTRICTION and this was causing the problem with executing the cron task witch could not reach the prestashop. The sollution is to allow Geolocation behavior for other countries and add my hosting server ip to whitelist and localhost ip is well 127.0.0.1. Now its flying like it should. Thanks a lot and hope that this will help some other people. Link to comment Share on other sites More sharing options...
shokinro Posted May 20, 2016 Share Posted May 20, 2016 that's great you have got a solution and thanks for sharing. Link to comment Share on other sites More sharing options...
ubv Posted May 25, 2016 Share Posted May 25, 2016 Hi, does anyone know if this works for the cloud version of Prestashop too? Or if not, is there a way of using multistore with one of the stores in catalog mode and others in selling mode? If anyone has an Idea, I'd be very grateful! Thank you! Link to comment Share on other sites More sharing options...
8mete8 Posted May 25, 2016 Author Share Posted May 25, 2016 Hi. I am not sure about prestashop cloud but if you are looking to use one shop permanently in catalog mode just select your shop and then put it to catalog mode via admin panel settings then product an tick the small square beside catalog mode an set the catalog mode to yes.The other shops remain active. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now