Velo Shipping Restrictions

I’m in Wix Studio using the Velo Public & Backend Custom Extension for ecom-validations to create a shipping restriction by product for certain states. The code works in test runs, but does not execute on the live site or log.

The code for the config folder is:

import * as ecomValidations from 'interfaces-ecommerce-v1-validations-provider';

export function getConfig() {
  return {validateInCart: true};
}

The code for the other .js folder is

import * as ecomValidations from 'interfaces-ecommerce-v1-validations-provider';

/**
 * This endpoint retrieves validation violations from your app.
 *
 * Wix calls this endpoint when certain actions are performed on a visitor's cart and checkout. For example, when an item is added to the cart, or when a coupon is added to a checkout.
 * This endpoint validates a visitor's cart and checkout, and returns any validation violations (using the structure provided by Wix eCommerce). Site visitors can see the validation violations in their cart and checkout pages. If there aren't any validation violations, the endpoint returns an object containing an empty list.
 *
 * > __Notes:__
 * > + By default, this endpoint only retrieves validation violations from a visitor's checkout. If you want to also retrieve validation violations from a visitor's cart, set the `validateInCart` parameter to `true` in the Ecom Validations Integration's config file located in the [Wix Developers Center](https://dev.wix.com/). For more information, see the [prerequisites](https://dev.wix.com/api/rest/drafts/validations-integration-spi/introduction#drafts_validations-integration-spi_introduction_prerequisites) section of the introduction.
 * > + You cannot try out this endpoint because it has to be implemented by an app and can have an arbitrary URL. Therefore, ignore the **Authorization** and **POST** sections below as well as the **Try It Out** button.
 * @param {import('interfaces-ecommerce-v1-validations-provider').GetValidationViolationsOptions} options
 * @param {import('interfaces-ecommerce-v1-validations-provider').Context} context
 * @returns {Promise<import('interfaces-ecommerce-v1-validations-provider').GetValidationViolationsResponse | import('interfaces-ecommerce-v1-validations-provider').BusinessError>}
 */
export const getValidationViolations = async (options, context) => {
    console.log('Hello from validation code: ' + new Date().toDateString());
    let violations = [];

    const source = options.sourceInfo.source;
    const severity = source == ecomValidations.Source.CART ? ecomValidations.Severity.WARNING : ecomValidations.Severity.ERROR;

    const gummyStateProhibitedDescription = 'We cannot ship gummies to your state per regulations.';
    const prohibitedGummyStatesByStateCode = ['alaska','colorado','connecticut','hawaii','idaho','nevada', 'north dakota','oregon', 'rhode island','vermont','washington'];

    const usersStateCode = (options.validationInfo?.shippingAddress?.address?.state)?.toLowerCase();
    console.log("usersStateCode: " + usersStateCode);
    const isUserInProhibitedGummyState = prohibitedGummyStatesByStateCode.includes(usersStateCode);
    console.log("isUserInProhibitedGummyState: " + isUserInProhibitedGummyState);

    
    const lineItems = options.validationInfo.lineItems;
    const gummyLineItems = [];
    for (let j = 0; j < options.validationInfo.lineItems?.length; j++ ) {
        gummyLineItems.push(options.validationInfo.lineItems[j]);
    }
    console.log("gummyLineItems.length: " + gummyLineItems.length);
    if (isUserInProhibitedGummyState && gummyLineItems?.length > 0) {
        console.log("isUserInProhibitedGummyState && gummyLineItems?.length > 0: " + (isUserInProhibitedGummyState && gummyLineItems?.length > 0));
        for (let i = 0; i < gummyLineItems.length; i++) {
            console.log('pushing a violoation');
            const lineItem = gummyLineItems[i];
            violations.push({
                severity,
                target: { lineItem: { name: ecomValidations.NameInLineItem.LINE_ITEM_DEFAULT, _id: lineItem._id } },
                description: gummyStateProhibitedDescription
            });
        }
    }

    return { violations };
};

const isGummie = (catalogItemId) => {
    // IMPORTANT: would be easier if this could lookup and just check against CategoryId from the product, but IDK how to look that up.
    // If you add new Gummie items, you should add the item GUID to the list below
    const gummieCatalogItemIds = [
        '362b1084-060a-49d8-9ba3-e4701d2dac32',
        'eee03e4c-9d2e-453c-a274-facba8810fbb',
        'ea30bf54-ff67-461c-87f3-2236f83c3e23',
        '9522d8ad-c3ac-36df-17c6-62b8671eb209',
    ];
    const isGummieItem = gummieCatalogItemIds.includes(catalogItemId);
    console.log('isGummieItem: ' + isGummieItem);
    return isGummieItem;
    // const isGummie = catalogItemId != undefined && (catalogItemId == gummieCatalogItemId);
    // return isGummie;
}

Can you clarify what is meant by “works in test runs”? Is that in Preview mode or something else?

Also are you seeing any error messages in console or site event logs?

So I worked with Duncan Simpson, who is a wix verified partner and he said that the ecom integration is not publishing, so there’s a bug on my site.

Got it. Please reach out to support here: https://www.wix.com/support-chatbot?nodeId=aedad5ab-8cdd-4c3a-94e9-7a6e3f96835e&referral=bugReportForum

Also if you have any error messages then please share them.

I submitted a support ticket. The error I’m getting when testing any code is the same: "cannot read properties of null (reading ‘sourceInfo’)

Can you or Duncan check and let us know if the Live Site Event Logs show any errors when a checkout happens?

Also just to confirm, are you using Wix Stores itself and not a third party application? I imagine you are but just want to make sure.

I’m not sure on the events log, but I can tell you I’m using the wix store. As I mentioned in my original ticket, my cart was not working at all so the wix team had to uninstall the store and reinstall to get that working. I’m not sure if it’s related. I also mentioned an app I got through the wix store called Product & Section Blocker. I didn’t end up using it and uninstalled, but I’m not sure if it leaves behind broken code or anything.