Jump to content

mass enable/disable products


mmleoni

Recommended Posts

Hi guys,  I'm new to ps, so have a mercy for me ;)

I worked for many years with joomla & virtuemart (or joomshopping); I think ps is great, but I really miss mass actions: especially enable/disable products and categories.

I took a look to the code, and I think it's quite simple to implement these functions, but I know that authors have a lot of work to do before than this one.

 

I needed to enable/disable a lot of products at same time, so I modified the code, of course I don't want to keep modified core code :(
Can you help me to check if the code is ok and if I can submit this code to be inserted into next official release?

bye,
marco
 

 

in: /controllers/admin/AdminProductsController.php (v 1.5.6.0)

 

replace line 65 with:

		$this->bulk_actions = array(
			'delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')),
			'enable' => array('text' => $this->l('Enable selected'), 'confirm' => $this->l('Enable selected items?')),
			'disable' => array('text' => $this->l('Disable selected'), 'confirm' => $this->l('Disable selected items?'))
		);

replace line 3476 with:

		$this->bulk_actions = array(
			'delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')),
			'enable' => array('text' => $this->l('Enable selected'), 'confirm' => $this->l('Enable selected items?')),
			'disable' => array('text' => $this->l('Disable selected'), 'confirm' => $this->l('Disable selected items?'))
		);

insert where ever you want:

	protected function processBulkEnable()
	{
		$this->doBulkEnable(true);
	}

	protected function processBulkDisable()
	{
		$this->doBulkEnable(false);
	}
	
	protected function doBulkEnable($status)
	{
		if ($this->tabAccess['edit'] === '1')
		{
			if (is_array($this->boxes) && !empty($this->boxes))
			{
				$products = Tools::getValue($this->table.'Box');
				if (is_array($products) && ($count = count($products)))
				{
					// I don't think (un)publish products can be quite long on a cheap server... anyway.
					if (intval(ini_get('max_execution_time')) < round($count * 1.5))
						ini_set('max_execution_time', round($count * 1.5));

					foreach ($products as $id_product)
					{
						$product = new Product((int)$id_product);
						$product->active = $status;
						$product->update();
					}
				}
			}
			else
				$this->errors[] = Tools::displayError('You must select at least one element to enable/disable.');
		}
		else
			$this->errors[] = Tools::displayError('You do not have permission to enable/disable this.');
	}
	

in the attachment the modified file
AdminProductsController.php

  • Like 2
Link to comment
Share on other sites

  • 2 months later...
  • 4 weeks later...
  • 1 year later...
  • 11 months later...

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...