Change price of all products by percentage?

  • Posts: 76
  • Thank you received: 2
11 years 3 months ago #119188

Hi,

Hopefully just a quick question...

Can you use mass action, or some other tool, to change the price of all your hikashop products at once? Would be good to change large selections of products by a given percentage to account for inflation each year...

Best wishes,

Jonathan

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
11 years 3 months ago #119220

Hi,

Yes you can and it is one of the goals of the mass action system.
www.hikashop.com/support/documentation/167-massaction-form.html

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 76
  • Thank you received: 2
11 years 3 months ago #119525

Hi,

Thanks for this. Could you give a bit more detail, as I have read the documentation and failed to make it work.

Say I want to create a mass action that halfs all prices on the site (extreme I know, but just for example):
-I set data to "product"
-I don't apply a trigger as I only want it to happen when admin says "process".
-I don't apply a filter as I want it to happen on all products.
-I set the action to "update the values" with "product_price_percentage" = "int" "50"

When I say "process", nothing happens to the prices... What am I doing wrong?

Many thanks,
Jonathan

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 3 months ago #119626

Hi,

In the action you have to set "update the values" "price_value" = "operation" "price.price_value*0.5"

0.5 to half all the prices on the site, you can change this value to make another operation

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 1 month ago #128305

Hi Xavier,

This doesn't seem to work for me, please see attached. I have tried modifying your code to see if i need to add the prefix for the table to it as i know this is randomly generated by Joomla, either way i get errors. Has the name of something changed in more recent version Hikashop?

Thanks

Alex

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #128486

Hi,

Thanks for the report.
I have corrected the problem.
Thanks to edit the file "plugins\hikashop\massaction_product\massaction_product.php" and in the function "onProcessProductMassActionupdateValues()" replace:

			if(!in_array($alias[0],array('product,price'))){
				$hk = 'product';
			}else{
				$hk = $alias[0];
			}
By:
			if(!in_array($alias[0],array('product','price'))){
				$hk = 'product';
			}else{
				$hk = $alias[0];
			}

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 3 weeks ago #129836

Hi Xavier,

Sorry for the slow reply i have been away. I tried your fix however i still get this error (attached).

Any ideas?

Thanks

Alex

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 3 weeks ago #129845

Hi,

In the MySQL query the id are duplicated, they shouldn't.
I am not able to reproduce that bug on my end, but some fixes have been made recently, thanks to replace the current function by this content:

	function onProcessProductMassActionupdateValues(&$elements,&$action,$k){
		$current = 'product';
		$current_id = $current.'_id';
		$ids = array();
		foreach($elements as $element){
			$ids[] = $element->$current_id;
			if(isset($element->$action['type']))
				$element->$action['type'] = $action['value'];

		}

		$action['type'] = strip_tags($action['type']);
		$alias = explode('_',$action['type']);
		$queryTables = array($current);
		$possibleTables = array($current, 'price');

		$value = $this->massaction->updateValuesSecure($action,$possibleTables,$queryTables);

		if(!empty($queryTables)){
			$query = 'UPDATE '.hikashop_table($current).' AS hk_'.$current.' ';
			$queryTables = array_unique($queryTables);
			foreach($queryTables as $queryTable){
				switch($queryTable){
					case 'price':
					case 'hk_price':
						$query .= 'LEFT JOIN '.hikashop_table('price').' AS hk_price ON hk_price.price_product_id = hk_product.product_id ';
						break;
				}
			}
			if(!in_array($alias[0],array('product','price'))){
				$hk = 'product';
			}else{
				$hk = $alias[0];
			}
			$db = JFactory::getDBO();
			JArrayHelper::toInteger($ids);

			$max = 5;
			if(count($ids) > $max){
				$c = ceil((int)count($ids) / $max);
				for($i = 0; $i < $c; $i++){
					$offset = $max * $i;
					$id = array_slice($ids, $offset, $max);
					$query .= 'SET hk_'.$hk.'.'.$action['type'].' = '.$value.' ';
					$query .= 'WHERE hk_'.$current.'.'.$current.'_id IN ('.implode(',',$id).')';
					$db->setQuery($query);
					//$db->query();
					var_dump($id);
				}
			}else{
				$query .= 'SET hk_'.$hk.'.'.$action['type'].' = '.$value.' ';
				$query .= 'WHERE hk_'.$current.'.'.$current.'_id IN ('.implode(',',$ids).')';
				$db->setQuery($query);
				$db->query();
			}
			// If the product hasn't any price
			if($hk == 'price'){
				$db->setQuery('SELECT price_product_id FROM '.hikashop_table('price').' WHERE `price_product_id` IN ('.implode(',',$ids).')');
				$existingIds = $db->loadObjectList();
				foreach($existingIds as $k => $existingId){
					$existingIds[$k] = $existingId->price_product_id;
				}
				if(count($existingIds) < count($ids)){
					if(!is_array($existingIds)) $existingIds = array($existingIds);
					$missingInsert = array_diff($ids,$existingIds);
					if(!empty($missingInsert)){
						$values = array();
						foreach($missingInsert as $id){
							$data = new stdClass();
							$data->price_currency_id = hikashop_getCurrency();
							$data->price_product_id = $id;
							$data->price_value = 0;
							$data->price_min_quantity = 0;
							$data->price_access = 'all';
							$data->$action['type'] = $action['value'];
							$values[] = (int)$data->price_currency_id.','.(int)$data->price_product_id.','.(float)$data->price_value.','.(int)$data->price_min_quantity.','.$db->quote($data->price_access);
						}
						$query = 'INSERT INTO '.hikashop_table('price').' (price_currency_id,price_product_id,price_value,price_min_quantity,price_access) VALUES ('.implode('),(',$values).')';
						$db->setQuery($query);
						$db->query();
					}
				}
			}
		}
	}

