- Posts: 193
- Thank you received: 76
All products are free after CSV import
11 years 10 months ago #179559
by korzo
All products are free after CSV import was created by korzo
-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.6
I have CSV file with columns product_code,product_quantity,price_value.
I used CSV import till now, but because of several problems I switched to Mass action with CSV products filter.
When this mass action was first triggered, all products have become free.
Cause of this issue is in plugins\hikashop\massaction_product\massaction_product.php on line 356.
As price_currency_id column is not in csv file, $data->elements[$id]->prices[$k]->price_currency_id is NULL and price is later in hikashopProductClass::updatePrices() saved to database with non existent id 0 in price_currency_id column.
I fixed it by populating $price_currency_id from $config->get('main_currency',1), but I suppose better place to fix this is in
hikashopProductClass::updatePrices().
Also I think it is unnecessary to query database 1000x for the same value and $price_currency should be cached.
-- Joomla version -- : 3.3.6
I have CSV file with columns product_code,product_quantity,price_value.
I used CSV import till now, but because of several problems I switched to Mass action with CSV products filter.
When this mass action was first triggered, all products have become free.
Cause of this issue is in plugins\hikashop\massaction_product\massaction_product.php on line 356.
As price_currency_id column is not in csv file, $data->elements[$id]->prices[$k]->price_currency_id is NULL and price is later in hikashopProductClass::updatePrices() saved to database with non existent id 0 in price_currency_id column.
I fixed it by populating $price_currency_id from $config->get('main_currency',1), but I suppose better place to fix this is in
hikashopProductClass::updatePrices().
Also I think it is unnecessary to query database 1000x for the same value and $price_currency should be cached.
Please Log in or Create an account to join the conversation.
11 years 10 months ago #179577
by Xavier
Replied by Xavier on topic All products are free after CSV import
Hi,
Thanks for the report.
Please try to replace the updatePrices() function in the product class by:
Thanks for the report.
Please try to replace the updatePrices() function in the product class by:
Code:
function updatePrices($element,$status){
$filters=array('price_product_id='.$status);
if(count($element->prices)){
$ids = array();
foreach($element->prices as $price){
if(!empty($price->price_id) && !empty($price->price_value)) $ids[] = $price->price_id;
}
if(!empty($ids)){
$filters[]= 'price_id NOT IN ('.implode(',',$ids).')';
}
}
$query = 'DELETE FROM '.hikashop_table('price').' WHERE '.implode(' AND ',$filters);
$this->database->setQuery($query);
$this->database->query();
if(count($element->prices)){
$insert = array();
foreach($element->prices as $price){
if((int)$price->price_currency_id == 0)
$price->price_currency_id = hikashop_getCurrency();
if(empty($price->price_value)) continue;
if(empty($price->price_id)) $price->price_id = 'NULL';
$line = '('.(int)$price->price_currency_id.','.$status.','.(int)$price->price_min_quantity.','.(float)$price->price_value.','.$price->price_id.','.$this->database->Quote(@$price->price_site_id);
if(hikashop_level(2)){
if(empty($price->price_access)){
$price->price_access = 'all';
}
$line.=','.$this->database->Quote($price->price_access);
}
$insert[]=$line.')';
}
if(!empty($insert)){
$select = 'price_currency_id,price_product_id,price_min_quantity,price_value,price_id,price_site_id';
if(hikashop_level(2)){
$select.=',price_access';
}
$query = 'REPLACE '.hikashop_table('price').' ('.$select.') VALUES '.implode(',',$insert).';';
$this->database->setQuery($query);
$this->database->query();
}
}
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.149 seconds