【问题标题】:Filter products by category in a Shopware 6 Import/Export Profile在 Shopware 6 导入/导出配置文件中按类别过滤产品
【发布时间】:2022-11-10 22:13:06
【问题描述】:

我使用 api 在 shopware 6 中创建了一个配置文件。 请求的正文是:

{
  "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}
}

有没有办法指定我只想要某些类别的产品?不是所有的人

【问题讨论】:

    标签: shopware6 shopware6-api shopware6-app


    【解决方案1】:

    不,目前仅使用配置文件和现有端点是不可能的。您必须实现自定义 api 端点。

    如果您能够做到这一点,请按照this answer 中的步骤操作,直到您第一次检索到logId。然后,不要使用现有端点启动流程,而是请求新的自定义端点。实现可能与此类似:

    /**
     * @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]);
        }
    }
    

    调用您的自定义端点后,继续执行上面链接的答案中描述的步骤。

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 2022-01-04
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2011-01-20
      相关资源
      最近更新 更多