簡體   English   中英

Shopware 6 Plugin Api 獲取帶有選定字段的產品數據以減少響應負載

[英]Shopware 6 Plugin Api get Product data with selected field to reduce response payload

我們創建了一個插件,現在我們只想在響應中獲取選定的字段,以最小化響應負載。

我們知道標准“包括”將根據 URL https://developer.shopware.com/docs/guides/integrations-api/general-concepts/search-criteria有所幫助

$criteria數組中,我們可以看到像過濾器一樣添加了“包含”,但沒有給出所選字段

請幫助我做錯了什么?

例子

use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
$Criteria = new Criteria();
$Criteria->addFilter(new EqualsFilter('id', $productId));
$Criteria->setIncludes(array('product-alias' => array('name')));
$productRepo = $this->productRepository->search($Criteria, $context);

我努力了

$Criteria->setIncludes(array('product' => array('name')));
$Criteria->setIncludes(array('name'));

includes集合僅在序列化響應 json 的對象時使用,您可以在JsonApiEncoder中找到。 它在內部獲取映射對象時無效,因為它可能導致僅與部分映射對象發生沖突。 您當然可以在內部使用JsonApiEncoder對實體集合進行編碼,以接收包含數據子集的響應 object。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM