-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for send categories to Nosto
- Loading branch information
1 parent
7e75e9e
commit c04cd74
Showing
8 changed files
with
91 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,34 +123,52 @@ private function publishCollectionToMessageQueue( | |
); | ||
return; | ||
} | ||
$productIdsChunks = array_chunk($entityIds, $this->getBulkSize()); | ||
|
||
$bulkUuid = $this->identityService->generateId(); | ||
/** | ||
* Argument is of type string but array is expected | ||
*/ | ||
/** @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal */ | ||
$bulkDescription = __('Sync ' . count($entityIds) . ' Nosto products'); | ||
$bulkDescription = __('Sync ' . count($entityIds) . ' Nosto entities'); | ||
Check warning on line 128 in Model/Service/Sync/AbstractBulkPublisher.php
|
||
$operationsData = []; | ||
foreach ($productIdsChunks as $productIdsChunk) { | ||
$operationsData[] = $this->buildOperationData( | ||
$storeId, | ||
$productIdsChunk, | ||
$bulkUuid | ||
); | ||
|
||
// TODO: @Ugljesa Check the code. | ||
Check warning on line 131 in Model/Service/Sync/AbstractBulkPublisher.php
|
||
if (isset($entityIds['entity']) && $entityIds['entity'] === 'category') { | ||
// Process Categories. | ||
$categoryIdsChunks = array_chunk($entityIds['categoryIds'], $this->getBulkSize()); | ||
|
||
foreach ($categoryIdsChunks as $categoryIdsChunk) { | ||
$operationsData[] = $this->buildOperationData( | ||
$storeId, | ||
[], | ||
$categoryIdsChunk, | ||
$bulkUuid | ||
); | ||
} | ||
} else { | ||
// Process Products. | ||
$productIdsChunks = array_chunk($entityIds, $this->getBulkSize()); | ||
foreach ($productIdsChunks as $productIdsChunk) { | ||
$operationsData[] = $this->buildOperationData( | ||
$storeId, | ||
$productIdsChunk, | ||
[], | ||
$bulkUuid | ||
); | ||
} | ||
} | ||
|
||
$operations = []; | ||
foreach ($operationsData as $operationData) { | ||
$operations[] = $this->operationFactory->create($operationData); | ||
} | ||
|
||
if (empty($operations)) { | ||
return; | ||
} | ||
|
||
$result = $this->bulkManagement->scheduleBulk( | ||
$bulkUuid, | ||
$operations, | ||
$bulkDescription | ||
); | ||
|
||
if (!$result) { | ||
$msg = 'Something went wrong while publishing bulk to RabbitMQ. Please check your connection'; | ||
/** @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal */ | ||
|
@@ -190,17 +208,20 @@ abstract public function getMetaData(): string; | |
* Build asynchronous operation data | ||
* @param int $storeId | ||
* @param array $productIds | ||
* @param array $categoryIdsChunks | ||
* @param string $bulkUuid | ||
* @return array | ||
*/ | ||
private function buildOperationData( | ||
int $storeId, | ||
array $productIds, | ||
array $categoryIdsChunks, | ||
string $bulkUuid | ||
) { | ||
$dataToEncode = [ | ||
'meta_information' => $this->getMetaData(), | ||
'product_ids' => $productIds, | ||
'category_ids' => $categoryIdsChunks, | ||
'store_id' => $storeId | ||
]; | ||
return [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ | |
|
||
class CategoryUpdateService extends AbstractService | ||
{ | ||
const CATEGORY_SERIVCE = 'category'; | ||
|
||
/** @var NostoCategoryRepository $nostoCategoryRepository */ | ||
private NostoCategoryRepository $nostoCategoryRepository; | ||
|
||
|
@@ -113,7 +115,12 @@ public function addCollectionToUpdateMessageQueue(CategoryCollection $collection | |
); | ||
/** @var CategoryCollection $page */ | ||
foreach ($iterator as $page) { | ||
$this->upsertBulkPublisher->execute($store->getId(), $this->toParentCategoryIds($page)); | ||
$data = [ | ||
'entity' => self::CATEGORY_SERIVCE, | ||
'categoryIds' => $this->toParentCategoryIds($page) | ||
]; | ||
|
||
$this->upsertBulkPublisher->execute($store->getId(), $data); | ||
} | ||
} | ||
|
||
|
@@ -125,6 +132,7 @@ private function toParentCategoryIds(CategoryCollection $collection): array | |
{ | ||
$categoryIds = []; | ||
/** @var CategoryInterface $category */ | ||
// TODO: @ugljesa Check instanceof. | ||
Check warning on line 135 in Model/Service/Update/CategoryUpdateService.php
|
||
foreach ($collection->getItems() as $category) { | ||
try { | ||
/** @phan-suppress-next-line PhanTypeMismatchArgument */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters