News:

Looking for documentation? Take a look on our wiki

Main Menu

Display all products for one shopper group

Started by Agaton, March 24, 2019, 14:29:02 PM

Previous topic - Next topic

Agaton

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.

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 print_r($this->vmPagination); it will return 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 $this->vmPagination->limit = $this->vmPagination->total; it will return 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

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

Thanks for your reply, could you give me some direction to get me started on this?

Studio 42

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

 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

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.