How to Filter Products In Shopware 6 Import & Export
Data filtering is a handy improvement to standard import and export processes. It helps you transfer only the necessary information without additional manual editing. As a result, your standard import and export workflow is dramatically improved. While different e-commerce platforms offer different filtering options, Shopware 6 provides fairly limited opportunities in this area. Below, we shed light on how to filter products in Shopware 6 import and export. We explore a
Table of contents
Shopware 6 Import & Export Profiles
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "id": "my99id2cb2784069938089a8a77ctest", "label": "Label test", "name": "name test", "sourceEntity": "product", "fileType": "text/csv", "delimiter": ";", "enclosure": "\"", "createdAt": "2022-11-10T10:15:22Z", "mapping": [{"key":"id","mappedKey":"id","position":0,"id":"someid4f7c6c478b8041cfd5fe0ae0c5"},{"key":"cover.media.url","mappedKey":"cover","position":1,"id":"someid0ffa7f48e6b135f6e754d6b93c"}], "config": {"createEntities": false, "updateEntities": true} } |
Shopware 6 profile and existing endpoint limitations
According to
Custom API endpoints
However, it is possible to overcome the existing limitations by using a custom API endpoint.
You’ll have to implement a custom API endpoint.
Use your admin API credentials to request the following endpoints in that order with the respective payloads:
1 2 3 4 5 |
POST /api/_action/import-export/prepare { "profileId": "...", "expireDate": "2022-12-12 12:00:00" } |
Where:
- profileId is the id of the profile you want to use for exporting.
- expireDate is a date after which the export would be deemed expired and ready to be deleted.
- file is a parameter that contains the file you’re trying to import, but since you want to export you just omit it.
This endpoint returns logId required in the next step.
1 2 3 4 |
POST /api/_action/import-export/process { "logId": "..." } |
Request this endpoint with the logId from the prior request to start export/import. Since it runs in the message queue, you’ll have to wait for the process to finish.
1 2 3 4 5 6 7 8 9 10 |
POST /api/search/import-export-log { "filter": [ { "type": "equals", "field": "id", "value": "..." } ] } |
Next, you can utilize the search endpoint for the import_export_log entities with the logId you received previously as a filter. Do so to check the state of the process. You will be able to proceed once it is finished. You’ll also need the fileId from this record for the download.
1 |
POST /api/_action/import-export/file/prepare-download/{fileId} |
Use the fileId to request this endpoint. You will get accessToken in return necessary for the final request.
1 |
GET /api/_action/import-export/file/download?accessToken=...&fileId=... |
Streamline both fileId and accessToken from earlier to request this endpoint which should yield a download stream of the exported file.
However, if you want to implement filters for Shopware 6 export, you will need to request your new custom endpoint instead of starting the process using the existing endpoint when you first retrieve logId. The implementation could look as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/** * @Route(defaults={"_routeScope"={"api"}}) */ class CustomExportApiController extends AbstractController { private ImportExportFactory $importExportFactory; public function __construct(ImportExportFactory $importExportFactory) { $this->importExportFactory = $importExportFactory; } /** * @Route("/api/_action/custom/export/{logId}/{categoryId}", name="api.action.custom.export", methods={"POST"}) */ public function customProductExport(string $logId, string $categoryId, Context $context): JsonResponse { $importExport = $this->importExportFactory->create($logId, 50, 50); $logEntity = $importExport->getLogEntity(); if ($logEntity->getState() === Progress::STATE_ABORTED) { return new JsonResponse(['success' => false]); } $criteria = new Criteria(); $criteria->addFilter(new EqualsAnyFilter('categoryTree', [$categoryId])); $offset = 0; do { $progress = $importExport->export($context, $criteria, $offset); $offset = $progress->getOffset(); } while (!$progress->isFinished()); return new JsonResponse(['success' => true]); } } |
After calling your custom endpoint proceed with the steps described earlier.
Custom API endpoint limitation
Unfortunately, this method doesn’t work for everyone. If you are going to build an app, it won’t work simply because you won’t be able to create the controller. So, how to address this issue?
Firebear’s Import and Export Filters and Conditions
Our team has a vast experience in data transfers. We started as a Magento company and then moved to new directions, using the existing experience. And export filters were among the important features of our Improved Import & Export extension. With the module’s help, you can quickly narrow down the selection of items you want to export. At the same time, it could possibly filter out a massive data scope to help you import only those items that you really need. Let’s take a look at the import and export filtering capabilities separately. Bear in mind, that we can help you implement similar features in the Improved Import, Export, and Mass Actions app for Shopware 6. Contact us for more information.
How to create Shopware 6 export filters
You can use the Improved Import, Export & Mass Actions application for Shopware 6 to extend the default data transfer capabilities of the platform. Although this solution doesn’t use filters, we describe how a basic export filter works in Magento 2. However, we can implement something similar for Shopware 6.
In Magento, you can get the export filtering done as follows:
- Create a new export profile and proceed to the filter tab. Click the ‘Add Filter’ button there;
- Select an entity chosen in the ‘Export Behaviour’ section;
- Next, specify a basis for a new filter. Select a system attribute in the ‘Field’ column. It will be used to narrow down the selection of exported items;
- After that, specify the parameters that will be applied for filtering.
Now, you can repeat these steps to create more filters. Note that parameters applied for filtering vary, depending on the selected attribute.
The following gif image illustrates how to narrow down the selection of exported orders by applying a filter on the basis of their subtotal.
Select ‘Orders’ in the ‘Entity’ column, specify the ‘subtotal’ attribute in the ‘Field’ column, and set a range in ‘Filter’.
Contact us regarding the implementation of similar export filters for Shopware 6.
How to create Shopware 6 import filters
Import filters address a slightly distinct set of challenges. The issue is that because third-party systems employ specific attribute standards, you cannot just take any data file and build filters and conditions based on external attributes.
It isn’t even a feature that is very demanding, though. Therefore, we haven’t implemented it in the Improved Import & Export extension yet, not to mention the Improved Import, Export & Mass Actions application for Shopware 6. While the module offers robust mapping capabilities, it doesn’t let you use filters on import. But if there are enough clients willing to implement this functionality, we will add this feature to our update schedule.
To get more information about Shopware 6 import filters and conditions, please, contact our help center. Use the following link: Firebear Help Center.
Other Advanced Import & Export Features for Shopware 6
The Improved Import, Export, & Mass Actions application enables you to address the most frequent problems with Shopware 6 data transfers. Thanks to the full support for product properties, you can not only manage your catalog quickly in a spreadsheet editor and re-import it, but you can also automate various repetitive tasks related to data transfers. The following are additional key benefits of our app:
- Product import and export with full support for properties (attributes);
- Customer import and export with full support for addresses;
- Orders export;
- Full support for product variants with a full set of attributes;
- Product properties mapping with mapping presets;
- Import and export schedules;
- Import and export of CSV, XLSX, and XLSX files;
- Direct file uploads;
- FTP/FTPS uploads.
You can find more information about the Improved Import, Export & Mass Actions app here:
- Improved Import, Export & Mass Actions application for Shopware 6
- Improved Import, Export & Mass Actions Manual