- Posts: 44
- Thank you received: 1
Removal of Options using CSV import
14 years 4 months ago #49915
by PhilP
Removal of Options using CSV import was created by PhilP
Hi,
I am updating our site with new versions of products from our main supplier. Around 50 of the updated products no longer have options available so I should like to delete those options.
Is there a way to do this using a CSV file import? I have tried a couple of ways but neither seem to work.
Appreciate if you can let me know.
These are the two ways I tried so far, but neither was successful:
product_name,product_code,options
Test Product,TD_1039905,0
product_name,product_code,options
Test Product,TD_1039905,,
Regards
PhilP
I am updating our site with new versions of products from our main supplier. Around 50 of the updated products no longer have options available so I should like to delete those options.
Is there a way to do this using a CSV file import? I have tried a couple of ways but neither seem to work.
Appreciate if you can let me know.
These are the two ways I tried so far, but neither was successful:
product_name,product_code,options
Test Product,TD_1039905,0
product_name,product_code,options
Test Product,TD_1039905,,
Regards
PhilP
Please Log in or Create an account to join the conversation.
14 years 4 months ago #50005
by nicolas
Replied by nicolas on topic Re: Removal of Options using CSV import
Hi,
The CSV import system does not handle removing the completely the options of products with the current release.
Try to change the code:
to:
in the file administrator/components/com_hikashop/helpers/import.php and that should allow that.
The CSV import system does not handle removing the completely the options of products with the current release.
Try to change the code:
Code:
function _insertRelated(&$products,$type='related'){
$values = array();
$totalValid=0;
$insert = 'INSERT IGNORE INTO '.hikashop_table('product_related').' (`product_related_id`,`product_related_type`,`product_id`) VALUES (';
$ids=array();
foreach($products as $product){
if(empty($product->$type) && empty($product->hikashop_update)){
//copy files from template if any
if(!empty($this->template->$type)){
foreach($this->template->$type as $id){
$value = array((int)$id,$this->db->Quote($type),$product->product_id);
$values[] = implode(',',$value);
$totalValid++;
if( $totalValid%$this->perBatch == 0){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
}
}
}elseif(!empty($product->$type)){
$ids[] = (int)$product->product_id;
foreach($product->$type as $k => $id){
$id = $this->_getRelated($id);
$product->{$type}[$k] = $id;
$value = array((int)$id,$this->db->Quote($type),$product->product_id);
$values[] = implode(',',$value);
$totalValid++;
if( $totalValid%$this->perBatch == 0){
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).')');
$this->db->query();
$ids=array();
}
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
}
}
}
if(!empty($values)){
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).')');
$this->db->query();
}
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
}
}
Code:
function _insertRelated(&$products,$type='related'){
$values = array();
$totalValid=0;
$insert = 'INSERT IGNORE INTO '.hikashop_table('product_related').' (`product_related_id`,`product_related_type`,`product_id`) VALUES (';
$ids=array();
foreach($products as $product){
if(!isset($product->$type) && empty($product->hikashop_update)){
//copy files from template if any
if(!empty($this->template->$type)){
foreach($this->template->$type as $id){
$value = array((int)$id,$this->db->Quote($type),$product->product_id);
$values[] = implode(',',$value);
$totalValid++;
if( $totalValid%$this->perBatch == 0){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
}
}
}elseif(isset($product->$type)){
$ids[] = (int)$product->product_id;
foreach($product->$type as $k => $id){
if(!empty($id)){
$id = $this->_getRelated($id);
$product->{$type}[$k] = $id;
$value = array((int)$id,$this->db->Quote($type),$product->product_id);
$values[] = implode(',',$value);
$totalValid++;
}
if( $totalValid%$this->perBatch == 0){
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).')');
$this->db->query();
$ids=array();
}
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
}
}
}
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).')');
$this->db->query();
}
if(!empty($values)){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
}
}
Please Log in or Create an account to join the conversation.
14 years 4 months ago #51046
by PhilP
Replied by PhilP on topic Re: Removal of Options using CSV import
Hi Nicolas,
Thanks for the reply - definitely one for our technical guys I think!
Regards
PhilP
Thanks for the reply - definitely one for our technical guys I think!
Regards
PhilP
Please Log in or Create an account to join the conversation.
Time to create page: 0.168 seconds