prestashop-module/retailcrm/lib/RetailcrmInventories.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2019-01-18 15:56:22 +03:00
<?php
class RetailcrmInventories
{
public static $api;
2019-01-21 14:42:19 +03:00
2019-01-18 15:56:22 +03:00
/**
* Load stock from retailCRM
*
* @return mixed
*/
2019-01-21 14:42:19 +03:00
public static function loadStocks()
{
2019-01-18 15:56:22 +03:00
$page = 1;
do {
$result = self::$api->storeInventories(array(), $page, 250);
2019-01-21 14:42:19 +03:00
if ($result === false) {
return $result;
2019-01-18 15:56:22 +03:00
}
foreach ($result['offers'] as $offer) {
2019-01-21 14:42:19 +03:00
self::setQuantityOffer($offer);
2019-01-18 15:56:22 +03:00
}
2019-01-21 14:42:19 +03:00
$totalPageCount = $result['pagination']['totalPageCount'];
$page++;
} while ($page <= $totalPageCount);
2019-01-18 15:56:22 +03:00
}
2019-01-21 14:42:19 +03:00
private static function setQuantityOffer($offer)
{
if (isset($offer['externalId'])) {
$invOffer = explode('#', $offer['externalId']);
2019-01-18 15:56:22 +03:00
2019-01-21 14:42:19 +03:00
if (isset($invOffer[1])) {
StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']);
} else {
StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']);
}
}
2019-01-18 15:56:22 +03:00
}
}