Skip to content

Commit

Permalink
Merge pull request #11 from commercetools/fix-full-ingestion
Browse files Browse the repository at this point in the history
Fix missing store key in full-ingestion module
  • Loading branch information
leungkinghin-ct authored Sep 14, 2023
2 parents 5ea830f + aea1a61 commit 54b3b1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions full-ingestion/src/clients/query.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const queryArgs = {
expand: ['productSelection', 'taxCategory', 'productType', 'categories[*]'],
};

export async function getProductProjectionInStoreById(productId) {
export async function getProductProjectionInStoreById(storeKey, productId) {
return await createApiRoot()
.inStoreKeyWithStoreKeyValue({
storeKey: Buffer.from(process.env.CTP_STORE_KEY).toString(),
storeKey: Buffer.from(storeKey).toString(),
})
.productProjections()
.withId({
Expand All @@ -24,7 +24,7 @@ export async function getProductProjectionInStoreById(productId) {
.then((response) => response.body);
}

export async function getProductsInCurrentStore() {
export async function getProductsInCurrentStore(storeKey) {
let lastProductId = undefined;
let hasNextQuery = true;
let allProducts = [];
Expand All @@ -36,7 +36,7 @@ export async function getProductsInCurrentStore() {

let productChunk = await createApiRoot()
.inStoreKeyWithStoreKeyValue({
storeKey: Buffer.from(process.env.CTP_STORE_KEY).toString(),
storeKey: Buffer.from(storeKey).toString(),
})
.productSelectionAssignments()
.get({ queryArgs })
Expand Down
5 changes: 3 additions & 2 deletions full-ingestion/src/controllers/sync.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
HTTP_STATUS_SUCCESS_NO_CONTENT,
} from '../constants/http.status.constants.js';

async function syncProducts() {
async function syncProducts(storeKey) {
let productsToBeSynced = [];
const products = await getProductsInCurrentStore();
const products = await getProductsInCurrentStore(storeKey);

//Clean up search index before full sychronization
const productIdsToBeRemoved = products.map((product) => product.id);
Expand All @@ -26,6 +26,7 @@ async function syncProducts() {
for (let productInCurrentStore of products) {
let productToBeSynced = undefined;
productToBeSynced = await getProductProjectionInStoreById(
storeKey,
productInCurrentStore.id
).catch(async (error) => {
// Product cannot be found in store assignment. Need to remove product in external search index
Expand Down

0 comments on commit 54b3b1e

Please sign in to comment.