Scenario - there is an item with a promotion, if the promotion is expired but a customer has it lingering in the cart I want to prevent it’s sale.
I am running a validation that seems to block deleting items from the cart when it is in the error state. This is not ideal as I want to force a user to remove the item from the cart if they are no longer valid. Has anyone else run into this issue? (looking again it seems to block all cart modification?)
Here is some simplified example of code, it’s working as expected in terms of cart items being invalidated when the promoPhase over takes the line items date. It feels like I’m missing something bigger picture about why validation would prevent other types of interaction? Or perhaps this is a bug, but I am unsure where best to file an issue if that’s the case.
# run.graphql
query RunInput {
cart {
lines {
validTill: attribute(key: "itemEpoch") {
value # string of epoch time
}
}
validation {
promoPhase: metafield(
namespace: "foo"
key: "bah"
) {
value # string of epoch time
}
}
}
I looked into this some more and wrote a more general issue on the functions examples repo
It seems like this is a fairly serious flaw (unless I’ve misunderstood something ), any time a validation is enabled / updated it could trap users in an invalid state. That same holds true for updating any of the functions inputs that are not user triggered?
Here’s an example of the user flow that leads to a non-modifiable cart:
The customer adds 15 units of product A and 15 units of product B to the cart.
The customer abandons the cart and leaves the store.
Later, the merchant or developer configures a validation function that prevents checkout if the total quantity of line items in the cart exceeds 10.
When the customer returns to the store, their cart still contains products A and B. However, here’s the trap: the validation rule blocks any attempt to remove a product or decrease its quantity. As a result, the customer is stuck—they can neither clean up the cart nor proceed to checkout.
This happens because the function executes on every cart action, using the current cart state as input. Even if the customer attempts to remove product A, the cart still contains 15 units of product B, which fails validation.
@a-z provided a great example in the previous post.
It would be helpful if the Shopify Functions team could provide one of the following solutions:
Skip function execution for the “remove product from the cart” action.
Force removal of the product from the cart.
Introduce a flag in the buyerJourney object within the function input that indicates the specific cart action—e.g., { "cart_action": "LINE_REMOVAL" }. This would allow developers to adjust function logic and prevent validation errors when products are being removed during the CART_INTERACTION step.