[Skip to main content](#vessel-content)

#   Order of Related Products not kept during import

##

- **[dkmetz@taylorbruce.com](/forum/user/11254-dkmetz-taylorbruce-com "View dkmetz@taylorbruce.com's Profile")**
- [![dkmetz@taylorbruce.com's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/11254-dkmetz-taylorbruce-com "View dkmetz@taylorbruce.com's Profile") Topic Author
- [ Offline](/forum/user/11254-dkmetz-taylorbruce-com)

Less More

- Posts: 69
- Thank you received: 1
-
-
-
-

11 years 4 months ago [\#209477](#209477) by [dkmetz@taylorbruce.com](/forum/user/11254-dkmetz-taylorbruce-com "View dkmetz@taylorbruce.com's Profile")  *[Order of Related Products not kept during import](/forum/37-import-export-csv-xls/878376-order-of-related-products-not-kept-during-import#209477 "-- 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&#95;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")* was created by *[dkmetz@taylorbruce.com](/forum/user/11254-dkmetz-taylorbruce-com "View dkmetz@taylorbruce.com's Profile")*

-- 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](http://prntscr.com/7wkkca)

Order observed (after the import):
[ prntscr.com/7wknlt](http://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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM3LWltcG9ydC1leHBvcnQtY3N2LXhscy84NzgzNzYtb3JkZXItb2YtcmVsYXRlZC1wcm9kdWN0cy1ub3Qta2VwdC1kdXJpbmctaW1wb3J0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

11 years 4 months ago [\#209496](#209496) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Order of Related Products not kept during import](/forum/37-import-export-csv-xls/878376-order-of-related-products-not-kept-during-import#209496 "-- 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&#95;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")*

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: Code:

function _insertRelated(&amp;$products,$type='related'){ $values = array(); $totalValid=0; $insert = 'INSERT IGNORE INTO '.hikashop_table('product_related').' (&#96;product_related_id&#96;,&#96;product_related_type&#96;,&#96;product_id&#96;) VALUES ('; $ids=array(); foreach($products as $product){ if(!isset($product-&gt;$type) &amp;&amp; empty($product-&gt;hikashop_update)){ //copy files from template if any if(@$product-&gt;product_type!='variant' &amp;&amp; !empty($this-&gt;template-&gt;$type)){ foreach($this-&gt;template-&gt;$type as $id){ $value = array((int)$id,$this-&gt;db-&gt;Quote($type),$product-&gt;product_id); $values[] = implode(',',$value); $totalValid++; if( $totalValid &amp;&amp; $totalValid%$this-&gt;perBatch == 0){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); $totalValid=0; $values=array(); } } } }elseif(isset($product-&gt;$type)&amp;&amp;is_array($product-&gt;$type)){ $ids[] = (int)$product-&gt;product_id; foreach($product-&gt;$type as $k =&gt; $id){ if(!empty($id)){ $id = $this-&gt;_getRelated($id); $product-&gt;{$type}[$k] = $id; $value = array((int)$id,$this-&gt;db-&gt;Quote($type),$product-&gt;product_id); $values[] = implode(',',$value); $totalValid++; } if( $totalValid &amp;&amp; $totalValid%$this-&gt;perBatch == 0){ if(!empty($ids)){ $this-&gt;db-&gt;setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this-&gt;db-&gt;Quote($type)); $this-&gt;db-&gt;query(); $ids=array(); } if(!empty($id)){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); } $totalValid=0; $values=array(); } } } } if(!empty($ids)){ $this-&gt;db-&gt;setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this-&gt;db-&gt;Quote($type)); $this-&gt;db-&gt;query(); } if(count($values)){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); } }

to: Code:

function _insertRelated(&amp;$products,$type='related'){ $values = array(); $totalValid=0; $insert = 'INSERT IGNORE INTO '.hikashop_table('product_related').' (&#96;product_related_id&#96;,&#96;product_related_type&#96;,&#96;product_id&#96;,&#96;product_related_ordering&#96;) VALUES ('; $ids=array(); foreach($products as $product){ if(!isset($product-&gt;$type) &amp;&amp; empty($product-&gt;hikashop_update)){ //copy files from template if any if(@$product-&gt;product_type!='variant' &amp;&amp; !empty($this-&gt;template-&gt;$type)){ $i = 0; foreach($this-&gt;template-&gt;$type as $id){ $value = array((int)$id,$this-&gt;db-&gt;Quote($type),$product-&gt;product_id,$i); $values[] = implode(',',$value); $totalValid++; if( $totalValid &amp;&amp; $totalValid%$this-&gt;perBatch == 0){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); $totalValid=0; $values=array(); } $i++; } } }elseif(isset($product-&gt;$type)&amp;&amp;is_array($product-&gt;$type)){ $ids[] = (int)$product-&gt;product_id; $i = 0; foreach($product-&gt;$type as $k =&gt; $id){ if(!empty($id)){ $id = $this-&gt;_getRelated($id); $product-&gt;{$type}[$k] = $id; $value = array((int)$id,$this-&gt;db-&gt;Quote($type),$product-&gt;product_id,$i); $values[] = implode(',',$value); $totalValid++; } if( $totalValid &amp;&amp; $totalValid%$this-&gt;perBatch == 0){ if(!empty($ids)){ $this-&gt;db-&gt;setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this-&gt;db-&gt;Quote($type)); $this-&gt;db-&gt;query(); $ids=array(); } if(!empty($id)){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); } $totalValid=0; $values=array(); } $i++; } } } if(!empty($ids)){ $this-&gt;db-&gt;setQuery('DELETE FROM '.hikashop_table('product_related').' WHERE product_id IN ('.implode(',',$ids).') AND product_related_type='.$this-&gt;db-&gt;Quote($type)); $this-&gt;db-&gt;query(); } if(count($values)){ $this-&gt;db-&gt;setQuery($insert.implode('),(',$values).')'); $this-&gt;db-&gt;query(); } }

in the file administrator/components/com_hikashop/helpers/import.php and that should allow the import to support it.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM3LWltcG9ydC1leHBvcnQtY3N2LXhscy84NzgzNzYtb3JkZXItb2YtcmVsYXRlZC1wcm9kdWN0cy1ub3Qta2VwdC1kdXJpbmctaW1wb3J0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.062 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
