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

Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order and Call to a member function getPriceType() on n #525

Merged
merged 7 commits into from
May 2, 2019

Conversation

XxXgeoXxX
Copy link
Member

Description (*)

Description #474

Manual testing scenarios (*)

Generate Customer token
Create an empty cart as Registered Customer from GraphQL Client
Perform mutation from the description

Note: Magento get custom options from frontend like mixed data [id=>string, id=>array]. That's why in graphQl query we catch error for multidimensional data(Example: checkbox).
Also 'sort_order' doesn't exist on values level.

Example for multiple data:

mutation {
    addSimpleProductsToCart(
    input: {
      cart_id: "{{cart_id}}"
      cartItems: {
        data: {
          qty: 1
          sku: "test-simple"
        }
        customizable_options: [
          {
            id: 14
            value: "[13,23]"
          }
          {
            id: 23
            value: "test"
          }
        ]
      }
    }
  )
{
    cart {
      items {
        product {
          sku
        }
        ... on SimpleCartItem {
          customizable_options {
            id
            is_required
            sort_order
          }
        }
      }
    }
  }
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@@ -15,6 +15,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Quote\Model\Quote;
use phpDocumentor\Reflection\Types\Mixed_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, remove the redundant dependency

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -135,7 +136,9 @@ private function extractCustomizableOptions(array $cartItemData): array

$customizableOptionsData = [];
foreach ($customizableOptions as $customizableOption) {
$customizableOptionsData[$customizableOption['id']] = $customizableOption['value'];
$customizableOptionsData[$customizableOption['id']] = $this->convertCustomOptions(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, cover functionality with API-functional test

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests were added

*/
private function convertCustomOptions(string $value)
{
if (substr($value, 0, 1) === "[" ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need OR or AND condition?

Copy link
Member Author

Choose a reason for hiding this comment

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

My mistake. We need AND condition. PR was updated

@TomashKhamlai
Copy link
Contributor

Hi, @XxXgeoXxX. Feel free to write me in Slack if I can be useful for you during work on this issue.

@TomashKhamlai TomashKhamlai added QA in progress We are checking and removed QA failed labels Apr 16, 2019
@TomashKhamlai
Copy link
Contributor

TomashKhamlai commented Apr 22, 2019

When I have this product prod_opt.zip and create the empty cart as a Customer and add this product to cart by querying

mutation addSimpleProductsToCart(
  $cart_id: String!
  $qty: Float!
  $sku: String!
) {
  addSimpleProductsToCart(
    input: {
      cart_id: $cart_id
      cartItems: {
        customizable_options: [
          {
            id: 1
            value: "[1]"
          }
          {
            id: 2
            value: "4"
          }
          {
            id: 3
            value: "7"
          }
          {
            id: 4
            value: "[10]"
          }
        ]
        data: {
          qty: $qty
          sku: $sku
        }
      }
    }
  ) {
    cart {
      items {
        id
        qty
        product {
          sku
          stock_status
        }
        ... on SimpleCartItem {
          customizable_options {
            id
            is_required
            label
            type
            values {
              id
              label
              price {
                value
              }
              sort_order
            }
          }
        }
      }
    }
  }
}

with variables

{
  "cart_id": "4nsy2q2ldOGv2hcJqjnRUhH1Ub7r9TOt",
  "qty": 1,
  "sku": "simple-product-with-options"
}

I get this problem:

{
  "errors": [
    {
      "debugMessage": "Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order.",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 23,
          "column": 15
        }
      ],
      "path": [
        "addSimpleProductsToCart",
        "cart",
        "items",
        0,
        "customizable_options",
        0,
        "values",
        0,
        "sort_order"
      ]
    },
    {
      "debugMessage": "Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order.",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 23,
          "column": 15
        }
      ],
      "path": [
        "addSimpleProductsToCart",
        "cart",
        "items",
        0,
        "customizable_options",
        1,
        "values",
        0,
        "sort_order"
      ]
    },
    {
      "debugMessage": "Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order.",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 23,
          "column": 15
        }
      ],
      "path": [
        "addSimpleProductsToCart",
        "cart",
        "items",
        0,
        "customizable_options",
        2,
        "values",
        0,
        "sort_order"
      ]
    },
    {
      "debugMessage": "Cannot return null for non-nullable field SelectedCustomizableOptionValue.sort_order.",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 23,
          "column": 15
        }
      ],
      "path": [
        "addSimpleProductsToCart",
        "cart",
        "items",
        0,
        "customizable_options",
        3,
        "values",
        0,
        "sort_order"
      ]
    }
  ],
  "data": {
    "addSimpleProductsToCart": {
      "cart": {
        "items": [
          {
            "id": "301",
            "qty": 2,
            "product": {
              "sku": "simple-product-with-options",
              "stock_status": "IN_STOCK"
            },
            "customizable_options": [
              {
                "id": 1,
                "is_required": 1,
                "label": "opt1",
                "type": "checkbox",
                "values": [
                  null
                ]
              },
              {
                "id": 2,
                "is_required": 1,
                "label": "opt2",
                "type": "radio",
                "values": [
                  null
                ]
              },
              {
                "id": 3,
                "is_required": 1,
                "label": "opt3",
                "type": "drop_down",
                "values": [
                  null
                ]
              },
              {
                "id": 4,
                "is_required": 1,
                "label": "opt4",
                "type": "multiple",
                "values": [
                  null
                ]
              }
            ]
          }
        ]
      }
    }
  }
}

@TomashKhamlai
Copy link
Contributor

@XxXgeoXxX, please apply updates from mainline.

@naydav
Copy link
Contributor

naydav commented Apr 24, 2019

@TomashKhamlai I merged mainline, please, continue testing the issue

@naydav
Copy link
Contributor

naydav commented Apr 24, 2019

@XxXgeoXxX

Also 'sort_order' doesn't exist on values level.

Great point! It was a mistake in the initial scheme.

…alue.sort_order and Call to a member function getPriceType() on null
…alue.sort_order and Call to a member function getPriceType() on null
…alue.sort_order and Call to a member function getPriceType() on null
XxXgeoXxX and others added 2 commits April 30, 2019 11:51
…alue.sort_order and Call to a member function getPriceType() on null
…izableOptionValue.sort_order and Call to a member function getPriceType() on null
…izableOptionValue.sort_order and Call to a member function getPriceType() on null
@naydav naydav added Progress: accept and removed Progress: ready for qa Add this in any case when you need some feedback, even if automated tests are failing labels Apr 30, 2019
…izableOptionValue.sort_order and Call to a member function getPriceType() on null
@magento-engcom-team magento-engcom-team merged commit 05ea6ef into magento:2.3-develop May 2, 2019
@ghost
Copy link

ghost commented May 2, 2019

Hi @XxXgeoXxX, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants