简体   繁体   中英

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

We created a plugin and now we want to get selected fields only on the response, to minimize the response payload.

We are aware that criteria "includes" will help based on the URL https://developer.shopware.com/docs/guides/integrations-api/general-concepts/search-criteria

In the Array of $criteria we can see what "includes" is added like filter but does not give the selected fields

Please help what I am doing wrong?

EXample

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);

I have tried

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

The includes collection is only used when serializing the objects for the response json, as you can find in the JsonApiEncoder . It's not in effect when fetching mapped objects internally, as it could lead to conflicts with only partially mapped objects. You could of course just use the JsonApiEncoder internally to encode a collection of entities to receive a response object including a subset of the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM