Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add the filter so that API call is returning just the results that I want?

Tags:

php

filter

akeneo

This is what I got so far, but it doesn't work.

public function getCompleteness(){
    $searchBuilder = new AkeneoSearchBuilder();
    $searchBuilder->addFilter('completeness', '=', 100);

    try {
        $products = $this->apiClient->getProductApi()->all(
            50,
            [
                'search' => $searchBuilder->getFilters(),
                'scope' => 'ecommerce'
            ]
        );
    } catch (HttpException $e){
        echo "Message: " . $e->getMessage();
        echo "Code: " . $e->getCode();
    }

    return $products;
}

}

This is the call that I am trying to use from Akeneo API.

{{url}}/api/rest/v1/products?search={"completeness":[{"operator":"=","value":100,"scope":"ecommerce"}]}

How can I use GetCompleteness() method in order that it produces some results ? I have problem with using AkeneoSearchBuilder();

like image 440
FortuneSoldier Avatar asked Jan 19 '26 14:01

FortuneSoldier


1 Answers

When you do:

$searchBuilder = new AkeneoSearchBuilder();
$searchBuilder->addFilter('completeness', '=', 100);
$products = $this->apiClient->getProductApi()->all(
    50,
    [
        'search' => $searchBuilder->getFilters(),
        'scope' => 'ecommerce'
    ]
);

It basically means: "For all products complete on scope "undefined", give me all their "ecommerce" values".

What you are trying to achieve is (I guess): "For all products complete on scope "ecommerce", give me all their values".

As you can read on the official documentation about completeness filter, you need to specify a scope:

$searchBuilder = new AkeneoSearchBuilder();
$searchBuilder->addFilter('completeness', '=', 100, ['scope' => 'ecommerce']);

Now you can retrieve their values, by calling:

$products = $this->apiClient->getProductApi()->all(
    50,
    [
        'search' => $searchBuilder->getFilters()
    ]
);

Note that I removed the "scope" parameter here.

To resume:

  • You need to specify a scope when filtering by completeness
  • The scope parameter on the query is to retrieve only values of this scope
like image 125
grena Avatar answered Jan 22 '26 02:01

grena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!