magento/graphql-ce

Cart applied_taxes of empty cart causes 'Internal server error' message on PHP 7.2

therealtbs opened this issue · 2 comments

Preconditions (*)

  1. PHP 7.2.18
  2. Magento 2.3.2

Steps to reproduce (*)

  1. Create an empty cart
mutation {
  createEmptyCart
}
  1. Retrieve that cart without adding any products
{
  cart(cart_id: "CARTID") {
    prices {
      grand_total {
        value
      }
      applied_taxes {
        amount {
          value
        }
      }
    }
  }
}

Expected result (*)

{
  "data": {
    "cart": {
      "prices": {
        "grand_total": {
          "value": 0
        },
        "applied_taxes": []
      }
    }
  }
}

Actual result (*)

{
  "errors": [
    {
      "debugMessage": "Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vendor/magento/module-quote-graph-ql/Model/Resolver/CartPrices.php on line 75",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "cart",
        "prices"
      ]
    }
  ],
  "data": {
    "cart": {
      "prices": null
    }
  }
}

At this point $appliedTaxes is NULL and therefore not countable. From PHP 7.2 onwards there is a warning generated which I assume Magento turns into a Throwable.

Since the fix is quite easy I'm not sure if I should make a PR for this.

@therealtbs thanks for pointing out. Would you like to submit a PR to fix? If not I can this weekend.

Sure, I'll get it going first thing tomorrow.