After update to 4.8.2 cannot reorder images in the administration product

Started by piliop, September 05, 2026, 08:40:22 AM

Previous topic - Next topic

piliop

i have confirmed the problem in several different instances.
can anyone confirm it?

piliop

I have found a temp solution in administrator/components/com_virtuemart/models/media.php
I added some code and now i am able to change the order by dragging the images.

if needed i can provide the fix code.

jflash


piliop

in administrator\components\com_virtuemart\models\media.php

under the line 405 that seems like this :

if(!is_array($oldIds)) $oldIds = array($oldIds);

Add

       
if(isset($data['ordering'], $data['active_media_id'])){
            if(!isset($data['mediaordering']) || !is_array($data['mediaordering'])){
                $data['mediaordering'] = array();
            }
            $data['mediaordering'][(int)$data['active_media_id']] = (int)$data['ordering'];
        }


also

after line 440 whitch seems like this :

               
// Bind the media to the product,

replace the line   

             
  return  $table->bindChecknStore($data);
With

       
$result = $table->bindChecknStore($data);

        if(!empty($data['mediaordering']) && !empty($data['virtuemart_'.$type.'_id'])){
            $db = JFactory::getDbo();
            $relationTable = '#__virtuemart_'.$type.'_medias';
            $entityId = (int)$data['virtuemart_'.$type.'_id'];
            foreach($data['mediaordering'] as $mediaId => $ordering){
                $query = $db->getQuery(true)
                    ->update($db->quoteName($relationTable))
                    ->set($db->quoteName('ordering').' = '.(int)$ordering)
                    ->where($db->quoteName('virtuemart_'.$type.'_id').' = '.$entityId)
                    ->where($db->quoteName('virtuemart_media_id').' = '.(int)$mediaId);
                $db->setQuery($query)->execute();
            }
        }

        return $result;

piliop

For Addressing then problem with the correct way, what i did was in file : administrator/components/com_virtuemart/helpers/vmtablexarray.php

i changed :

line 198 with       
foreach ($newArray as $sKeyInd => &$newValue) {

line 203 with       
$newValue['id'] = $oldArray[$sKeyInd]['id'];

line 214 Added   
unset($newValue);



the functions
store($updateNulls = false)  code in vmtablexarray.php calculated each image's order number but never wrote it to the database. It assigned the number to a copy of the row (foreach (... as $k => $newValue)), so the original row never got it. Every row was stored without an order number.

the fix should be considered for a next version of virtuemart.

Milbo

Hello Piliop,
your code looks good and is at the right place. But I wonder that it is necessary. The table xarray should handle it. It works for me. There was small change. Do you have still the problem in the new version?

Maybe I take your code as kind of fallback. I just write with Grok about the issue. But first without this page, without your code. It mentioned some problems storing the sorting. When we think we have the oversight solution, then I show your code.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/