Hi, I'm facing this problem - when I order products manually by putting numbers in the column for order and than click save option (the litle floppy disk) the order that I have fill in the fields did not save and things came back from the begining. I've read all about this in the forum, but without any solution. Is there any smart guy to solve this, because I have been struggling this for 3 days, and did not reach the goal. I have realized that when you are in category mode, where you have all of your categories and subcategories, and you reorder manually them by writing numbers for them and than click save - It works perfect. Why for products it does not :'(
Please find time for this problem, it has no minor importancy and it wll be great to work like in vm 1.9x
I use Joomla 2.5.6 an VM 2.0.8e
this is from
administrator/components/com_virtuemart/models/product.php
/* reorder product in one category
* TODO this not work perfect ! (Note by Patrick Kohl)
*/
function saveorder ($cid = array(), $order, $filter = NULL) {
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 ($order as $key => $ord) {
$tableOrdering[$key] = $ord;
}
asort ($tableOrdering);
$i = 1;
$ordered = 0;
foreach ($tableOrdering as $key => $order) {
// if ($order != $i) {
$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);
}
/**
* Moves the order of a record
*
* @param integer The increment to reorder by
*/
function move ($direction, $filter = NULL) {
JRequest::checkToken () or jexit ('Invalid Token');
// Check for request forgeries
$table = $this->getTable ('product_categories');
$table->move ($direction);
JFactory::getApplication ()->redirect ('index.php?option=com_virtuemart&view=product&virtuemart_category_id=' . JRequest::getInt ('virtuemart_category_id', 0));
}
I have the same issue and i use 2.0.12b
Yes, I have updated to VM 2.0.12b and the problem still persist. And I have to reorder products with this arrows, but I have problems and with them cause, sometimes you have to click twice or more an arrow, to move one product to somewhere else, but it does not change, and when you click it one more time, the product suddenly moves through 2-3 places and not there where you have wanted from the very beginning.
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php
Replace all the function with this...
Quotefunction saveorder ($cid = array(), $order, $filter = NULL) {
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 $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
// set and save new ordering
foreach ($order as $key => $ord) {
$tableOrdering[$key] = $ord;
}
asort ($tableOrdering);
$i = 1;
$ordered = 0;
foreach ($tableOrdering as $key => $order) {
// if ($order != $i) {
$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);
}
The problem was here...
Quote
foreach ($pkey_orders as $order) {
$tableOrdering[$order->id] = $order->ordering;
}
Silly error on variable use ($order), because used in the foreach cycle and then in second foreach cycle.
Changed to $orderTemp seem to fix it.
Quoteforeach ($pkey_orders as $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
.
Please have some test on this and let me know if it's ok for you.
Wow,
thanks, works great for me! (J 2.5.7+VM 2.0.8 )
hmm... in 2.0.12f the problem still persist. And this fix not works - there are no function saveorder in this file :/
Quote from: SAS on October 23, 2012, 20:29:30 PM
... there are no function sortorder in this file :/
The function is "saveorder" not "sortorder", by the way I don't know if exists, have a look ;-)
Yes, it was my typo. Fixed.
I had this sorting problem (putting numbers in the columns and clicking save icon) three moths ago, many debate some fixes for sorting.. Now I am back, updating to latest 2.0.12f and the same sorting problems. Uff. I think essential things should be done first, not some super duper futures. Now if I have 50 products in category it take ages to sort in the way I want.
So I am also on of those who asks " please FIX at last all sorting issues!!!!
Quote from: BaidareW on October 27, 2012, 16:04:47 PM
So I am also on of those who asks " please FIX at last all sorting issues!!!!
.
Have a look on my solution above, maybe works for you version.
I haven't test it on 2.0.12.
I read SAS comment "hmm... in 2.0.12f the problem still persist. And this fix not works - there are no function saveorder in this file :/" so didn't tried it.
[/quote].
Have a look on my solution above, maybe works for you version.
I haven't test it on 2.0.12.
[/quote]
Quote from: umbobabo on October 21, 2012, 15:54:33 PM
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php
Replace all the function with this...
Quotefunction saveorder ($cid = array(), $order, $filter = NULL) {
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 $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
// set and save new ordering
foreach ($order as $key => $ord) {
$tableOrdering[$key] = $ord;
}
asort ($tableOrdering);
$i = 1;
$ordered = 0;
foreach ($tableOrdering as $key => $order) {
// if ($order != $i) {
$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);
}
This worked for me on Vmart 2.0.12f. I replaced lines 1270 to 1312. Make this IN THE NEXT VERSION!!!
Quote from: umbobabo on October 21, 2012, 15:54:33 PM
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php
Replace all the function with this...
Quotefunction saveorder ($cid = array(), $order, $filter = NULL) {
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 $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
// set and save new ordering
foreach ($order as $key => $ord) {
$tableOrdering[$key] = $ord;
}
asort ($tableOrdering);
$i = 1;
$ordered = 0;
foreach ($tableOrdering as $key => $order) {
// if ($order != $i) {
$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);
}
The problem was here...
Quote
foreach ($pkey_orders as $order) {
$tableOrdering[$order->id] = $order->ordering;
}
Silly error on variable use ($order), because used in the foreach cycle and then in second foreach cycle.
Changed to $orderTemp seem to fix it.
Quoteforeach ($pkey_orders as $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
.
Please have some test on this and let me know if it's ok for you.
YOU ARE AWESOME!!!!!! I'm so greatful. This is the solution I was looking for and now reordering is piece of cake :)
Quote from: umbobabo on October 21, 2012, 15:54:33 PM
The problem was here...
Quote
foreach ($pkey_orders as $order) {
$tableOrdering[$order->id] = $order->ordering;
}
Silly error on variable use ($order), because used in the foreach cycle and then in second foreach cycle.
Changed to $orderTemp seem to fix it.
Quoteforeach ($pkey_orders as $orderTemp) {
$tableOrdering[$orderTemp->id] = $orderTemp->ordering;
}
.
Please have some test on this and let me know if it's ok for you.
Great, I added it already to vm2.1.0. There will be a small update for the 2.0 also.
Just want to say thank you to umbobabo for solution.
There are two more bugs:
1. In the file administrator/components/com_virtuemart/models/product.php, before this line (line 851 for 2.0.14) within the function getProductSingle:
$product->virtuemart_category_id = $product->categories[0];
insert these lines
// added by JK to fix bug
$virtuemart_category_id = JRequest::getInt ('virtuemart_category_id', 0);
if ($virtuemart_category_id)
$product->virtuemart_category_id = $virtuemart_category_id;
else
// added by JK ends
This will fix the cases when one product belongs to multiple categories.
2. In the file administrator/components/com_virtuemart/helpers/vmtablexarray.php, change this line (line 71 for version 2.0.14)
$query = 'SELECT `id` WHERE $this->_pkey = '.(int)$cid[0].' AND `virtuemart_category_id` = '.(int)$skeyId ;
to
$query = 'SELECT `id` FROM `' . $this->_tbl . '` WHERE ' . $this->_pkey . ' = '.(int)$cid[0].' AND `virtuemart_category_id` = '.(int)$skeyId ; //mod by JK to fix bug
This will fix the bug when using orderup and orderdown icon to change the sort order.
These bug fixes are funded by a client. It may not work in all cases. Please test it and report back.
Perfect, great, thank you and your client for sharing this!!!
Works nice in 2.0.14 (and 2.0.8c - line 689 for 1.bug)
would you be interrested in a job fixing 'odering of related products'?
http://forum.virtuemart.net/index.php?topic=108177.msg370553#msg370553
Thanks gogo123. That request may not be straight forward. Please read the PM I sent.
Fixes still work, but when editing a product, on save
the order of products in its categories gets lost (j258+vm2014)
Hmm.. this can be subtle. Not sure if this works but you can try. Replace fix #1 above with
1. In the file administrator/components/com_virtuemart/models/product.php, replace this line (line 851 for 2.0.14) within the function getProductSingle:
$product->virtuemart_category_id = $product->categories[0];
with these lines
// mod by JK to fix bug
$product->virtuemart_category_id = JRequest::getInt ('virtuemart_category_id', 0);
// mod by JK ends
I hope this will add an ordering for showing all products (without an association with any category). But probably some code elsewhere may need to modify as well.
This replacement code will work better.
$product->virtuemart_category_id = $this->virtuemart_category_id;
thanks for providing help, works perfect!
so with new fix #1 + old fix #2:
orderup and -down icon still working good (in-/decrease product ordernumber,
though not switching place with next/previous - but fine with me)
odering when product belongs to multiple categories still working good and per category
on saving product with multiple categories,
odering is not changed (checked both categories), so this is fixed!!!
so great, for me it's fixed, thank you so much!!!
I had understood this should have been fixed in version 2.0.14 but it is still giving me trouble. I may be asking too much in that I have 3 levels of category hierarchy and want to display products at all three levels. I have given up trying to order the lower two levels and am manually ordering at the top level only. Typing in an order and then saving it does not seem to work correctly. The order displayed from the admin view is not the same as the order number. It might be that the sort for the admin view and possibly the customer view are treating the order as text. The only way I have been able to get ordering to work (top level) is by usingthe up/down arrows (and they don't work as expected often jumping several positions).
hi, if it is still giving you trouble, please backup your site, test the fixes mentioned above and post here, if it works for all 3 levels or test 2.0.15b (not for live site!) - version 2.0.14 works great for me with these fixes.
Kwan
Please how do you think should be this part be written?
if (!empty($product->categories) and is_array ($product->categories) and !empty($product->categories[0])) {
$product->virtuemart_category_id = $product->categories[0];
Added, please test
I tried this fix and my child products are still arranged arbitrarily. I'm using the latest version of virtuemart and joomla. Everything is updated. Any ideas?
Thanks!
My site is here:
http://haydenmedicalinc.com/joomla/viretuemart/7/3/bariatric-instruments/forceps-bariatric/debakey-forceps-bariatric-detail (http://haydenmedicalinc.com/joomla/viretuemart/7/3/bariatric-instruments/forceps-bariatric/debakey-forceps-bariatric-detail)
Quote from: porscha on October 16, 2012, 12:49:59 PM
I use Joomla 2.5.6 an VM 2.0.8e
this is from
administrator/components/com_virtuemart/models/product.php
/* reorder product in one category
* TODO this not work perfect ! (Note by Patrick Kohl)
*/
function saveorder ($cid = array(), $order, $filter = NULL) {
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 ($order as $key => $ord) {
$tableOrdering[$key] = $ord;
}
asort ($tableOrdering);
$i = 1;
$ordered = 0;
foreach ($tableOrdering as $key => $order) {
// if ($order != $i) {
$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);
}
/**
* Moves the order of a record
*
* @param integer The increment to reorder by
*/
function move ($direction, $filter = NULL) {
JRequest::checkToken () or jexit ('Invalid Token');
// Check for request forgeries
$table = $this->getTable ('product_categories');
$table->move ($direction);
JFactory::getApplication ()->redirect ('index.php?option=com_virtuemart&view=product&virtuemart_category_id=' . JRequest::getInt ('virtuemart_category_id', 0));
}
I am using J2.5.8 VM2.0.18a . I can confirm that setting the ordering of products which belong to multiple categories still does not work correctly.
I am not able to apply any of the hacks suggested here as the administrator/components/com_virtuemart/modesl/product.php looks quite different from the previous versions mentioned here (2.0.14 and before).
I am happy to say that I have found a fix for 2.0.18a
Roughly, here's how to reproduce the bug:
1. Assign products to category A and B
2. In products list view, filter by category B
3. Set ordering for products
4. The ordering is saved to category A instead
The problem is, if a product is assigned to several categories, when you set the ordering for that product in one particular category, Virtuemart will always load and save the ordering to the first category it belongs to.
And here's the fix:
In administrator/components/com_virtuemart/models/product.php , function getProductSingle , line 898
replace this :
} else {
$product->virtuemart_category_id = JRequest::getInt ('virtuemart_category_id', 0);
if (!empty($product->categories) and is_array ($product->categories) and !empty($product->categories[0])) {
$product->virtuemart_category_id = $product->categories[0];
} else {
$product->virtuemart_category_id = 0;
}
}
with this:
} else {
$product->virtuemart_category_id = $this->virtuemart_category_id; // shouldn't get from JRequest. This gets from the filtering state in the model object
if ( !empty($product->virtuemart_category_id) ) {
// don't do anything, we already have the right category id from JRequest
} else if (!empty($product->categories) and is_array ($product->categories) and !empty($product->categories[0])) {
$product->virtuemart_category_id = $product->categories[0];
} else {
$product->virtuemart_category_id = 0;
}
var_dump($product->virtuemart_category_id);
}
I have checked against 2.1 in the SVN trunk and this bug still exists there. Is there any chance this can be merged into 2.1, Max?
Just wanted to say thanks to jingtao, the shop finally sports sorted shoesizes!
Dorandis (very happy)
Hello again. While the code worked perfect in the old VM the new 2.0.24 is all mixed up again. Any help?
Thanks in advance!
Dorandis