Product variation does not apply modifier

curl

#1

Hello,

I’m using a product modifier to append a value to the slug:

{
  "type": "product-variation",
  "id": "26ab3d6a-8a96-4f95-9dac-950e919799f6",
  "name": "training_date_85bc5d97-3dd4-4d7f-9c61-9288762097fe_2018-04-17",
  "options": [
    {
      "id": "b5c9d197-e74d-4463-baaa-af0015c1254f",
      "name": "training_date",
      "description": "Variation on training date",
      "modifiers": [
        {
          "id": "765bd72e-a6b5-47e5-b40f-3b6eb1185035",
          "type": "slug_append",
          "value": "_2018-04-17"
        }
      ]
    }
  ]
}

Here’s the result when I build child products:

{
  "data": [
    {
      "type": "product",
      "id": "c4d556c7-4bf5-4424-87e6-7ba33d4bfcda",
      "name": "How to Become a Superhero",
      "slug": "daily-planet-s-how-to-become-a-superhero-2018-05-10",
      "sku": "abcd-1234-how-to-become-a-superhero-2018-05-10",
      "manage_stock": true,
      "description": "Work on your strength.",
      "price": [
        {
          "currency": "EUR",
          "amount": 200,
          "includes_tax": false
        }
      ],
      "status": "live",
      "commodity_type": "digital"
    }
  ]
}

As you can see the slug is not modified (ie. _2018-04-17 is not appended).
I also tried to use name_equals and sku_append but it does not work…

Thanks for your help,
Guillaume


#2

If needed I can provide a test case to reproduce this issue:

  1. POST /variations
{
  "data": {
    "type": "product-variation",
    "name": "training_date_$productId_2018-04-17"
  } 
}
  1. Get the product variation id from the response
  2. Create an option POST /variations/$variationId/options:
{
  "data": {
    "type": "option",
    "name": "training_date"
  } 
}
  1. Get the option id from the response
  2. Create a product modifier POST /variations/$variationId/options/$optionId/modifiers:
{
  "data": {
    "type": "modifier",
    "modifier_type": "slug_append",
    "value":  "_2018-04-17"
  } 
}
  1. Create a product variation relationship POST /products/$productId/relationships/variations:
{
  "data": {
    "type": "product-variation",
    "id": "$variationId"
  } 
}
  1. Build child products POST /products/$productId/build"

Am I missing something ? Am I doing something wrong ?

Thanks,
Guillaume


#3

Here’s my product variation:

{
  "data": {
    "type": "product-variation",
    "id": "f334021b-2254-437f-8345-7cd01522ef59",
    "name": "training_date_160f3f77-05f6-4f3e-9d0e-ee019cf0830a_2018-05-07",
    "options": [
      {
        "id": "33de8470-76de-4b9d-a403-05b5d92fe6a7",
        "name": "training_date",
        "description": "Variation on training date",
        "modifiers": [
          {
            "id": "cda266b6-3730-4020-b1ab-7923a11b82e4",
            "type": "slug_append",
            "value": "_2018-05-07"
          }
        ]
      }
    ],
    "relationships": {
      "options": {
        "data": [
          {
            "type": "option",
            "id": "33de8470-76de-4b9d-a403-05b5d92fe6a7"
          }
        ]
      }
    }
  },
  "included": {
    "options": [
      {
        "type": "option",
        "id": "33de8470-76de-4b9d-a403-05b5d92fe6a7",
        "name": "training_date",
        "description": "Variation on training date",
        "relationships": {
          "modifiers": {
            "data": [
              {
                "type": "modifier",
                "id": "cda266b6-3730-4020-b1ab-7923a11b82e4"
              }
            ]
          }
        }
      }
    ],
    "modifiers": [
      {
        "id": "cda266b6-3730-4020-b1ab-7923a11b82e4",
        "type": "modifier",
        "modifier_type": "slug_append",
        "value": "_2018-05-07"
      }
    ]
  }
}

As you can see I have a modifier attached to an option attached to a product variation. I don’t know how to list the variations attached to a product but I did create a relationship with:

POST /products/$productId/relationships/variations
{
  "data": {
    "type": "product-variation",
    "id": "$variationId"
  }
}

And here’s my children when calling POST /products/$productId/build:

