Я хочу получить все товары из Square Catalog.
Вот код:
require 'vendor/autoload.php';
use Square\SquareClient;
use Square\LocationsApi;
use Square\Exceptions\ApiException;
use Square\Http\ApiResponse;
use Square\Models\ListLocationsResponse;
use Square\Environment;
$client = new SquareClient([
'accessToken' => '{{access_token}}',
'environment' => Environment::SANDBOX,
]);
//Providing SKU
$object_ids = ['GFLR20L', '232GGGD'];
$body = new \Square\Models\BatchRetrieveCatalogObjectsRequest($object_ids);
$body->setIncludeRelatedObjects(true);
$api_response = $client->getCatalogApi()->batchRetrieveCatalogObjects($body);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}
Вывод:
object(Square\Models\BatchRetrieveCatalogObjectsResponse)#13 (3)
{
["errors":"Square\Models\BatchRetrieveCatalogObjectsResponse":private] => NULL
["objects":"Square\Models\BatchRetrieveCatalogObjectsResponse":private] => NULL
["relatedObjects":"Square\Models\BatchRetrieveCatalogObjectsResponse":private] => NULL
}
**> Предложения по размещению sjosey:
Мой PHP Код:
Ищу товары с названием Paper. **
$object_types = ['ITEM'];
$prefix_query = new \Square\Models\CatalogQueryPrefix('name', 'paper');
$query = new \Square\Models\CatalogQuery();
$query->setPrefixQuery($prefix_query);
> Сохранение значений здесь
$body = new \Square\Models\SearchCatalogObjectsRequest();
$body->setObjectTypes($object_types);
$body->setQuery($query);
$body->setLimit(100);
$api_response = $client->getCatalogApi()->searchCatalogObjects($body);
> Получение ответа API здесь
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}
> Результат эха
var_dump($result);
Вот результат:
object(Square\Models\SearchCatalogObjectsResponse)#15 (5) { ["errors":"Square\Models\SearchCatalogObjectsResponse":private]=> NULL ["cursor":"Square\Models\SearchCatalogObjectsResponse":private]=> NULL ["objects":"Square\Models\SearchCatalogObjectsResponse":private]=> NULL ["relatedObjects":"Square\Models\SearchCatalogObjectsResponse":private]=> NULL ["latestTime":"Square\Models\SearchCatalogObjectsResponse":private]=> string(20) "1776-07-04T00:00:00Z" }