T
T
thisuser2018-02-02 12:04:14
MODX
thisuser, 2018-02-02 12:04:14

How to select from two categories through pdoResources?

Tortured to make the conditions of the sample.
It is required to select all resources from the parent + another category, the value of the tv-parameter of the children of which will be the id of the current resource) The example should make it clearer:

{'!mFilter2' | snippet : [
    'parents' => '2, 100', // родителем будет текущий ресурс и ещё ресурс с id = 100
    'suggestions' => 0,
    'limit' => 10,
    'includeTVs' => 'price, spec', // интересует spec
    'tplPageWrapper' => '@INLINE <div class="mypagination"><ul></ul></div>', 
    
    'sortby' => ,
]}

By default, the value of the spec parameter tv is 0 . In resources with a parent (id=100), the value of this parameter is one of 2.
That is, for example, on a page with id = 500, I need to select all children (spec==0) and also add all children from the resource with id=100, whose spec value will be 500 )
I tried a lot. For example , it did nothing. Also, I tried: - also by. Can you please tell me how to implement this condition? Thanks to. 'tvFilters' => 'spec==2||spec==0','where' => '{"spec":0, "OR:spec":2}'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thisuser, 2018-02-02
@thisuser

It seems to have overcome the problem.
Long and persistent googling suggested that leftJoin would be indispensable. As a result, the following code was born:

{'!mFilter2' | snippet : [
    'parents' => '2, 100', // Из текущего + 100
    'suggestions' => 0,
    'limit' => 10,
    'includeTVs' => 'price, spec',
    'tplPageWrapper' => '@INLINE <div class="pagination p10"><ul></ul></div>',
    
    'leftJoin' => '{
    	"spec": {
    	    "class":"modTemplateVarResource"
    	    ,"alias":"spec"
    		,"on": "modResource.id = spec.contentid AND spec.tmplvarid = 62"
    	}
    }',
    // Либо spec не указан (что сделано в дочерних ресурсах текущего), либо spec = id текужего ресурса (а может и нескольких)
    'where' => '["(`spec`.`value` IS NULL OR `spec`.`value` IN (2))"]' 
]}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question