Checkout Rule House Number Validation

Checkout Rule House Number Validation

Yodit
Shopify Partner
10 0 3

Hi,

 

I have an extension for blocking the checkout process when trying to continue without entering an house number. But I am getting this error when activating the rule. Is there a mistake in the code?

 

This is the run.js:

/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
*/

/**
* @param {RunInput} input
* @returns {FunctionRunResult}
*/

export function run(input) {
const errors = [];

if(input.buyerJourney.step != "CART_INTERACTION") {
    // the error
    const errorHousnumber = {
    localizedMessage: "Füge bitte eine Hausnummer hinzu.",
    target: "cart.deliveryGroups[0].deliveryAddress?.address1"
}

const customerAdressOne = input.cart.deliveryGroups[0].deliveryAddress?.address1;
const customerAdressTwo = input.cart.deliveryGroups[0].deliveryAddress?.address2;
const containsHouseNumberOne = /\d/.test(customerAdressOne);


// address housenumber validation
if (!containsHouseNumberOne) {
    errors.push(errorHousnumber);
   }
}

return { 
    errors
   }
};

 

And this is the run.graphql:

query RunInput {
  buyerJourney{
    step
  }
  cart {
    deliveryGroups {
      deliveryAddress {
        address1
        address2
        company
        firstName
        lastName
      }
    }
  }
}

 

 

This is the error message i am getting: 

Bildschirmfoto 2024-04-08 um 09.35.12.png

 

Thank you in advance!

 

Best regards,

Yodit

Replies 0 (0)