News:

Support the VirtueMart project and become a member

Main Menu

Bugfix: Product ordering function

Started by SniperSister, February 28, 2012, 15:52:21 PM

Previous topic - Next topic

SniperSister

Hi,

I did some bugfixing on the product ordering function which results in the following patch:

/helpers/shopfunctions.php, line 1169 changed to:
'product_unit', 'product_packaging', 'p.virtuemart_product_id','ordering');


/models/products.php, function saveorder changed to:
function saveorder($cid , $orders) {
JRequest::checkToken() or jexit( 'Invalid Token' );

$virtuemart_category_id = JRequest::getInt('virtuemart_category_id', 0);

$q = 'SELECT `id`,`ordering` FROM `#__virtuemart_product_categories`
WHERE virtuemart_category_id='.(int)$virtuemart_category_id.'
ORDER BY `ordering` ASC';
$this->_db->setQuery($q);
$pkey_orders = $this->_db->loadObjectList();

$tableOrdering = array();
foreach ($pkey_orders as $order) $tableOrdering[$order->id] = $order->ordering;
// set and save new ordering
foreach  ($orders as $key => $order) $tableOrdering[$key] = $order;
asort($tableOrdering);
$i = 1 ; $ordered = 0 ;
foreach  ($tableOrdering as $key => $order) {
$this->_db->setQuery('UPDATE `#__virtuemart_product_categories`
SET `ordering` = '. $i.'
WHERE `id` = ' . (int)$key . ' ');
if (! $this->_db->query()){
vmError($this->_db->getErrorMsg());
return false;
}
$ordered ++ ;
$i++ ;
}
if ($ordered) $msg = JText::sprintf('COM_VIRTUEMART_ITEMS_MOVED', $ordered);
else $msg = JText::_('COM_VIRTUEMART_ITEMS_NOT_MOVED');
JFactory::getApplication()->redirect('index.php?option=com_virtuemart&view=product&virtuemart_category_id='.$virtuemart_category_id, $msg);

}


Now it seems to be working properly.

Best regards
David

skygirl


Milbo

Spilka did something simular, will be in the release today.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

luxuryvps

Will this fix have any effect on my current problem reported here: http://forum.virtuemart.net/index.php?topic=98824.0 ?

Liam
Liam Studham - Graphical Designer / Server Engineer
http://www.luxuryvps.com
VPS & Dedicated Servers - Discounts available for all VM Forum users (PM me)

beipink

Quote from: Milbo on February 29, 2012, 15:08:59 PM
Spilka did something simular, will be in the release today.
Hi Max,
Did you manage to include this fix in the release?
I have updated to 2.0.4 just now and the sorting of products from back-end appear to be still broken!

Studio 42

Hi,
I have read the code, it's exactly the same as your in last SVN files/release(commented line excluded)

beipink

Quote from: Electrocity on April 10, 2012, 15:14:14 PM
Hi,
I have read the code, it's exactly the same as your in last SVN files/release(commented line excluded)
The code might be included and it seems to work in the back-end however the changes are NOT reflected in the frontend.
am I doing something wrong??

Studio 42

If you use sef it"s a mistake in the file and the dev revision is updated.
Without SEF this must work.

beipink

#8
Quote from: Electrocity on April 11, 2012, 18:51:17 PM
If you use sef it"s a mistake in the file and the dev revision is updated.
Without SEF this must work.

Ok, I definetely use SEF, I'll have to give it a go with SEF disabled.
anyway where to i get the ammended file?


[update]
Tried with SEF disabled both in VM and J! and the product ordering still not working in the front end.
With regards to the back-end the arrows require some attnetion too

beipink

Quote from: Electrocity on April 11, 2012, 18:51:17 PM
If you use sef it"s a mistake in the file and the dev revision is updated.
Without SEF this must work.

Hi Electrocity,
Is the product ordering working for you?? I cannot get it to work. In the backend posions (nr of the positions) can be changed however the listing of the products remain always the same (both back-end and front-end)
VM2.0.4 J!2.5.5

beipink

I have updated to VM2.0.6 and ordering in the back-end seems to work now however changes are not reflected in the front-end.
at this point it might be my installation that has a problem. anybody experiencing this sorting/ordering issue in the front-end??

miata

The same issue here, the above patch doesn't influence the order on frontend... any idea how to fix this? This seems to be  strange bug for such a popular software and already for years available!?

beipink

I have done a fresh install of J2.5.4 and VM2.0.6 and the reordering is not working.
the order nrs can be changed in the back-end however products are always displayed in the same order both in the back-end and front-end as per attached



[attachment cleanup by admin]

beipink

#13
Ordering seems to work, some work is still required but the basics are there.
to order your products you need:
1. filter products by category
2. enter the position nr (arrows do not work as expected yet)
3. hit the  save order icon in the "reorder" column
4. click on configuration/configuration on the right hand side menu
5. then product order settings and select ordering in the drop down list "Default product sort order"

things that still do not work:
1. reordering arrows are inverted (down arrow will increment and up arrow will decrease  the oreder nr)
2. products in the back-end remain in the same position (product_id order) after reordering them. Products should always be listed by sort order. 

Tested on VM 2.6 & J2.5