$html .= '<td style="white-space:nowrap;">'
. '<span class="vmicon vmicon-16-move"
style="cursor:move;font-size:20px;color:#666;vertical-align:middle;margin:0 6px 0 5px;"
title="Reorder">⋮⋮</span>'
. JHTML::_('link', ...)
. '<input type="hidden" class="vmchild-ordering"
name="childs[' . $child->virtuemart_product_id . '][pordering]"
value="' . (int)($child->pordering ?? 0) . '" />'
. '</td>';
if (isset($childIds[$product_id])) {
$sorted = self::sortChildIds($product_id, $childIds[$product_id], $field->options);
$allIds = array_merge([$product_id], array_values($childIds[$product_id]));
$db = JFactory::getDBO();
$db->setQuery('SELECT virtuemart_product_id, pordering FROM #__virtuemart_products'
. ' WHERE virtuemart_product_id IN (' . implode(',', array_map('intval', $allIds)) . ')');
$porderingMap = $db->loadAssocList('virtuemart_product_id', 'pordering');
$sorted[] = ['parent_id' => $product_id, 'vm_product_id' => $product_id]; // parent included
usort($sorted, function ($a, $b) use ($porderingMap) {
$posA = isset($porderingMap[$a['vm_product_id']]) ? (int)$porderingMap[$a['vm_product_id']] : 999;
$posB = isset($porderingMap[$b['vm_product_id']]) ? (int)$porderingMap[$b['vm_product_id']] : 999;
return $posA - $posB;
});
} else {
$sorted[] = ['parent_id' => $product_id, 'vm_product_id' => $product_id];
}
// array_unshift(...) removed - parent is now part of the sorted array
jQuery(document).ready(function ($) {
$('#syncro').sortable({
cursorAt: { top: 0, left: 0 },
handle: '.vmicon-16-move',
update: function (event, ui) {
$(this).find('.vmchild-ordering').each(function (index, el) {
$(el).val(index);
});
}
});
$('#syncro .vmchild-ordering').each(function (index, el) {
$(el).val(index);
});
});
} else {
// Parent variant: only update pordering if explicitly submitted
if (isset($child['pordering'])) {
$db = JFactory::getDBO();
$db->setQuery('UPDATE #__virtuemart_products SET pordering = '
. (int)$child['pordering']
. ' WHERE virtuemart_product_id = ' . (int)$productId);
$db->execute();
}
}
Page created in 0.063 seconds with 9 queries.