How to handle pricing when weight and price change based on variation

Hello everyone, I have a situation I need to address.

Situation:

I am building a store that sells jackets. The price and shipping weight for each product change based on which size the customer chooses.

Problem:

My checkout workflow fails whenever the customer attempts to purchase a size different from the default size listed on the product’s details page.

Assumptions:

I know the failure is caused by the HTML crawler seeing data attribute values in the DOM that don’t match the customer’s selections. More specifically, these data attribute values are related to weight, which directly affects the price.

The only solution I can think of is to set up a unique REST API that serves JSON data for every possible variant/size/weight/price combination so that Snipcart can validate products in the checkout workflow using the JSON crawler instead.

Building an API just for product validation would be an astronomical amount of work on top of an already tight deadline with this client.

I imagine this problem has been addressed before in a more efficient manner, so I was hoping someone might share some insight.

Also, for the record, this site uses the Contentful CMS to hold my data models and product listings. I could use their API, but I would still run into the same problem of producing a JSON representation of every possible variation.

Here’s a test hosting of the site :

That said, the store is still in test mode, so you can attempt to make purchases using Snipcart’s test credit card … i.e., 4242 4242 4242 … etc.

Thank you so much! :pray::pray::pray::heart:

This should be possible, however because Snipcart relies on scraping HTML to validate orders, it will require some legwork to make it work.

This recent post has information on how you can achieve this:

The TL;DR is that you can provide a validation URL that has query parameters. I believe you’ll need to be using server-side rendering (SSR) for this to work though, as the crawler needs to receive static HTML that’s been updated with the data in the query parameters. Traditionally cached HTML won’t be able to update like that on its own.

Doing this, you won’t need to generate every possible variation. Whether it’s more or less work for you, I’m not sure.

1 Like

Hello @hackerman,

You could use our product custom fields to change the price of items depending on which one is selected.

However, this won’t allow you to change the weight of the product depending on the selected field.

If this is a deal-breaker, you’ll need to rely on generating a custom JSON or server-side render your page with custom attributes, as explained in the reply above.

Let me know if that helps!

I completely forgot about the custom fields that can modify the price!

The Snipcart order validation only checks for a valid price, right? so if the product contains a dynamic weight (e.g. set via JavaScript), the Cart/order could get a dynamic weight and still pass validation, right?

Weight can’t be updated dynamically with JavaScript. It’s part of the order validation process to ensure a customer doesn’t bypass the cost of a shipping method.

For instance, if it was customizable, a customer could set the weight of any order to 0, which could trigger a cheaper shipping method.

Ah, right, that makes sense. Thanks for the clarification Michael!

Hopefully either the custom fields or the dynamic url help out, hackerman :grinning: