Skip to content

Products added to cart with REST API give total prices equal to zero #2991

Closed
@degaray

Description

@degaray

Preconditions (*)

  1. Magento 2.3.0(release), 2.3-develop, 2.2-develop

Steps to reproduce (*)

1.Execute:

endpoint="http://m2ce.conf/rest"
shippingEmail="[email protected]"

admin_token=$(curl -X POST "$endpoint/V1/integration/admin/token" \
--header "Content-Type: application/json" \
-d '{"username":"admin","password":"123123q"}') && echo $admin_token && admin_token=$(echo $admin_token | tr -d '"')

curl -X POST "$endpoint/V1/categories" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"category":{"parent_id":2,"name":"Category 1","is_active":true,"level":2,"path":"1/2/3","include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"category-1"},{"attribute_code":"url_path","value":"category-1"}]}}' | json_pp

curl -X POST "$endpoint/V1/categories" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"category":{"parent_id":2,"name":"Category 2","is_active":true,"level":2,"path":"1/2/4","include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"category-2"},{"attribute_code":"url_path","value":"category-1"}]}}' | json_pp

category_id="3"; productSKU="Simple Product SSM 1" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

category_id="3"; productSKU="Simple Product SSM 2" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

category_id="3"; productSKU="Simple Product SSM 3" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

category_id="4"; productSKU="Simple Product SSM 4" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

category_id="4"; productSKU="Simple Product SSM 5" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

curl -X POST "$endpoint/V1/categories" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"category":{"parent_id":2,"name":"Category 3","is_active":true,"level":2,"path":"1/2/4","include_in_menu":true,"custom_attributes":[{"attribute_code":"is_anchor","value":"1"},{"attribute_code":"url_key","value":"category-3"},{"attribute_code":"url_path","value":"category-3"}]}}' | json_pp

category_id="5"; productSKU="Simple Product SSM 5" && curl -X POST "$endpoint/V1/products" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"product":{"sku":"'"$productSKU"'","name":"'"$productSKU"'","attribute_set_id":4,"price":10,"status":1,"visibility":4,"type_id":"simple","created_at":"2018-01-01 00:00:01","updated_at":"2018-01-01 00:01:00","weight":1,"extension_attributes":{"category_links":[{"position":0,"category_id":"'"$category_id"'"}],"stock_item":{"qty":1000,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp

curl -X POST $endpoint/V1/customers \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $admin_token" \
-d '{"customer":{"default_billing":false,"default_shipping":true,"email":"'"$shippingEmail"'","firstname":"Jim","lastname":"Earthworm","store_id":1,"website_id":1,"addresses":[{"id":1,"region":{"region_code":"CA","region":"California","region_id":12},"region_id":12,"country_id":"US","street":["6161 West Centinela Avenue"],"company":"Magento","telephone":"555-55-555-55","postcode":"90230","city":"Culver City","firstname":"Jim","lastname":"Earthworm"}],"disable_auto_group_change":0,"extension_attributes":{"is_subscribed":false}},"password":"MetaFrame1"}' | json_pp

customer_token=$(curl -X POST "$endpoint/V1/integration/customer/token" \
 -H "Content-Type: application/json" \
 -d '{"username":"'"$shippingEmail"'","password":"MetaFrame1"}') && echo $customer_token && customer_token=$(echo $customer_token | tr -d '"')

 cart_id=$(curl -X POST "$endpoint/V1/carts/mine" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $customer_token") && echo $cart_id && cart_id=$(echo $cart_id | tr -d '"')

curl -X GET "$endpoint/V1/customers/me" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $customer_token" | grep -i customer_id

curl -X GET "$endpoint/V1/carts/mine/items" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $customer_token"

curl -X POST "$endpoint/V1/carts/mine/items" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $customer_token" \
-d '{"cartItem":{"sku":"'"$productSKU"'","qty": 1,"name": "'"$productSKU"'","price":10,"product_type":"simple","quote_id":"'"$cart_id"'"}}' | json_pp

curl -X POST "$endpoint/V1/carts/mine/items" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $customer_token" \
-d '{"cartItem":{"sku":"'"$productSKU"'","qty": 1,"name": "'"$productSKU"'","price":10,"product_type":"simple","quote_id":"'"$cart_id"'"}}' | json_pp

Expected result (*)

  1. Price is present in both last two responses and is not equal to zero or is equal to real price whatever price was specified in the request payload.
  2. No side-effects on Storefront

Actual result (*)

  1. Fresh cart always has no price property. Submit an order and you will be able to reproduce again.
  2. Zero price in the Cart on Storefront
    report

Information from reporter

I have created a Product with a prize of $24 using the backend of Magento2. When I check it in the backent it is fine.
However, when I add one unit of it to an existent cart using the REST API I get a price of zero. For that I call [POST] /carts/mine/items with body:

{
    "cart_item": {
        "quote_id": "2",
        "sku": "MY_SKU",
        "qty": 1
    }
}

I get the following response:

{
  "item_id": 2,
  "sku": "MY_SKU",
  "qty": 2,
  "name": "My Product",
  "price": 0,
  "product_type": "virtual",
  "quote_id": "2"
}

Also when I call [GET] /products I get the right price in the response, this is the response I get:

{
  "items": [
    {
      "id": 1,
      "sku": "MY_SKU",
      "name": "My Product",
      "attribute_set_id": 9,
      "price": 24,
      "status": 1,
      "visibility": 4,
      "type_id": "virtual",
      "created_at": "2016-01-11 19:17:10",
      "updated_at": "2016-01-13 17:49:11",
      "product_links": [],
      "options": [],
      "tier_prices": [],
      "custom_attributes": [
        {
          "attribute_code": "meta_title",
          "value": "My Product"
        },
        {
          "attribute_code": "meta_keyword",
          "value": "My Product"
        },
        {
          "attribute_code": "meta_description",
          "value": "My Product"
        },
        {
          "attribute_code": "options_container",
          "value": "container2"
        },
        {
          "attribute_code": "required_options",
          "value": "0"
        },
        {
          "attribute_code": "has_options",
          "value": "0"
        },
        {
          "attribute_code": "url_key",
          "value": "my-product"
        },
        {
          "attribute_code": "tax_class_id",
          "value": "0"
        },
        {
          "attribute_code": "custom_time",
          "value": "2016-01-11 00:00:00"
        }
      ]
    }
  ],
  "search_criteria": {
    "filter_groups": [
      {
        "filters": [
          {
            "field": "custom_time",
            "value": "2015-11-19",
            "condition_type": "gt"
          }
        ]
      }
    ]
  },
  "total_count": 1
}

Any guesses why this might be?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: QuoteFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions