Jump to content

Update all categories with new customer groups


Danijelp

Recommended Posts

Hi all,
 
is it possible to include or adapt php code to show in back office.
I mean, I create controller and make Update button to menu of back office and want to include this code to show there

<?php
require(dirname(__FILE__).'/config/config.inc.php');
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$new_group = $_POST["new_group"];
$categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT c.*
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = '.(int)Context::getContext()->language->id.')
');


foreach($categories as $category){
$categoryObj = new Category($category['id_category'], (int)Context::getContext()->language->id);
$categoryObj->addGroups(array($new_group));
}
echo 'Updated';
}
else
{
echo'
<form method="post" action="'.$_SERVER["PHP_SELF"].'">
Enter New Group id: <input type="text" name="new_group">
<input type="submit" name="update" > 
</form>';
}
?>

thnx in advance

Link to comment
Share on other sites

Thnx Eric,

 

I tried but don't know how get this to work.  :unsure:

I tried in this way that create menu button in BO, make controller to call tpl file, but as I saw there is no possibility to include php functions in tpl file.

 

Do you have some working example or something else to help me?

 

thnx in advance

D.

Link to comment
Share on other sites

Hi Dani,

 

Did you have a look at the developers guide already? There is some example on how to make a module, and in there, they describe how to add some configuration page, where you add some input fields to modify, and a submit button. There you can see how they act on a submit as well.

 

On creating a module:

http://doc.prestashop.com/display/PS16/Creating+a+PrestaShop+Module

 

and a direct link for how to add the configuration page:

http://doc.prestashop.com/display/PS16/Adding+a+configuration+page

 

Hope this helps,

pascal.

Link to comment
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
×
×
  • Create New...