News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Save order for manual product ordering in category does not work

Started by porscha, October 16, 2012, 12:27:17 PM

Previous topic - Next topic

porscha

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

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


porscha

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

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.

CE WebDesign München

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

hmm... in 2.0.12f the problem still persist. And this fix not works - there are no function saveorder in this file :/

umbobabo

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 ;-)


BaidareW

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

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.

BaidareW

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

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

porscha

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 :)

Milbo

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