Jump to content

Anyone knows how to make this cron?


Recommended Posts

Hello,

 

I want to do a cron to my prestashop, I think that is very simple but I havo no idea how to do it.

 

I want to make a specific cron that can programe it and every day for example at 00:00 am it changes the url of the items of the menu to another specific url.

 

I want this because i want to change te products to show every day. Anyone have any idea how to do it?

 

For the menu I use the default module that comes with prestashop.

 

Thanks a lot!

Link to comment
Share on other sites

Prestashop version? WHy not using the very same cron module? That, given that you already have such script, cron-ing it is the last step. Or were you asking how to make such script?

Thanks for your answer! I use the last version of prestashop (1.6.9). I have no idea of how to do the scrip because i do not knoe anything of php..

 

Thanks.

Edited by Guixe94 (see edit history)
Link to comment
Share on other sites

To clarify you are asking 2 things

 

1) You want a script that will change one or more of the top menu links.

2) You want a cronjob created that will execute the script in #1 once per day

 

Creating a cronjob that will execute at midnight each day is the easy part. 

 

Creating a script that will change the menu links is not 'easy'.  How will the script know what URL to change, and what to change it to?

 

Are you looking for someone to provide this to you for free, or are you searching for a freelancer to provide you with an estimate?

Link to comment
Share on other sites

To clarify you are asking 2 things

 

1) You want a script that will change one or more of the top menu links.

2) You want a cronjob created that will execute the script in #1 once per day

 

Creating a cronjob that will execute at midnight each day is the easy part. 

 

Creating a script that will change the menu links is not 'easy'.  How will the script know what URL to change, and what to change it to?

 

Are you looking for someone to provide this to you for free, or are you searching for a freelancer to provide you with an estimate?

 

Thanks for your answer, the cronjob i think i can do it searching on google i found some things. I need the scrip, In the menu module, you can add links for example with the name "Computers" and a specific url. I don't know if this url are stored in any place where you can after replace it or not..

 

I know that anyone de thing for free (normally), so if anyone knows ow to do it o any module that do this I will pay for it. (depending the price..)

 

Thanks!

 

(sorry for mi bad english..)

Link to comment
Share on other sites

the top menu links are stored in the database, in tables named ps_linkmenutop and ps_linksmenutop_lang

The URL is contained in the table ps_linksmenutop_lang, in a column called 'link', and the menu name in the column called 'label'

 

So if you will pre-create this menu item, and then each day just change the value of the link, it should be fairly straight forward SQL command.  There are 2 issues however

 

1) What will you change the link to each day?  You have not defined your requirements or expectations.

2) While these links are stored in the database, Prestashop utilizes a caching mechanism for the menu, so your script would also need to clear the cache (similar to you clicking on the clear cache button in the back office).

Link to comment
Share on other sites

the top menu links are stored in the database, in tables named ps_linkmenutop and ps_linksmenutop_lang

The URL is contained in the table ps_linksmenutop_lang, in a column called 'link', and the menu name in the column called 'label'

 

So if you will pre-create this menu item, and then each day just change the value of the link, it should be fairly straight forward SQL command.  There are 2 issues however

 

1) What will you change the link to each day?  You have not defined your requirements or expectations.

2) While these links are stored in the database, Prestashop utilizes a caching mechanism for the menu, so your script would also need to clear the cache (similar to you clicking on the clear cache button in the back office).

 

 

Hello,

 

Yes I just saw that is stored in the database. So i need a script that connect to the database, change the values of the links and clear the cache. The problem is that i havo no idea of php or scripts..

 

I want to do that because the items of my menu are the categories. For example: Tech, Gadgets, etc. But I only want to sell one product each day. So i want to change the url of the menu items to redirect directly to the product that i want to sell this day. For example:

Menu day 1:

 

Tech goes to: http://myshop.com/produc1

Gadgets goes to: http://myshop.com/product11

 

Menu day 2:

 

Tech goes to: http://myshop.com/produc2

Gadgets goes to: http://myshop.com/product22

 

 

Thanks!

Link to comment
Share on other sites

For the moment yes I want to star only two elements.

About the days I want to make 7 copies of the script (one for monday, thuesday, etc) and update the links of the script every week. Every scrip will have a cronjob asigned to run it on the specific day.

 

It's dificult to do that?

 

Thanks.

Link to comment
Share on other sites

this should get you started.  just copy this script 7 times and update the id and link values accordingly

<?php

require(dirname(__FILE__).'/config/config.inc.php');

