Add automatically upload ICML in CRM
This commit is contained in:
parent
2b4f670b8c
commit
d872730796
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP version 5.6
|
* PHP version 5.6
|
||||||
*
|
*
|
||||||
@ -198,22 +199,23 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||||||
$codeSite = '';
|
$codeSite = '';
|
||||||
$infoApiKey = $this->apiClient->credentials();
|
$infoApiKey = $this->apiClient->credentials();
|
||||||
|
|
||||||
if (empty($infoApiKey) === false && $infoApiKey->isSuccessful() === true) {
|
if (
|
||||||
if (empty($infoApiKey['siteAccess']) === false && $infoApiKey['siteAccess'] === 'access_selective') {
|
$infoApiKey->isSuccessful()
|
||||||
if (empty($infoApiKey['sitesAvailable']) === false && count($infoApiKey['sitesAvailable']) === 1) {
|
&& !empty($infoApiKey['siteAccess'])
|
||||||
|
&& !empty($infoApiKey['sitesAvailable'])
|
||||||
|
&& $infoApiKey['siteAccess'] === 'access_selective'
|
||||||
|
&& count($infoApiKey['sitesAvailable']) === 1
|
||||||
|
) {
|
||||||
$codeSite = $infoApiKey['sitesAvailable'][0];
|
$codeSite = $infoApiKey['sitesAvailable'][0];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($codeSite) === false) {
|
if (!empty($codeSite)) {
|
||||||
$getSites = $this->apiClient->sitesList();
|
$getSites = $this->apiClient->sitesList();
|
||||||
|
|
||||||
if (empty($getSites['sites']) === false && $getSites->isSuccessful() === true) {
|
if ($getSites->isSuccessful() && !empty($getSites['sites'][$codeSite])) {
|
||||||
if (empty($getSites['sites'][$codeSite]) === false) {
|
|
||||||
$dataSite = $getSites['sites'][$codeSite];
|
$dataSite = $getSites['sites'][$codeSite];
|
||||||
|
|
||||||
if (empty($dataSite['ymlUrl']) === false) {
|
if (!empty($dataSite['ymlUrl'])) {
|
||||||
$ymlUrl = $dataSite['ymlUrl'];
|
$ymlUrl = $dataSite['ymlUrl'];
|
||||||
|
|
||||||
if (strpos($ymlUrl, 'simla') === false) {
|
if (strpos($ymlUrl, 'simla') === false) {
|
||||||
@ -225,10 +227,38 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$retailCrmIcml = new WC_Retailcrm_Icml();
|
$retailCrmIcml = new WC_Retailcrm_Icml();
|
||||||
$retailCrmIcml->generate();
|
$retailCrmIcml->generate();
|
||||||
|
|
||||||
|
$this->uploadCatalog($infoApiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add task for automatically upload catalog in CRM
|
||||||
|
*/
|
||||||
|
private function uploadCatalog($infoApiKey)
|
||||||
|
{
|
||||||
|
if ($infoApiKey->isSuccessful() && !empty($infoApiKey['scopes'])) {
|
||||||
|
if (!in_array('analytics_write', $infoApiKey['scopes'])) {
|
||||||
|
writeBaseLogs(
|
||||||
|
'To automatically load the catalog in CRM, you need to enable analytics_write for the API key'
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$statisticUpdate = $this->apiClient->statisticUpdate();
|
||||||
|
|
||||||
|
if ($statisticUpdate->isSuccessful()) {
|
||||||
|
writeBaseLogs('Catalog generated, task automatically upload added to CRM');
|
||||||
|
} else {
|
||||||
|
writeBaseLogs(
|
||||||
|
$statisticUpdate['errorMsg']
|
||||||
|
?? 'Unrecognized error when adding catalog upload task to CRM'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -548,7 +578,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||||||
/**
|
/**
|
||||||
* Return time work next cron
|
* Return time work next cron
|
||||||
*/
|
*/
|
||||||
public function get_cron_info() {
|
public function get_cron_info()
|
||||||
|
{
|
||||||
$defaultValue = __('This option is disabled', 'retailcrm');
|
$defaultValue = __('This option is disabled', 'retailcrm');
|
||||||
$icml = $defaultValue;
|
$icml = $defaultValue;
|
||||||
$history = $defaultValue;
|
$history = $defaultValue;
|
||||||
@ -724,4 +755,3 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,3 +166,14 @@ function getShippingRates()
|
|||||||
|
|
||||||
return $shippingRates['rate'] ?? $shippingRates;
|
return $shippingRates['rate'] ?? $shippingRates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write base logs in retailcrm file.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore Check in another tests
|
||||||
|
*/
|
||||||
|
function writeBaseLogs($message)
|
||||||
|
{
|
||||||
|
WC_Retailcrm_Logger::addCaller(__METHOD__, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user