3

I am developing an interface between Magento and Epicor 9 and we access our customer's orders using the REST API. When the customer buys one of our custom products, they modify their order using Custom Options. Their choices appear in the API response packet as follows:

{
  "items": [
     {
       ...
      "sku": "custom-product-1",
       ...
      "product_option": {
        "extension_attributes": {
          "custom_options": [
            {
              "option_id": "867",
              "option_value": "952"
            },
            {
              "option_id": "868",
              "option_value": "Please make sure that art is centered. Thank you!"
            },
            {
              "option_id": "869",
              "option_value": "image/jpeg,Our_Company_Logo.jpg,custom_options/quote/T/h/f311f8f7f56a74b8c8a95c310895930a.jpg,custom_options/order/T/h/f311f8f7f56a74b8c8a95c310895930a.jpg,/var/www/vhosts/ourdomain.com/pub/media/custom_options/quote/T/h/f389f8f7f56a74b8c8a95c310895930a.jpg,25550,200,199,f311f8f7f56a74b8c8a9"
            }
          ],
         ...

Apparently, Magento changes the option_id and option_value values every time the site structure is changed and re-saved (bringing me to my first question: REALLY??!?). Luckily, Magento provides this information via the REST interface (fragment below part of response to GET /rest/V1/products/custom-product-1/options, note use of sku as key):

[
 ...
{
    "product_sku": "custom-product-1",
    "option_id": 867,
    "title": "White Option",
    "type": "drop_down",
    "sort_order": 2,
    "is_require": true,
    "max_characters": 0,
    "image_size_x": 0,
    "image_size_y": 0,
    "values": [
      {
        "title": "No White",
        "sort_order": 1,
        "price": null,
        "price_type": null,
        "option_type_id": 950
      },
      {
        "title": "Spot White",
        "sort_order": 1,
        "price": null,
        "price_type": null,
        "option_type_id": 951
      },
      {
        "title": "Flood White",
        "sort_order": 2,
        "price": null,
        "price_type": null,
        "option_type_id": 952
      }
    ]
  },
   ...
]

As long as my co-developers do not change the title of the option from 'White Option', this can work. However, edits to the site will change ALL option_id and option_value values in the site, which means that orders placed before the change become impossible to translate, even knowing the correct title attributes.

Sure, we can save the option definitions every time they change, and look up the correct translation based on created_at, but before we do that, I wanted to check with the community. How do you code against these changing values? Is there something we missed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.