shopwareshopware6shopware6-apishopware6-app

Filter order search result


Is it possible to filter a search result and only get the orders back, that have a document entity set and these are only for the technical name "invoice" and "credit_note"? Thats what I tried but its not working properly:

data: {
    associations: {
      documents: {
          associations: {
              documentType: {
                filter: [
                  {
                    type: "equals",
                    field: "technicalName",
                    value: 'invoice'
                  },
                  {
                    type: "equals",
                    field: "technicalName",
                    value: 'credit_note'
                  }
                ]
              }
          }
      }
    },
    includes: {
      order: [ 'orderNumber', 'documents' ]
    }
}

I dont see that any filters mentioned in the docs would fit that criterium or am I missing something?


Solution

  • Having the filter on the association like that only means that the collection belonging the association is filtered, not the overall result set. You need to set the filter directly on the root entity.

    {
        "filter": [
            { 
                "type": "multi",   
                "operator": "or",
                "queries": [
                    {
                        "type": "equals",
                        "field": "documents.documentType.technicalName",
                        "value": "invoice"
                    },
                    {
                        "type": "equals",
                        "field": "documents.documentType.technicalName",
                        "value": "credit_note"
                    }
                ]
            }
        ]
    }