- Posts: 69
- Thank you received: 1
Order of Related Products not kept during import
- dkmetz@taylorbruce.com
-
Topic Author
- Offline
Less
More
11 years 2 months ago #209477
by dkmetz@taylorbruce.com
______________
Dennis Kmetz
-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.5.25
Hi,
I am updating products, adding related products to each of my products. I would like the related products to show in the order that I enter them... can this be done?
Here is my import:
product_id related
1380 104,106,113,103AF,106AF,118AF,119AF
Related Module settings:
prntscr.com/7wkkca
Order observed (after the import):
prntscr.com/7wknlt
103AF,106AF,118AF,119AF,104,106,113
Order desired:
104,106,113,103AF,106AF,118AF,119AF
Dennis
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.5.25
Hi,
I am updating products, adding related products to each of my products. I would like the related products to show in the order that I enter them... can this be done?
Here is my import:
product_id related
1380 104,106,113,103AF,106AF,118AF,119AF
Related Module settings:
prntscr.com/7wkkca
Order observed (after the import):
prntscr.com/7wknlt
103AF,106AF,118AF,119AF,104,106,113
Order desired:
104,106,113,103AF,106AF,118AF,119AF
Dennis
______________
Dennis Kmetz
Please Log in or Create an account to join the conversation.
11 years 2 months ago #209496
by nicolas
Replied by nicolas on topic Order of Related Products not kept during import
Hi,
The ordering of the related products is indeed not handled by the CSV import.
It can be added quite easily I think.
Change the code:
to:
in the file administrator/components/com_hikashop/helpers/import.php and that should allow the import to support it.
The ordering of the related products is indeed not handled by the CSV import.
It can be added quite easily I think.
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(!isset($product->$type) && empty($product->hikashop_update)){
//copy files from template if any
if(@$product->product_type!='variant' && !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 && $totalValid%$this->perBatch == 0){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
}
}
}elseif(isset($product->$type)&&is_array($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 && $totalValid%$this->perBatch == 0){
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this->db->Quote($type));
$this->db->query();
$ids=array();
}
if(!empty($id)){
$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).') AND product_related_type='.$this->db->Quote($type));
$this->db->query();
}
if(count($values)){
$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`,`product_related_ordering`) VALUES (';
$ids=array();
foreach($products as $product){
if(!isset($product->$type) && empty($product->hikashop_update)){
//copy files from template if any
if(@$product->product_type!='variant' && !empty($this->template->$type)){
$i = 0;
foreach($this->template->$type as $id){
$value = array((int)$id,$this->db->Quote($type),$product->product_id,$i);
$values[] = implode(',',$value);
$totalValid++;
if( $totalValid && $totalValid%$this->perBatch == 0){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
$totalValid=0;
$values=array();
}
$i++;
}
}
}elseif(isset($product->$type)&&is_array($product->$type)){
$ids[] = (int)$product->product_id;
$i = 0;
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,$i);
$values[] = implode(',',$value);
$totalValid++;
}
if( $totalValid && $totalValid%$this->perBatch == 0){
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this->db->Quote($type));
$this->db->query();
$ids=array();
}
if(!empty($id)){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
}
$totalValid=0;
$values=array();
}
$i++;
}
}
}
if(!empty($ids)){
$this->db->setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this->db->Quote($type));
$this->db->query();
}
if(count($values)){
$this->db->setQuery($insert.implode('),(',$values).')');
$this->db->query();
}
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.146 seconds