Community

Hi, can anyone tell me how to set up product options and product category filters in MODX?

Hi, I have following getPage call …

    [[getPage?
                    &element=`getResources`
                    &parents=`7, 23, 24, 25, 49, 51, 52, 113`
                    &limit=`4`
                    &includeTVs=`1`
                    &processTVs=`1`
					[[sortByForm]]
                    &tpl=`product-list`
                    &totalVar=`total`
                    &pagePrevTpl=`<li class="pagination-prev"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon=""></span></a></li>`
                    &pageNextTpl=`<li class="pagination-next"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon=""></span></a></li>`
                    &pageActiveTpl=`<li class="active" class="page-[[+pageNo]]"><span style="display: inline-block;">[[+pageNo]]</span></li>`
                    &pageNavTpl=`<li><a href="[[++site_url]][[+href]]"><span>[[+pageNo]]</span></a></li>`
					&tvFilters=`product_location==[[!getUrlParam? &name=`product_location`]]`
                    &pageNavOuterTpl=`[[+prev]][[+pages]][[+next]]`
					&pageNavVar=`page.nav`
					&toPlaceholder=`products`
                    ]]

[[sortByForm]] is for my sorting functionality so ignore it, its working fine !! My main question is I have two filters in the sidebar of my Shop page. 1st is Product Location ( A product option I set through making Template Variable having four different values of 1 to be selected for each product on adding / updating ). 2nd filter is normal product category filter. I want to know the best way to manipulate the above getPage call for this to work. There will be multiple selection of locations and product categories as well.

Thanks,
Ronak

Hi Ronak,

Edit: Part of my reply was incorrect

I was looking at the snippet code to get an idea of what it is doing but I missed that it will pass on parameters and process the target object based on element and elementClass.

I think this was more of a simple paging utility but doesn’t include template variable filtering or query capabilities.

Edit: I didn’t think of the ability to pass this to another snippet as the object which would allow you to do further processing.

Also the &element=`getResources` is not an element class. Here it is expecting something like `modResource`.

See further conversation below with the question back to Bruno.

-Jared

@jaredfhealy

his properties are all valid, since getPage passes all parameters to the called snippet, which in this case is getResources, also element=`getResources` is valid

Can you point me in the right direction for where it does that? I think I see what I missed. Line 57 is where element and element class are used.

$elementObj = $modx->getObject($properties['elementClass'], array('name' => $properties['element']));

But for getPage to properly pass on to getResources, wouldn’t it need an &elementClass parameter passed into it otherwise it defaults to modChunk? Perhaps something like:

[[!getPage ?
    &elementClass=`modSnippet`
    &element=`getResources`
]]

@ronaksmpt Perhaps you could clarify your question further? Including a screenshot of the sidebar with the optional filters would be helpful.

Also, can you confirm all the values you are filtering on are stored in TVs on the resources?

-Jared

modSnippet is defined with the default-properties of getPage

I see how it’s working now. It’s a bit confusing since there is a check for empty on the elementClass I thought it was expected that the user might not pass it in. The default property in the set means that wouldn’t occur unless the property was deleted.

$properties['elementClass'] = empty($elementClass) ? 'modChunk' : $elementClass;

@ronaksmpt Sorry to side-track your thread! :slight_smile:

Hi, everyone… thanks for your inputs, I have resolved it by myself quite earlier and its working now … below is the working catalog call for me …

                          [[getPage?
                          &element=`getResources`
                          &limit=`9`
                          &includeTVs=`1`
                          &processTVs=`1`
                          [[sortByForm]]
                          &tpl=`product-list`
                          &totalVar=`total`
                          &pagePrevTpl=`
                          <li class="pagination-prev"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon="?"></span></a></li>
                          `
                          &pageNextTpl=`
                          <li class="pagination-next"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon="?"></span></a></li>
                          `
                          &pageActiveTpl=`
                          <li class="active" class="page-[[+pageNo]]"><span style="display: inline-block;">[[+pageNo]]</span></li>
                          `
                          &pageNavTpl=`
                          <li><a href="[[++site_url]][[+href]]"><span>[[+pageNo]]</span></a></li>
                          `
                          &pageNavOuterTpl=`[[+prev]][[+pages]][[+next]]`
                          &pageNavVar=`page.nav`
                          &toPlaceholder=`products`
                          ]]
                          [[+products:neq=``:then=`
                          <ul class="products">
                             [[+products]]
                          </ul>
                          <ul class="pagination">
                             [[!+page.nav]]
                          </ul>
                          `:else=`
                          [[*product_category_countdown_text]]
                          <div class="countdown"></div>
                          `]]

Also can anyone guide me the way to list resources ( Products in my case ) published in one particular month of the year or between two particular dates ? I see, it would be somewhere near by sortby / sortByTV or publishedon properties but am unable to achieve the results … below is my current getPage Call.

                        [[getPage?
                        &element=`getResources`
                        &parents=`[[*id]]`
                        &limit=`6`
                        &includeContent=`1`
                        &includeTVs=`1`
                        &processTVs=`1`
                        &showHidden=`1`
                        &sortby=`publishedon`
                       	&tvFilters=`[[tv.publishedon]]<<[[!getDate:date=`%Y-%m`]]` 
                        &sortdir=`DESC`
                        &tpl=`news-list`
                        &totalVar=`total`
                        &pagePrevTpl=`<li class="pagination-prev"><a href="[[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon=""></span></a></li>`
                        &pageNextTpl=`<li class="pagination-next"><a href="[[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon=""></span></a></li>`
                        &pageActiveTpl=`<li class="active" class="page-[[+pageNo]]"><span style="display: inline-block;">[[+pageNo]]</span></li>`
                        &pageNavTpl=`<li><a href="[[+href]]"><span>[[+pageNo]]</span></a></li>`
                        &pageNavOuterTpl=`[[+prev]][[+pages]][[+next]]`
                        ]]

Also, pagination is not working in the above last call.

Thanks Again,
Ronak