2 godziny temu, tecniconivelz napisał:Our references go by numbers all of them
So product 1 has this references: 040001, 040002, 040003But reference 040003 is newer, and when we imported it, it shows the first. So rn the order is 040003, 040001, 040002. We want to order them by the reference.
We can update them by the reference but, there are a lot of attributes (like +4000), is there a way to order them with a sql query?
Here is function that will sort numeric references.
function cmp( $a, $b ) { if( $a['reference'] == $b['reference'] ){ return 0 ; } return ($a['reference'] < $b['reference']) ? 1 : -1; } usort($attributes_groups,'cmp'); $attributes_groups = array_reverse($attributes_groups);
You have to place it before
foreach ($attributes_groups as $k => $row) {
This will only work if your references are exacly as u sent.
There might be an issue if you try to order attributes by product references and set their position inside database, because attributes can be assigned to many different products which might have different references. If you are going to use those same attributes in different product, their order will set exacly the same as on product the sorting was done.