Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Added option_id in response for product with customizable options. #247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/code/Magento/CatalogGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGrap
title: String @doc(description: "The display name for this option")
required: Boolean @doc(description: "Indicates whether the option is required")
sort_order: Int @doc(description: "The order in which the option is displayed")
option_id: Int @doc(description: "Option ID")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VoronoyAlexandr Why does option_id need to be exposed? Please provide scenario, which requires this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good day @paliarush.
Scenario:
If we used mutation to add product in cart with options like in this code

mutation {
  addSimpleProductsToCart(
    input: {
      cart_id: "CDNuOMoQBV3CElFSUbgbAswlVcoaeSId", 
      cartItems: [
        {
          data: {
            sku: "product_dynamic_1", 
            qty: 1
          }, 
          customizable_options: [
            {id: 5, value: "4"},
            {id: 6, value: "5"}
          ]
        }
      ]
    }
  ) 
.......

we need know what is id of options. At this moment schema return only 'title', 'required', 'sort_order'. This option_id in schema, response look like:

{
  "data": {
    "products": {
      "items": [
        {
          "id": 1,
          "attribute_set_id": 10,
          "created_at": "2018-11-11 14:00:34",
          "name": "Simple Product 1",
          "sku": "product_dynamic_1",
          "type_id": "simple",
          "updated_at": "2018-11-13 09:25:55",
          "options": [
            {
              "title": "Test option 1",
              "required": true,
              "sort_order": 1,
              "option_id": 1
            },
            {
              "title": "Test option 2",
              "required": true,
              "sort_order": 2,
              "option_id": 3
            }
          ]
        }
      ]
    }
  }
}

}

interface CustomizableProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\ProductInterfaceTypeResolverComposite") @doc(description: "CustomizableProductInterface contains information about customizable product options.") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function testQueryAllFieldsSimpleProduct()
title
required
sort_order
option_id
... on CustomizableFieldOption {
product_sku
field_option: value {
Expand Down Expand Up @@ -337,6 +338,7 @@ public function testQueryMediaGalleryEntryFieldsSimpleProduct()
title
required
sort_order
option_id
... on CustomizableFieldOption {
product_sku
field_option: value {
Expand Down Expand Up @@ -753,7 +755,8 @@ private function assertOptions($product, $actualResponse)
$assertionMap = [
['response_field' => 'sort_order', 'expected_value' => $option->getSortOrder()],
['response_field' => 'title', 'expected_value' => $option->getTitle()],
['response_field' => 'required', 'expected_value' => $option->getIsRequire()]
['response_field' => 'required', 'expected_value' => $option->getIsRequire()],
['response_field' => 'option_id', 'expected_value' => $option->getOptionId()]
];

if (!empty($option->getValues())) {
Expand All @@ -777,7 +780,7 @@ private function assertOptions($product, $actualResponse)
['response_field' => 'product_sku', 'expected_value' => $option->getProductSku()],
]
);
$valueKeyName = "";

if ($option->getType() === 'file') {
$valueKeyName = 'file_option';
$valueAssertionMap = [
Expand Down