# Free Gift Checkout Validation

This Shopify Validation Function blocks checkout whenever a free gift variant
(`Product B`) is in the cart without its mapped qualifying variant (`Product A`).

## Product mapping

Update `src/cart_validations_generate_run.js` and replace the placeholder
variant IDs in `PRODUCT_MAPPING` with real ProductVariant GIDs from your shop:

```js
const PRODUCT_MAPPING = {
  "gid://shopify/ProductVariant/A_variant_id_1":
    "gid://shopify/ProductVariant/B_variant_id_1",
  "gid://shopify/ProductVariant/A_variant_id_2":
    "gid://shopify/ProductVariant/B_variant_id_2",
};
```

## Deployment steps

From the app root:

```bash
cd /Users/deepaksharma/Desktop/projects/shopify-app/checkout-new1/checkout-ui-custom-app
shopify app function typegen
shopify app dev
```

Deploy the app and extension when you're ready:

```bash
shopify app deploy
```

After deployment, open the Shopify admin for your dev store:

1. Go to `Apps > Checkout UI Custom APP`.
2. Open the `Free Gift Checkout Validation` function.
3. Enable the function for the store or publish the app version if prompted.

## Sample input JSON

```json
{
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/1",
        "quantity": 1,
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/B_variant_id_1"
        }
      }
    ]
  },
  "buyerJourney": {
    "step": "CHECKOUT_COMPLETION"
  }
}
```

## Sample output JSON when validation fails

```json
{
  "operations": [
    {
      "validationAdd": {
        "errors": [
          {
            "message": "Free gift items cannot be purchased without the qualifying product.",
            "target": "$.cart"
          }
        ]
      }
    }
  ]
}
```

## Sample output JSON when validation passes

```json
{
  "operations": [
    {
      "validationAdd": {
        "errors": []
      }
    }
  ]
}
```
