Author Topic: Display all products for one shopper group  (Read 1046 times)

Agaton

  • Jr. Member
  • **
  • Posts: 163
Display all products for one shopper group
« on: March 24, 2019, 14:29:02 pm »
Hi,

I am currently trying to get all products for one shopper group to be displayed on one link when the user logs in. So far I have been able to create override templates that I have customised to display only products assigned to that shoppergroup by using a simple if statement as shown below.

Code: [Select]
foreach ( $products as $product ) {

if ($product->shoppergroups[2] == 3) {

Not sure if this is the correct approach but it works and I can't see any downsides apart from the fact it has to scroll through all the products in one go to display. A few seconds load time is annoying but not unusual when entering a login area on a lot of websites. However if someone has a better approach I would be grateful to hear suggestions.

The reason I am on the forum is because the pagination is affecting the result. I use virtuemart category module to link at top level category, removed category display in override template and if I give front page products a large maximum it displays fine. If I then visit a sub category, then back to the link for the shopper group products I get pagination showing again.

I know that pagination is compiled in the vmpagination.php file in administrator/components/com_virtuemart/helpers, i know that if put in the code
Code: [Select]
print_r($this->vmPagination); it will return
Code: [Select]
VmPagination Object ( [_perRow:VmPagination:private] => 1 [limitstart] => 0 [limit] => 50 [total] => 6288 [prefix] => [_viewall:protected] => [_additionalUrlParams:protected] => Array ( ) [pages.total] => 126 [pages.current] => 1 [pages.start] => 1 [pages.stop] => 10 )
If I add
Code: [Select]
$this->vmPagination->limit = $this->vmPagination->total; it will return
Code: [Select]
VmPagination Object ( [_perRow:VmPagination:private] => 1 [limitstart] => 0 [limit] => 6288 [total] => 6288 [prefix] => [_viewall:protected] => [_additionalUrlParams:protected] => Array ( ) [pages.total] => 126 [pages.current] => 1 [pages.start] => 1 [pages.stop] => 10 )
However products are still displayed as if pagination was 50 per page even though I have altered limit to 6288. I am missing something. Either I have a completely wrong approach due to a completely lack of understanding about the virtuemart arrays or I am missing one final piece of the puzzle.

I cannot give a link as I am doing this in a test area on my server with a host file change to a fake domain. Can someone help me either:

  • Direct me to a better approach to achieve this
  • Guide me in the right direction to find the missing piece if there i indeed one
  • or point me in the direction of a good module that filters by shopper group also - maybe this should be my approach anyway?

I have already considered adding all products to a category and only displaying that category to the shopper group, however that does require more management which I am trying to avoid by making it a template override function rather than a new module or virtuemart category.

Hope someone can help.

Cheers
Martyn

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4382
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Display all products for one shopper group
« Reply #1 on: March 24, 2019, 16:59:32 pm »
trying to display 6288 products kill your shop.
You need to prefilter the shopper group directly using a class override and set your shopper group filter in the query, not on render.
VIrtuemart verify if a class exist so you can preload the class using a system plugin

Agaton

  • Jr. Member
  • **
  • Posts: 163
Re: Display all products for one shopper group
« Reply #2 on: March 24, 2019, 17:00:53 pm »
Thanks for your reply, could you give me some direction to get me started on this?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4382
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Display all products for one shopper group
« Reply #3 on: March 24, 2019, 21:55:16 pm »
Check Joomla system plugin https://docs.joomla.org/Plugin/Events/System
YOu have trigger onAfterInitialise
include your class inside(check you are in site and not admin)
Do not forget to add
Code: [Select]
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig();
copy administrator\components\com_virtuemart\models\product.php
In your own product class modify the sortSearchListQuery for your needs to filter shoppergroups.

Agaton

  • Jr. Member
  • **
  • Posts: 163
Re: Display all products for one shopper group
« Reply #4 on: March 25, 2019, 11:18:25 am »
Thanks

Agaton

  • Jr. Member
  • **
  • Posts: 163
Re: Display all products for one shopper group
« Reply #5 on: March 25, 2019, 21:58:10 pm »
 Thank you for that info, I've had a good look at what you have provided me.

If I am understanding this correctly, I am creating my own plugin that will then create a new class for my filters which I then call into my template.

Am I on the right lines?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4382
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Display all products for one shopper group
« Reply #6 on: March 26, 2019, 00:05:26 am »
You dont have to call the class, if this is declared before Virtuemart class, then the original class is not loaded
This mean that you have only to check for user shopper group(or your group input) and add your filter in your new class in the class product function exesearchquery.