{
  "data": {
    "type": "product",
    "id": "160f3f77-05f6-4f3e-9d0e-ee019cf0830a",
    "name": "How to Be Superman",
    "slug": "daily-planet-s-how-to-be-superman-2018-05-10",
    "sku": "abcd-1234-how-to-be-superman-2018-05-10",
    "manage_stock": true,
    "description": "This is gonna be fine",
    "price": [
      {
        "amount": 200,
        "currency": "EUR",
        "includes_tax": false
      }
    ],
    "status": "live",
    "commodity_type": "digital",
    "meta": {
      "timestamps": {
        "created_at": "2018-05-07T14:10:52+00:00",
        "updated_at": "2018-05-07T14:10:53+00:00"
      },
      "display_price": {
        "with_tax": {
          "amount": 200,
          "currency": "EUR",
          "formatted": "200€"
        },
        "without_tax": {
          "amount": 200,
          "currency": "EUR",
          "formatted": "200€"
        }
      },
      "stock": {
        "level": 0,
        "availability": "out-stock"
      },
      "variation_matrix": []
    },
    "relationships": {
      "children": {
        "data": [
          {
            "type": "product",
            "id": "e15dc3a7-d9a5-4af8-b431-6bb81f40e425"
          }
        ]
      }
    },
    "program_url": null,
    "trainer": "Superman",
    "initial_place_count": 2,
    "learning_goal": "Dot it now.",
    "requirement": "None.",
    "teaching_method": "The hard way.",
    "discount_ratio": 0,
    "document_url": null,
    "hours_count": 16,
    "cpf_code": null,
    "intra_available": false,
    "attendance_mode": "MOOC",
    "customer": "abcd-1234",
    "location_lat": null,
    "location_lng": null,
    "place": null,
    "showcase": false
  },
  "included": {
    "children": [
      {
        "type": "product",
        "id": "e15dc3a7-d9a5-4af8-b431-6bb81f40e425",
        "name": "How to Be Superman",
        "slug": "daily-planet-s-how-to-be-superman-2018-05-10",
        "sku": "abcd-1234-how-to-be-superman-2018-05-10",
        "manage_stock": true,
        "description": "This is gonna be fine",
        "price": [
          {
            "amount": 200,
            "currency": "EUR",
            "includes_tax": false
          }
        ],
        "status": "live",
        "commodity_type": "digital",
        "meta": {
          "timestamps": {
            "created_at": "2018-05-07T14:10:53+00:00",
            "updated_at": "2018-05-07T14:10:53+00:00"
          },
          "display_price": {
            "with_tax": {
              "amount": 200,
              "currency": "EUR",
              "formatted": "200€"
            },
            "without_tax": {
              "amount": 200,
              "currency": "EUR",
              "formatted": "200€"
            }
          },
          "stock": {
            "level": 0,
            "availability": "out-stock"
          }
        },
        "relationships": {
          "parent": {
            "data": {
              "type": "product",
              "id": "160f3f77-05f6-4f3e-9d0e-ee019cf0830a"
            }
          }
        }
      }
    ]
  }
}

_2018-05-07 is not appended to the slug.
Any help will be greatly appreciated as this issue is a blocker for our migration.

Thanks,
Guillaume


#4

Hey Guillaume,

Reading through this thread. New here at Moltin but I can dig into this. I will get back to you later today.

-George


#5

Excellent, thanks George, let me know if you need additional information. :blush:


#7

Hi ggrossetie!!

I’m looking at your products…

160f3f77-05f6-4f3e-9d0e-ee019cf0830a is the base product and one child product has been build (e15dc3a7-d9a5-4af8-b431-6bb81f40e425)

The variation you describe though is NOT attached to the base product.

If you hit:

POST /products/160f3f77-05f6-4f3e-9d0e-ee019cf0830a/relationships/variations

payload:

{
  "data": {
    "type": "product-variation",
    "id": "26ab3d6a-8a96-4f95-9dac-950e919799f6"
  } 
}

That should ensure the variation is attached to the product

Then go and hit:

POST /products/160f3f77-05f6-4f3e-9d0e-ee019cf0830a/build

You should then see your child product created…

PLEASE NOTE - you have at teh very least to specify a slug AND sku modifier so please create a sku modifier on the same variation option and you should be good to go.

Any problems just come back to us on here.

Ian


#8

Hi Ian,

Oups!
How did you get the list of variations attached to a product ? As far as I know there’s no endpoint in the API to list the variations attached to a product ? Maybe we should add include=variations on the GET /products/{PRODUCT_ID} API ?

My child product was created but the modifier was not applied.

This is interesting I didn’t know about that. I think the documentation should make it clear that you need to at least specify a SLUG and a SKU modifier.

I will give it a try and let you know!

Thanks for your help :+1:


#9

It’s working!
I was not using an array in POST products/{PRODUCT_ID}/relationships/variations:

wrong

{
  "data": {
    "type": "product-variation",
    "id": "3ab3deca-1f11-47b7-a409-24ea3234d72c"
  }
}

good

{
  "data": [{
    "type": "product-variation",
    "id": "3ab3deca-1f11-47b7-a409-24ea3234d72c"
  }]
}

#10

You are correct…

I C&P the one in the post further up rather than from docs - my bad!

Anyway…

Super pleased you’re off and running.

happy coding

Ian


#11

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.