VirtueMart Forum

VirtueMart 2 + 3 => Templating & Layouts => Topic started by: Agaton on March 24, 2019, 14:29:02 pm

Title: Display all products for one shopper group
Post by: Agaton 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:


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
Title: Re: Display all products for one shopper group
Post by: Studio 42 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
Title: Re: Display all products for one shopper group
Post by: Agaton on March 24, 2019, 17:00:53 pm
Thanks for your reply, could you give me some direction to get me started on this?
Title: Re: Display all products for one shopper group
Post by: Studio 42 on March 24, 2019, 21:55:16 pm
Check Joomla system plugin https://docs.joomla.org/Plugin/Events/System (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.
Title: Re: Display all products for one shopper group
Post by: Agaton on March 25, 2019, 11:18:25 am
Thanks
Title: Re: Display all products for one shopper group
Post by: Agaton 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?
Title: Re: Display all products for one shopper group
Post by: Studio 42 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.