Files
ltsecurityinc/app/code/JR/NetSuite/Service/LocationsSyncService.php
T

70 lines
1.8 KiB
PHP
Executable File

<?php
namespace JR\NetSuite\Service;
class LocationsSyncService
{
protected $logger;
protected $helper;
protected $netSuiteAPI;
protected $locationResourceModel;
/**
* @param \JR\NetSuite\Logger\Logger $logger
* @param \JR\NetSuite\Helper\Data $helper
* @param \JR\NetSuite\Lib\NetSuiteAPI $netSuiteAPI
* @param \JR\NetSuite\Model\ResourceModel\Location $locationResourceModel
*/
public function __construct(
\JR\NetSuite\Logger\Logger $logger,
\JR\NetSuite\Helper\Data $helper,
\JR\NetSuite\Lib\NetSuiteAPI $netSuiteAPI,
\JR\NetSuite\Model\ResourceModel\Location $locationResourceModel
) {
$this->logger = $logger;
$this->helper = $helper;
$this->netSuiteAPI = $netSuiteAPI;
$this->locationResourceModel = $locationResourceModel;
}
/**
* @return array
*/
public function sync()
{
$result = [
'error' => false,
'message' => 'Locations saved successfully.'
];
$this->logger->info('Start Locations Sync');
$this->logger->info('Fetching locations from NetSuite');
$locations = $this->netSuiteAPI->fetchLocations();
if (isset($locations['error'])) {
$result['error'] = true;
$result['message'] = $locations['message'];
$this->logger->info('Error while fetching locations from NetSuite: ' . $locations['message']);
return $result;
}
$this->logger->info('Locations fetched successfully');
$this->logger->info('Start saving locations');
$this->locationResourceModel->saveLocations($locations['data']);
$this->logger->info('Locations saved successfully');
$this->logger->info('End Locations Sync');
return $result;
}
}