If that doesn't work, I will need a FTP + backend access to debug.

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 3 weeks ago #130249

Hi Xavier,

Did you get my pm a couple of days ago?

Kind regards

Alex

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 3 weeks ago #130250

Oh i see you had FTP issues i will send info over now.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 3 weeks ago #130259

Problem solved, thanks for the report, we correct that bug on our end.

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 3 weeks ago #130294

Great, works like a charm!

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 3 days ago #133016

Hi Xavier,

I updated hikashop the get the new email templates you added however this is now broken again was this bug not fixed in one of the hotfixes?

Kind regards

Alex

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 2 days ago #133216

Hi,

We don't made new release since this fix, so that couldn't be in the package.
The email feature is in the 2.2.2 since the 28 September. ;)

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 2 days ago #133231

Ah my mistake, please can you tell me the name of the file you uploaded via ftp for this fix so that i can retrieve it from my backups?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 2 days ago #133233

The file is massaction_product.php in the hikashop_massaction_product plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 0
11 years 2 days ago #133238

Please help, can`t change price for all product. Look screenshots. I don`t have any error, but price not change. This mass actions work with dispay, but don`t work with change price.

Attachments:
Last edit: 11 years 2 days ago by mishgan2004.

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 2 days ago #133272

Hi Xavier,

Was this file in a different location before this as i asked the host and they say they cannot see the file be fore the date 17/11/13 and i have a 14 day backup on my server? Was it in another hikashop directory?

Thanks

Alex

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 2 days ago #133308

Hi,

@mishgan2004:
Thanks to enable the debug mode and set the error reporting level to maximum.
This should display possible errors. But I think that it's the same issue than the one encountered by Dibben.
So the fix will be in the next release.

@Dibben & @mishgan2004:
As I can remember, to fix that issue you have to replace the function "onProcessProductMassActionupdateValues" by:

function onProcessProductMassActionupdateValues(&$elements,&$action,$k){
		$current = 'product';
		$current_id = $current.'_id';
		$ids = array();
		foreach($elements as $element){
			$ids[] = $element->$current_id;
			if(isset($element->$action['type']))
				$element->$action['type'] = $action['value'];

		}

		$action['type'] = strip_tags($action['type']);
		$alias = explode('_',$action['type']);
		$queryTables = array($current);
		$possibleTables = array($current, 'price');

		$value = $this->massaction->updateValuesSecure($action,$possibleTables,$queryTables);

		if(!empty($queryTables)){
			$query = 'UPDATE '.hikashop_table($current).' AS hk_'.$current.' ';
			$queryTables = array_unique($queryTables);
			foreach($queryTables as $queryTable){
				switch($queryTable){
					case 'price':
					case 'hk_price':
						$query .= 'LEFT JOIN '.hikashop_table('price').' AS hk_price ON hk_price.price_product_id = hk_product.product_id ';
						break;
				}
			}
			if(!in_array($alias[0],array('product','price'))){
				$hk = 'product';
			}else{
				$hk = $alias[0];
			}
			$db = JFactory::getDBO();
			JArrayHelper::toInteger($ids);

			$max = 500;
			if(count($ids) > $max){
				$c = ceil((int)count($ids) / $max);
				$mainQuery = $query;
				for($i = 0; $i < $c; $i++){
					$offset = $max * $i;
					$id = array_slice($ids, $offset, $max);
					$query = $mainQuery.' SET hk_'.$hk.'.'.$action['type'].' = '.$value.' ';
					$query .= 'WHERE hk_'.$current.'.'.$current.'_id IN ('.implode(',',$id).')';
					$db->setQuery($query);
					$db->query();
				}
			}else{
				$query .= 'SET hk_'.$hk.'.'.$action['type'].' = '.$value.' ';
				$query .= 'WHERE hk_'.$current.'.'.$current.'_id IN ('.implode(',',$ids).')';
				$db->setQuery($query);
				$db->query();
			}
			// If the product hasn't any price
			if($hk == 'price'){
				$db->setQuery('SELECT price_product_id FROM '.hikashop_table('price').' WHERE `price_product_id` IN ('.implode(',',$ids).')');
				$existingIds = $db->loadObjectList();
				foreach($existingIds as $k => $existingId){
					$existingIds[$k] = $existingId->price_product_id;
				}
				if(count($existingIds) < count($ids)){
					if(!is_array($existingIds)) $existingIds = array($existingIds);
					$missingInsert = array_diff($ids,$existingIds);
					if(!empty($missingInsert)){
						$values = array();
						foreach($missingInsert as $id){
							$data = new stdClass();
							$data->price_currency_id = hikashop_getCurrency();
							$data->price_product_id = $id;
							$data->price_value = 0;
							$data->price_min_quantity = 0;
							$data->price_access = 'all';
							$data->$action['type'] = $action['value'];
							$values[] = (int)$data->price_currency_id.','.(int)$data->price_product_id.','.(float)$data->price_value.','.(int)$data->price_min_quantity.','.$db->quote($data->price_access);
						}
						$query = 'INSERT INTO '.hikashop_table('price').' (price_currency_id,price_product_id,price_value,price_min_quantity,price_access) VALUES ('.implode('),(',$values).')';
						$db->setQuery($query);
						$db->query();
					}
				}
			}
		}
	}
in the file: "plugins\hikashop\massaction_product\massaction_product.php"

Please Log in or Create an account to join the conversation.

  • Posts: 377
  • Thank you received: 7
11 years 1 day ago #133552

Hi Xavier,

It seems to work ok now for products with a vlue of £0.00 but the mass price % increase doesn't work.. Any ideas?

Thanks

Alex

Please Log in or Create an account to join the conversation.

Time to create page: 0.084 seconds
Powered by Kunena Forum