Added skipping product\offer in ICML if filter result is an empty array. Added skipping segments' changes in back sync

This commit is contained in:
max-baranikov 2022-09-09 10:59:25 +03:00 committed by GitHub
parent 1861b5255a
commit 7ade3ca00b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 30 deletions

View File

@ -295,7 +295,7 @@ class RetailcrmCatalog
unset($arComb); unset($arComb);
yield RetailcrmTools::filter( $item = RetailcrmTools::filter(
'RetailcrmFilterProcessOffer', 'RetailcrmFilterProcessOffer',
$item, $item,
[ [
@ -303,6 +303,10 @@ class RetailcrmCatalog
'offer' => $offer, 'offer' => $offer,
] ]
); );
if ([] !== $item) {
yield $item;
}
} }
} else { } else {
++$offersCount; ++$offersCount;
@ -316,32 +320,34 @@ class RetailcrmCatalog
$quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product']); $quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product']);
} }
$item = [ $item = RetailcrmTools::filter(
'id' => $product['id_product'],
'productId' => $product['id_product'],
'productActivity' => ($available_for_order) ? 'Y' : 'N',
'name' => htmlspecialchars(strip_tags($product['name'])),
'productName' => htmlspecialchars(strip_tags($product['name'])),
'categoryId' => $categoriesLeft,
'picture' => $pictures,
'url' => $url,
'quantity' => 0 < $quantity ? $quantity : 0,
'purchasePrice' => round($purchasePrice, 2),
'price' => $price,
'vendor' => $vendor,
'article' => $article,
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
];
yield RetailcrmTools::filter(
'RetailcrmFilterProcessOffer', 'RetailcrmFilterProcessOffer',
$item, [
'id' => $product['id_product'],
'productId' => $product['id_product'],
'productActivity' => ($available_for_order) ? 'Y' : 'N',
'name' => htmlspecialchars(strip_tags($product['name'])),
'productName' => htmlspecialchars(strip_tags($product['name'])),
'categoryId' => $categoriesLeft,
'picture' => $pictures,
'url' => $url,
'quantity' => 0 < $quantity ? $quantity : 0,
'purchasePrice' => round($purchasePrice, 2),
'price' => $price,
'vendor' => $vendor,
'article' => $article,
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
],
[ [
'product' => $product, 'product' => $product,
] ]
); );
if ([] !== $item) {
yield $item;
}
} }
} }

View File

@ -120,6 +120,8 @@ class RetailcrmHistory
} else { } else {
self::createCustomerInPrestashop($customerHistory); self::createCustomerInPrestashop($customerHistory);
} }
} catch (Error $e) {
continue;
} catch (Exception $e) { } catch (Exception $e) {
continue; continue;
} }
@ -811,7 +813,16 @@ class RetailcrmHistory
$organizedHistory = []; $organizedHistory = [];
$notOurChanges = []; $notOurChanges = [];
$fieldsToSkip = ['segments'];
$fieldsToKeep = ['externalId', 'status'];
foreach ($historyEntries as $entry) { foreach ($historyEntries as $entry) {
$field = $entry['field'];
if (in_array($field, $fieldsToSkip)) {
continue;
}
if (!isset($entry[$recordType]['externalId'])) { if (!isset($entry[$recordType]['externalId'])) {
if ('api' == $entry['source'] if ('api' == $entry['source']
&& isset($change['apiKey']['current']) && isset($change['apiKey']['current'])
@ -827,7 +838,6 @@ class RetailcrmHistory
} }
$externalId = $entry[$recordType]['externalId']; $externalId = $entry[$recordType]['externalId'];
$field = $entry['field'];
if (!isset($organizedHistory[$externalId])) { if (!isset($organizedHistory[$externalId])) {
$organizedHistory[$externalId] = []; $organizedHistory[$externalId] = [];
@ -841,7 +851,7 @@ class RetailcrmHistory
&& isset($entry['apiKey']['current']) && isset($entry['apiKey']['current'])
&& true == $entry['apiKey']['current'] && true == $entry['apiKey']['current']
) { ) {
if (isset($notOurChanges[$externalId][$field]) || 'externalId' == $field || 'status' == $field) { if (isset($notOurChanges[$externalId][$field]) || in_array($field, $fieldsToKeep)) {
$organizedHistory[$externalId][] = $entry; $organizedHistory[$externalId][] = $entry;
} }
} else { } else {

View File

@ -412,7 +412,7 @@ class RetailcrmJobManager
*/ */
private static function setLastRunDetails($lastRuns = []) private static function setLastRunDetails($lastRuns = [])
{ {
RetailcrmLogger::writeCaller(__METHOD__ . ':before', json_encode($lastRuns)); RetailcrmLogger::writeDebug(__METHOD__ . ':before', json_encode($lastRuns));
if (!is_array($lastRuns)) { if (!is_array($lastRuns)) {
$lastRuns = []; $lastRuns = [];
} }
@ -425,7 +425,7 @@ class RetailcrmJobManager
} }
} }
RetailcrmLogger::writeCaller(__METHOD__ . ':after', json_encode($lastRuns)); RetailcrmLogger::writeDebug(__METHOD__ . ':after', json_encode($lastRuns));
Configuration::updateGlobalValue(self::LAST_RUN_DETAIL_NAME, (string) json_encode($lastRuns)); Configuration::updateGlobalValue(self::LAST_RUN_DETAIL_NAME, (string) json_encode($lastRuns));
} }

View File

@ -66,7 +66,7 @@ class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements Reta
} }
$reference = new RetailcrmReferences($api); $reference = new RetailcrmReferences($api);
$site = $reference->getSite(); $site = $reference->getSite(); // todo remove duplicated code
if (empty($site)) { if (empty($site)) {
continue; continue;
} }

View File

@ -136,7 +136,7 @@ class RetailcrmSettingsHelper
if (null !== $api) { if (null !== $api) {
$reference = new RetailcrmReferences($api); $reference = new RetailcrmReferences($api);
$site = $reference->getSite(); $site = $reference->getSite(); // todo remove duplicated code
$icmlInfo['isUrlActual'] = !empty($site['ymlUrl']) $icmlInfo['isUrlActual'] = !empty($site['ymlUrl'])
&& $site['ymlUrl'] === RetailcrmCatalogHelper::getIcmlFileLink(); && $site['ymlUrl'] === RetailcrmCatalogHelper::getIcmlFileLink();
if (!empty($site['catalogId'])) { if (!empty($site['catalogId'])) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long