//to use this script, first create your two menu items using the "Top horizontal menu" module configuration page.
//then open your phpmyadmin, browse the `ps_linksmenutop_lang` table, and locate the `id_linksmenutop` for each menu item
//take note of the `id_linksmenutop` value and update the id and link below accordingly

//place this script in the root of your store and execute it from the browser to ensure it is working properly
//you can also run this from a cronjob

//this is the first menu item.  update the id and link accordingly
$menuitem1_id = 1;
$menuitem1_link = 'http://myshop.com/produc1';

//this is the second menu item.  update the id and link accordingly
$menuitem2_id = 2;
$menuitem2_link = 'http://myshop.com/produc2';



//you should not have to touch the code below
$sql1 = "UPDATE `ps_linksmenutop_lang` SET `link` = '$menuitem1_link' WHERE `ps_linksmenutop_lang`.`id_linksmenutop` = $menuitem1_id";
$sql2 = "UPDATE `ps_linksmenutop_lang` SET `link` = '$menuitem2_link' WHERE `ps_linksmenutop_lang`.`id_linksmenutop` = $menuitem2_id";

Db::getInstance()->execute($sql1);
Db::getInstance()->execute($sql2);

//clear the cache
Tools::enableCache();
Tools::clearCache(Context::getContext()->smarty, getTemplatePath('blocktopmenu.tpl'), null, null);
Tools::restoreCacheSettings();





function getTemplatePath($template)
{
    $overloaded = _isTemplateOverloaded('blocktopmenu', $template);
    if ($overloaded === null)
        return null;
    
    if ($overloaded)
        return $overloaded;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/views/templates/hook/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/views/templates/hook/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/views/templates/front/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/views/templates/front/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/'.$template;
    else
        return null;
}

function _isTemplateOverloaded($module_name, $template)
{
    if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/'.$template;
    elseif (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/hook/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/hook/'.$template;
    elseif (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/front/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/front/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/views/templates/hook/'.$template))
        return false;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/views/templates/front/'.$template))
        return false;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/'.$template))
        return false;
    return null;
}

 

  • Like 1
Link to comment
Share on other sites

 

this should get you started.  just copy this script 7 times and update the id and link values accordingly

<?php

require(dirname(__FILE__).'/config/config.inc.php');

//to use this script, first create your two menu items using the "Top horizontal menu" module configuration page.
//then open your phpmyadmin, browse the `ps_linksmenutop_lang` table, and locate the `id_linksmenutop` for each menu item
//take note of the `id_linksmenutop` value and update the id and link below accordingly

//place this script in the root of your store and execute it from the browser to ensure it is working properly
//you can also run this from a cronjob

//this is the first menu item.  update the id and link accordingly
$menuitem1_id = 1;
$menuitem1_link = 'http://myshop.com/produc1';

//this is the second menu item.  update the id and link accordingly
$menuitem2_id = 2;
$menuitem2_link = 'http://myshop.com/produc2';



//you should not have to touch the code below
$sql1 = "UPDATE `ps_linksmenutop_lang` SET `link` = '$menuitem1_link' WHERE `ps_linksmenutop_lang`.`id_linksmenutop` = $menuitem1_id";
$sql2 = "UPDATE `ps_linksmenutop_lang` SET `link` = '$menuitem2_link' WHERE `ps_linksmenutop_lang`.`id_linksmenutop` = $menuitem2_id";

Db::getInstance()->execute($sql1);
Db::getInstance()->execute($sql2);

//clear the cache
Tools::enableCache();
Tools::clearCache(Context::getContext()->smarty, getTemplatePath('blocktopmenu.tpl'), null, null);
Tools::restoreCacheSettings();





function getTemplatePath($template)
{
    $overloaded = _isTemplateOverloaded('blocktopmenu', $template);
    if ($overloaded === null)
        return null;
    
    if ($overloaded)
        return $overloaded;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/views/templates/hook/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/views/templates/hook/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/views/templates/front/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/views/templates/front/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$this->name.'/'.$template))
        return _PS_MODULE_DIR_.$this->name.'/'.$template;
    else
        return null;
}

function _isTemplateOverloaded($module_name, $template)
{
    if (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/'.$template;
    elseif (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/hook/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/hook/'.$template;
    elseif (Tools::file_exists_cache(_PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/front/'.$template))
        return _PS_THEME_DIR_.'modules/'.$module_name.'/views/templates/front/'.$template;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/views/templates/hook/'.$template))
        return false;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/views/templates/front/'.$template))
        return false;
    elseif (Tools::file_exists_cache(_PS_MODULE_DIR_.$module_name.'/'.$template))
        return false;
    return null;
}

 

Thanks a lot! It works like I want!

Link to comment
Share on other sites

×
×
  • Create New...