diff --git a/retail/interactive-tutorials/product/add-fulfillment-places.js b/retail/interactive-tutorials/product/add-fulfillment-places.js index c92637a73d..edb138f3d0 100644 --- a/retail/interactive-tutorials/product/add-fulfillment-places.js +++ b/retail/interactive-tutorials/product/add-fulfillment-places.js @@ -27,23 +27,21 @@ async function main(generatedProductId) { // Create product const createdProduct = await utils.createProduct( projectId, - generatedProductId + generatedProductId, + true ); // Full resource name of Product const product = createdProduct.name; // The fulfillment type, including commonly used types (such as - // pickup in store and same day delivery), and custom types. + // pickup in store and same-day delivery), and custom types. const type = 'same-day-delivery'; // The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for // "same-day-delivery" to be added for this type. const placeIds = ['store1', 'store2', 'store3']; - // The time when the fulfillment updates are issued, used to prevent - // out-of-order updates on fulfillment information. - //If set to true, and the product is not found, the fulfillment information will still be processed and retained for // at most 1 day and processed once the product is created const allowMissing = true; @@ -57,16 +55,18 @@ async function main(generatedProductId) { allowMissing, }; + // To send an out-of-order request assign the invalid addTime here: + // request.addTime = {seconds: Math.round(Date.now() / 1000) - 86400}; + console.log('Add fulfillment request:', request); + console.log('Waiting to complete add operation...'); // Run request const [operation] = await retailClient.addFulfillmentPlaces(request); await operation.promise(); - - console.log('Waiting to complete add operation..'); }; - // Add fulfillment places with current time + // Add fulfillment places console.log('Start add fulfillment'); await calladdFulfillmentPlaces(); diff --git a/retail/interactive-tutorials/product/remove-fulfillment-places.js b/retail/interactive-tutorials/product/remove-fulfillment-places.js index 8264fcceac..75adf40bbe 100644 --- a/retail/interactive-tutorials/product/remove-fulfillment-places.js +++ b/retail/interactive-tutorials/product/remove-fulfillment-places.js @@ -35,16 +35,13 @@ async function main(generatedProductId) { const product = createdProduct.name; // The fulfillment type, including commonly used types (such as - // pickup in store and same day delivery), and custom types. + // pickup in store and same-day delivery), and custom types. const type = 'same-day-delivery'; // The IDs for this type, such as the store IDs for "pickup-in-store" or the region IDs for // "same-day-delivery" to be added for this type. const placeIds = ['store1']; - // The time when the fulfillment updates are issued, used to prevent - // out-of-order updates on fulfillment information. - const callRemoveFulfillmentPlaces = async () => { // Construct request const request = { @@ -53,15 +50,18 @@ async function main(generatedProductId) { placeIds, }; + // To send an out-of-order request assign the invalid removeTime here: + // request.removeTime = {seconds: Math.round(Date.now() / 1000) - 86400}; + console.log('Remove fulfillment request:', request); + console.log('Waiting to complete remove operation...'); + // Run request const [operation] = await retailClient.removeFulfillmentPlaces(request); await operation.promise(); - - console.log('Waiting to complete remove operation..'); }; - // Remove fulfillment places with current time + // Remove fulfillment places console.log('Start remove fulfillment'); await callRemoveFulfillmentPlaces(); diff --git a/retail/interactive-tutorials/product/set-inventory.js b/retail/interactive-tutorials/product/set-inventory.js index 8f14f14ddb..f8e1295504 100644 --- a/retail/interactive-tutorials/product/set-inventory.js +++ b/retail/interactive-tutorials/product/set-inventory.js @@ -27,7 +27,8 @@ async function main(generatedProductId) { // Create product const createdProduct = await utils.createProduct( projectId, - generatedProductId + generatedProductId, + true ); // The inventory information to update @@ -52,9 +53,6 @@ async function main(generatedProductId) { availability: 'IN_STOCK', }; - // The time when the request is issued, used to prevent - // out-of-order updates on inventory fields with the last update time recorded. - // If set to true, and the product with name is not found, the // inventory update will still be processed and retained for at most 1 day until the product is created const allowMissing = true; @@ -65,35 +63,29 @@ async function main(generatedProductId) { inventory: product, allowMissing, }; + + // To send an out-of-order request assign the invalid setTime here: + // request.setTime = {seconds: Math.round(Date.now() / 1000) - 86400}; + console.log('Set inventory request:', request); + console.log('Waiting to complete set inventory operation...'); // Run request const [operation] = await retailClient.setInventory(request); await operation.promise(); - console.log('Waiting to complete set inventory operation..'); }; - // Set inventory with current time + // Set inventory console.log('Start set inventory'); await callSetInventory(); // Get product - let changedProduct = await utils.getProduct(createdProduct.name); + const changedProduct = await utils.getProduct(createdProduct.name); console.log( `Updated product ${createdProduct.id} with current time: `, JSON.stringify(changedProduct[0]) ); - // Set inventory with outdated time - product.priceInfo.price = 20.0; - await callSetInventory(); - - // Get product - changedProduct = await utils.getProduct(createdProduct.name); - console.log( - `Updated product ${createdProduct.id} with outdated time: `, - JSON.stringify(changedProduct[0]) - ); console.log('Set inventory finished'); // Delete product