ltsecurityinc安防产品在线商城代码
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user