Author Topic: Save order for manual product ordering in category does not work  (Read 18691 times)

porscha

  • Beginner
  • *
  • Posts: 6
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

porscha

  • Beginner
  • *
  • Posts: 6
Re: Save order for manual product ordering in category does not work
« Reply #1 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));
   }

edthenet

  • Beginner
  • *
  • Posts: 33
    • Scorpion Computers & Software
Re: Save order for manual product ordering in category does not work
« Reply #2 on: October 17, 2012, 11:34:16 am »
I have the same issue and i use 2.0.12b

porscha

  • Beginner
  • *
  • Posts: 6
Re: Save order for manual product ordering in category does not work
« Reply #3 on: October 18, 2012, 15:23:13 pm »
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.

umbobabo

  • Beginner
  • *
  • Posts: 9
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php

Replace all the function with this...

   
Quote
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 $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.

Quote
foreach ($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.

CE WebDesign München

  • Jr. Member
  • **
  • Posts: 112
  • CE WebDesign München
    • CE WebDesign München
Re: Save order for manual product ordering in category does not work
« Reply #5 on: October 23, 2012, 17:34:56 pm »
Wow,
thanks, works great for me! (J 2.5.7+VM 2.0.8 )
CE WebDesign München: https://ce-webdesign.de | Websites, eCommerce WebShops | Responsive Design | SEO

SAS

  • Beginner
  • *
  • Posts: 5
  • VirtueMart Version: 2.0.22b
Re: Save order for manual product ordering in category does not work
« Reply #6 on: October 23, 2012, 20:29:30 pm »
hmm... in 2.0.12f the problem still persist. And this fix not works - there are no function saveorder in this file :/

umbobabo

  • Beginner
  • *
  • Posts: 9
Re: Save order for manual product ordering in category does not work
« Reply #7 on: October 23, 2012, 20:35:38 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 ;-)

SAS

  • Beginner
  • *
  • Posts: 5
  • VirtueMart Version: 2.0.22b
Re: Save order for manual product ordering in category does not work
« Reply #8 on: October 23, 2012, 21:27:36 pm »
Yes, it was my typo. Fixed.

BaidareW

  • Jr. Member
  • **
  • Posts: 111
Re: Save order for manual product ordering in category does not work
« Reply #9 on: October 27, 2012, 16:04:47 pm »
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!!!!

umbobabo

  • Beginner
  • *
  • Posts: 9
Re: Save order for manual product ordering in category does not work
« Reply #10 on: October 27, 2012, 16:16:13 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.

BaidareW

  • Jr. Member
  • **
  • Posts: 111
Re: Save order for manual product ordering in category does not work
« Reply #11 on: October 27, 2012, 16:26:28 pm »
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]

jthrongard

  • Beginner
  • *
  • Posts: 30
    • Simple CMS Design
Re: Save order for manual product ordering in category does not work
« Reply #12 on: November 01, 2012, 19:07:54 pm »
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php

Replace all the function with this...

   
Quote
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 $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!!!
Small Business Joomla! Website Design - Simple CMS Design
http://www.simplecmsdesign.com

porscha

  • Beginner
  • *
  • Posts: 6
Hi,
I think I fixed it.
On administrator/components/com_virtuemart/models/product.php

Replace all the function with this...

   
Quote
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 $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.

Quote
foreach ($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 :)

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9642
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Save order for manual product ordering in category does not work
« Reply #14 on: November 02, 2012, 22:54:51 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.

Quote
foreach ($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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/