Keyword

k2 item > Update "ordering" when moving it from one category to another

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
1 week 6 days ago #178099 by RomyS
Hi Fotis!
I have a problem with the "ordering" when copying an article and then changing it category. The article still maintains the same order as in its previous category, so it appears very low when ordering it manually ... Can you tell me if I can touch the /tables/k2item.php or /model/item.php so that when it changes category, also check the last order of that new category?

Something like that, but when saving an article if it changes its category ...
$this->table->getNextOrder("catid = {$post} AND trash = 0");

I hope you can help me to solve this, I would appreciate it very much.

regards

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Away
  • Administrator
  • JoomlaWorks Support Team
More
1 week 5 days ago #178115 by Fotis
We don't specify any ordering as you may notice from the code.

As such, you'll have to edit the save method in the item's backend model and if you detect a category change, query the items table for the new category's items and get the highest ordering so you can "move" the item upon saving.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
1 week 5 days ago - 1 week 4 days ago #178133 by RomyS
Thanks again, Fotis!

This works for me. How you see it?


if (!$isNew) {
$id = JRequest::getInt('id');
$currentRow = JTable::getInstance('K2Item', 'Table');
$currentRow->load($id);
if ($currentRow->catid !== $row->catid ) {

$row->ordering = $row->getNextOrder("catid = ".(int)$row->catid." AND trash = 0");

}
}


Can it generate a conflict with other lines, or affect the queries of the database?

I would appreciate your help!
regards
Last edit: 1 week 4 days ago by RomyS.

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Away
  • Administrator
  • JoomlaWorks Support Team
More
1 week 4 days ago #178145 by Fotis
Seems OK.

Since we don't explicitly set any ordering on save, it should not conflict with anything.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
1 week 4 days ago #178148 by RomyS
Excellent, thank you very much for confirming! I will apply it and test it for a few days and then I will write to you again.
Regards

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Away
  • Administrator
  • JoomlaWorks Support Team
More
1 week 4 days ago #178155 by Fotis
Awaiting for your feedback.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.

  • RomyS
  • RomyS's Avatar Topic Author
  • Offline
  • Junior Member
More
1 week 6 hours ago #178192 by RomyS
Update: everything works ok! Without problems and ordering in each case when saving the article in a different category.
We give the post by Solved? Is the hack useful for new k2 updates?

Thank you very much team!

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Away
  • Administrator
  • JoomlaWorks Support Team
More
6 days 3 hours ago #178200 by Fotis
No need to add "solved". :)

As for getting this into K2, it's really an edge case. I can add a ton of edge cases but that would balloon the K2 settings and it's not worth it.

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum