Closed Maxtab closed 1 year ago
Maybe related to this #33 ?
Hello @Maxtab,
The problem is the method set()
who doesn't exist on request objects. You should use setMax()
and setOffset()
methods.
In your exemple, I think you retrieve the 10 first offers 7 or 8 times.
Here another way to write your exemple:
$api = new ShopApiClient($apiUrl, $apiKey, $shopId);
function fetchAllOffers(ShopApiClient $api, $shopId) {
$allOffers = [];
$offset = 0;
$max = 100; // Max query results
$totalOffersCount = 0; // Initialiser à 0
do {
$request = new GetOffersRequest($shopId);
$request->setMax($max);
$request->setOffset($offset);
$response = $api->getOffers($request);
// Get the total offers count
$totalOffersCount = $response->getTotalCount();
$offers = $response->getItems();
$allOffers = array_merge($allOffers, $offers);
$offset += $max;
} while (count($allOffers) < $totalOffersCount);
return $allOffers;
}
function displayOffers($allOffers) {
echo '<table border="1">';
echo '<tr><th>SKU</th></tr>';
foreach ($allOffers as $offer) {
echo '<tr>';
echo '<td>' . $offer->getSku() . '</td>';
echo '</tr>';
}
echo '</table>';
}
try {
$allOffers = fetchAllOffers($api, $shopId);
displayOffers($allOffers);
} catch (ClientException $e) {
echo 'Error : ' . $e->getMessage();
}
Hi @amarie75 , You are right, thank you for your help, this indeed solves the problem. Sorry to have missed that!
Hello.
Thank you for the SDK for which I took care to read the documentation, but I am facing an issue regarding the use of the API OF21: List offers of a shop. I use the PHP SDK in version 1.18.1
I want to retrieve all the offers from my shop (there are around 700) to store them once a day in a database on my side (and thus not systematically call the marketplace API). In particular, I need to access the Offers > Active and _Offers > Inactivityreasons information that is not found in the API OF51 Get offers CSV file.
I'm using the PHP SDK so I understand there is a limit to the number of results returned, but I don't see a way to handle pagination when using the SDK getOffers function
How to proceed to be able to retrieve and store on my side the list of all the offers via this API OF21, because I don't see anything about the possibility of using pagination in the getOffers function (expected parameters in particular)?
Thank you for your help.
For reference, here's, in a simplified way, what I was headed for