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();
}
}
}
}
}