Add pagination handle to xml requests
This commit is contained in:
parent
16c45753f5
commit
7f3a11c796
@ -12,6 +12,11 @@ class MoySkladICMLParser
|
||||
*/
|
||||
const TIMEOUT = 20;
|
||||
|
||||
/**
|
||||
* Шаг для выгрузки элементов в API
|
||||
*/
|
||||
const STEP = 1000;
|
||||
|
||||
/**
|
||||
* Адрес для запроса товарных групп
|
||||
*/
|
||||
@ -155,9 +160,15 @@ class MoySkladICMLParser
|
||||
$ignoreInfo = $this->getIgnoreProductGroupsInfo();
|
||||
$ignoreUuids = $ignoreInfo[self::UUIDS]; // сюда будут агрегироваться uuid для игнора с учетом вложеностей
|
||||
|
||||
$xml = $this->requestXml(self::GROUP_LIST_URL);
|
||||
$start = 0;
|
||||
$total = 0;
|
||||
do {
|
||||
$xml = $this->requestXml(self::GROUP_LIST_URL.'?'.http_build_query(['start' => $start]));
|
||||
|
||||
if ($xml) {
|
||||
|
||||
$total = $xml[0]['total'];
|
||||
|
||||
foreach ($xml->goodFolder as $goodFolder) {
|
||||
$uuid = (string) $goodFolder->uuid;
|
||||
$externalCode = (string) $goodFolder->externalcode;
|
||||
@ -190,8 +201,13 @@ class MoySkladICMLParser
|
||||
|
||||
$categories[$uuid] = $category;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('No xml');
|
||||
}
|
||||
|
||||
$start += self::STEP;
|
||||
} while ($start < $total);
|
||||
|
||||
$result = array();
|
||||
$this->sortGroupTree($result, $categories);
|
||||
|
||||
@ -207,16 +223,26 @@ class MoySkladICMLParser
|
||||
{
|
||||
$vendors = array();
|
||||
|
||||
$xml = $this->requestXml(self::COMPANY_LIST_URL);
|
||||
$start = 0;
|
||||
$total = 0;
|
||||
do {
|
||||
$xml = $this->requestXml(self::COMPANY_LIST_URL.'?'.http_build_query(['start' => $start]));
|
||||
|
||||
if ($xml) {
|
||||
$total = $xml[0]['total'];
|
||||
|
||||
foreach ($xml->company as $c) {
|
||||
$uuid = (string) $c->uuid;
|
||||
$name = (string) $c[0]['name'];
|
||||
$vendors[$uuid] = $name;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('No xml');
|
||||
}
|
||||
|
||||
$start += self::STEP;
|
||||
} while ($start < $total);
|
||||
|
||||
return $vendors;
|
||||
}
|
||||
|
||||
@ -233,8 +259,13 @@ class MoySkladICMLParser
|
||||
) {
|
||||
$products = array();
|
||||
|
||||
$xml = $this->requestXml(self::PRODUCT_LIST_URL);
|
||||
$start = 0;
|
||||
$total = 0;
|
||||
do {
|
||||
$xml = $this->requestXml(self::PRODUCT_LIST_URL.'?'.http_build_query(['start' => $start]));
|
||||
if ($xml) {
|
||||
$total = $xml[0]['total'];
|
||||
|
||||
foreach ($xml->good as $v) {
|
||||
|
||||
$parentUuid = isset($v[0]['parentUuid']) ?
|
||||
@ -259,11 +290,21 @@ class MoySkladICMLParser
|
||||
'offers' => array(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('No xml');
|
||||
}
|
||||
|
||||
$start += self::STEP;
|
||||
} while ($start < $total);
|
||||
|
||||
$start = 0;
|
||||
$total = 0;
|
||||
do {
|
||||
if (!$this->isIgnoreOffers()) {
|
||||
$xml = $this->requestXml(self::OFFER_LIST_URL);
|
||||
$xml = $this->requestXml(self::OFFER_LIST_URL.'?'.http_build_query(['start' => $start]));
|
||||
if ($xml) {
|
||||
$total = $xml[0]['total'];
|
||||
|
||||
foreach ($xml->consignment as $c) {
|
||||
// если нет feature, то товар без торговых предложений
|
||||
if (!isset($c->feature)) {
|
||||
@ -283,9 +324,14 @@ class MoySkladICMLParser
|
||||
// иначе это не товар а услуга (service)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('No xml');
|
||||
}
|
||||
}
|
||||
|
||||
$start += self::STEP;
|
||||
} while ($start < $total);
|
||||
|
||||
// для товаров без торговых преложений
|
||||
foreach ($products as $key1 => &$product) {
|
||||
// если нет торговых предложений
|
||||
|
Loading…
x
Reference in New Issue
Block a user