1

I have recently try to get product final price via rest api.

You can check special_price is already active and it will 20 but of price are coming 45 it will be 20.

API URL : http://magento.local/rest/V1/products/24-WB04

Magento Product API response.

{
  "id": 14,
  "sku": "24-WB04",
  "name": "Push It Messenger Bag",
  "attribute_set_id": 15,
  "price": 45,
  "status": 1,
  "visibility": 4,
  "type_id": "simple",
  "created_at": "2018-12-31 05:48:58",
  "updated_at": "2019-01-25 04:55:39",
  "extension_attributes": {
    "website_ids": [1],
    "category_links": [{
      "position": 0,
      "category_id": "3"
    }, {
      "position": 0,
      "category_id": "7"
    }, {
      "position": 0,
      "category_id": "4"
    }]
  },
  "product_links": [{
    "sku": "24-WB04",
    "link_type": "crosssell",
    "linked_product_sku": "24-WG082-pink",
    "linked_product_type": "simple",
    "position": 1
  }, {
    "sku": "24-WB04",
    "link_type": "crosssell",
    "linked_product_sku": "24-UG05",
    "linked_product_type": "simple",
    "position": 2
  }, {
    "sku": "24-WB04",
    "link_type": "crosssell",
    "linked_product_sku": "24-UG02",
    "linked_product_type": "simple",
    "position": 3
  }, {
    "sku": "24-WB04",
    "link_type": "crosssell",
    "linked_product_sku": "24-UG06",
    "linked_product_type": "simple",
    "position": 4
  }, {
    "sku": "24-WB04",
    "link_type": "upsell",
    "linked_product_sku": "24-MB02",
    "linked_product_type": "simple",
    "position": 1
  }, {
    "sku": "24-WB04",
    "link_type": "upsell",
    "linked_product_sku": "24-UB02",
    "linked_product_type": "simple",
    "position": 2
  }],
  "options": [],
  "media_gallery_entries": [{
    "id": 18,
    "media_type": "image",
    "label": "Image",
    "position": 1,
    "disabled": false,
    "types": ["image", "small_image", "thumbnail"],
    "file": "\/w\/b\/wb04-blue-0.jpg"
  }],
  "tier_prices": [],
  "custom_attributes": [{
    "attribute_code": "image",
    "value": "\/w\/b\/wb04-blue-0.jpg"
  }, {
    "attribute_code": "small_image",
    "value": "\/w\/b\/wb04-blue-0.jpg"
  }, {
    "attribute_code": "special_price",
    "value": "20.0000"
  }, {
    "attribute_code": "thumbnail",
    "value": "\/w\/b\/wb04-blue-0.jpg"
  }, {
    "attribute_code": "special_from_date",
    "value": "2019-01-25 04:55:39"
  }, {
    "attribute_code": "options_container",
    "value": "container2"
  }, {
    "attribute_code": "msrp_display_actual_price_type",
    "value": "0"
  }, {
    "attribute_code": "url_key",
    "value": "push-it-messenger-bag"
  }, {
    "attribute_code": "gift_message_available",
    "value": "0"
  }, {
    "attribute_code": "gst_origin",
    "value": "533"
  }, {
    "attribute_code": "required_options",
    "value": "0"
  }, {
    "attribute_code": "has_options",
    "value": "0"
  }, {
    "attribute_code": "image_label",
    "value": "Image"
  }, {
    "attribute_code": "small_image_label",
    "value": "Image"
  }, {
    "attribute_code": "thumbnail_label",
    "value": "Image"
  }, {
    "attribute_code": "tax_class_id",
    "value": "2"
  }, {
    "attribute_code": "category_ids",
    "value": ["3", "7", "4"]
  }, {
    "attribute_code": "description",
    "value": "<p>The name says so, but the Push It Messenger Bag is much more than a busy commuter's tote. It's a closet away from home when you're pedaling from class or work to gym and back or home again. It's the perfect size and shape for laptop, folded clothes, even extra shoes.<\/p>\r\n<ul>\r\n<li>Adjustable crossbody strap.<\/li>\r\n<li>Top handle.<\/li>\r\n<li>Zippered interior pocket.<\/li>\r\n<li>Secure clip closures.<\/li>\r\n<li>Durable fabric construction.<\/li>\r\n<\/ul>"
  }, {
    "attribute_code": "activity",
    "value": "20,23,8"
  }, {
    "attribute_code": "style_bags",
    "value": "27,28"
  }, {
    "attribute_code": "material",
    "value": "37,38"
  }, {
    "attribute_code": "color",
    "value": "49"
  }, {
    "attribute_code": "strap_bags",
    "value": "61,62,63,65,66,67"
  }, {
    "attribute_code": "features_bags",
    "value": "74,75,78,79"
  }, {
    "attribute_code": "eco_collection",
    "value": "0"
  }, {
    "attribute_code": "performance_fabric",
    "value": "1"
  }, {
    "attribute_code": "erin_recommends",
    "value": "0"
  }, {
    "attribute_code": "new",
    "value": "0"
  }, {
    "attribute_code": "sale",
    "value": "0"
  }]
}

Is there any function or plugin where I can set product final price and put it into response ?

1

2 Answers 2

2

Since magento 2.2.0 you can use special method for it.

For example, we have product with these params:

  1. SKU: 24-MB02
  2. Price: 59$
  3. Special price: 20$
  4. One drop-down required option with two values (+5$ and +10$)

API Link: http://m206.local:84/index.php/rest//V1/products-render-info?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB02&store_id=1&currency_code=USD

API Answer:

{
"items": [
    {
        "add_to_cart_button": {
            "post_data": "{\"action\":\"http:\\/\\/m206.local:84\\/default\\/fusion-backpack.html?options=cart\",\"data\":{\"product\":\"6\",\"uenc\":\"%uenc%\"}}",
            "url": "http://m206.local:84/default/fusion-backpack.html?options=cart",
            "required_options": true
        },
        "add_to_compare_button": {
            "post_data": null,
            "url": "{\"action\":\"http:\\/\\/m206.local:84\\/default\\/catalog\\/product_compare\\/add\\/\",\"data\":{\"product\":\"6\",\"uenc\":\"aHR0cDovL20yMDYubG9jYWw6ODQvaW5kZXgucGhwL3Jlc3QvL1YxL3Byb2R1Y3RzLXJlbmRlci1pbmZvP3NlYXJjaENyaXRlcmlhW2ZpbHRlcl9ncm91cHNdWzBdW2ZpbHRlcnNdWzBdW2ZpZWxkXT1za3Umc2VhcmNoQ3JpdGVyaWFbZmlsdGVyX2dyb3Vwc11bMF1bZmlsdGVyc11bMF1bdmFsdWVdPTI0LU1CMDImc3RvcmVfaWQ9MSZjdXJyZW5jeV9jb2RlPVVTRA,,\"}}",
            "required_options": null
        },
        "price_info": {
            "final_price": 20,
            "max_price": 20,
            "max_regular_price": 20,
            "minimal_regular_price": 25,
            "special_price": null,
            "minimal_price": 25,
            "regular_price": 59,
            "formatted_prices": {
                "final_price": "<span class=\"price\">$20.00</span>",
                "max_price": "<span class=\"price\">$20.00</span>",
                "minimal_price": "<span class=\"price\">$25.00</span>",
                "max_regular_price": "<span class=\"price\">$20.00</span>",
                "minimal_regular_price": null,
                "special_price": null,
                "regular_price": "<span class=\"price\">$59.00</span>"
            },
            "extension_attributes": {
                "msrp": {
                    "msrp_price": "<span class=\"price\">$0.00</span>",
                    "is_applicable": "",
                    "is_shown_price_on_gesture": "1",
                    "msrp_message": "",
                    "explanation_message": "Our price is lower than the manufacturer&#039;s &quot;minimum advertised price.&quot; As a result, we cannot show you the price in catalog or the product page. <br><br> You have no obligation to purchase the product once you know the price. You can simply remove the item from your cart."
                },
                "tax_adjustments": {
                    "final_price": 20,
                    "max_price": 20,
                    "max_regular_price": 20,
                    "minimal_regular_price": 25,
                    "special_price": 20,
                    "minimal_price": 25,
                    "regular_price": 59,
                    "formatted_prices": {
                        "final_price": "<span class=\"price\">$20.00</span>",
                        "max_price": "<span class=\"price\">$20.00</span>",
                        "minimal_price": "<span class=\"price\">$25.00</span>",
                        "max_regular_price": "<span class=\"price\">$20.00</span>",
                        "minimal_regular_price": null,
                        "special_price": "<span class=\"price\">$20.00</span>",
                        "regular_price": "<span class=\"price\">$59.00</span>"
                    }
                },
                "weee_attributes": [],
                "weee_adjustment": "<span class=\"price\">$20.00</span>"
            }
        },
        "images": [
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/1f44117d66b1d5cde587c13a0e45f902/m/b/mb02-gray-0.jpg",
                "code": "recently_viewed_products_grid_content_widget",
                "height": 300,
                "width": 240,
                "label": "Image",
                "resized_width": 240,
                "resized_height": 300
            },
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/c2e2d80491a314837e0a0b28435ceb8e/m/b/mb02-gray-0.jpg",
                "code": "recently_viewed_products_list_content_widget",
                "height": 340,
                "width": 270,
                "label": "Image",
                "resized_width": 270,
                "resized_height": 340
            },
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/5997dff03476beb538ee500dacdccf16/m/b/mb02-gray-0.jpg",
                "code": "recently_viewed_products_images_names_widget",
                "height": 90,
                "width": 75,
                "label": "Image",
                "resized_width": 75,
                "resized_height": 90
            },
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/1f44117d66b1d5cde587c13a0e45f902/m/b/mb02-gray-0.jpg",
                "code": "recently_compared_products_grid_content_widget",
                "height": 300,
                "width": 240,
                "label": "Image",
                "resized_width": 240,
                "resized_height": 300
            },
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/c2e2d80491a314837e0a0b28435ceb8e/m/b/mb02-gray-0.jpg",
                "code": "recently_compared_products_list_content_widget",
                "height": 340,
                "width": 270,
                "label": "Image",
                "resized_width": 270,
                "resized_height": 340
            },
            {
                "url": "http://m206.local:84/pub/media/catalog/product/cache/5997dff03476beb538ee500dacdccf16/m/b/mb02-gray-0.jpg",
                "code": "recently_compared_products_images_names_widget",
                "height": 90,
                "width": 75,
                "label": "Image",
                "resized_width": 75,
                "resized_height": 90
            }
        ],
        "url": "http://m206.local:84/default/fusion-backpack.html",
        "id": 6,
        "name": "Fusion Backpack",
        "type": "simple",
        "is_salable": "1",
        "store_id": 1,
        "currency_code": "USD",
        "extension_attributes": {
            "wishlist_button": {
                "post_data": null,
                "url": "{\"action\":\"http:\\/\\/m206.local:84\\/default\\/wishlist\\/index\\/add\\/\",\"data\":{\"product\":6,\"uenc\":\"aHR0cDovL20yMDYubG9jYWw6ODQvaW5kZXgucGhwL3Jlc3QvL1YxL3Byb2R1Y3RzLXJlbmRlci1pbmZvP3NlYXJjaENyaXRlcmlhW2ZpbHRlcl9ncm91cHNdWzBdW2ZpbHRlcnNdWzBdW2ZpZWxkXT1za3Umc2VhcmNoQ3JpdGVyaWFbZmlsdGVyX2dyb3Vwc11bMF1bZmlsdGVyc11bMF1bdmFsdWVdPTI0LU1CMDImc3RvcmVfaWQ9MSZjdXJyZW5jeV9jb2RlPVVTRA,,\"}}",
                "required_options": null
            },
            "review_html": "        <div class=\"product-reviews-summary short\">\n                <div class=\"rating-summary\">\n            <span class=\"label\"><span>Rating:</span></span>\n            <div class=\"rating-result\"\n                 id=\"rating-result_6\"\n                 title=\"67%\">\n                <span><span>67%</span></span>\n            </div>\n            <script type=\"text&#x2F;javascript\">var elem44teyd0u = document.querySelector('#rating-result_6 span');\nif (elem44teyd0u) {\nelem44teyd0u.style.width = '67%';\n}</script>        </div>\n                <div class=\"reviews-actions\">\n            <a class=\"action view\"\n               href=\"http://m206.local:84/default/fusion-backpack.html#reviews\">3                &nbsp;<span>Reviews                </span>\n            </a>\n        </div>\n    </div>\n"
        }
    }
]

}

If you want to get only price_info section use this query:

http://m206.local:84/index.php/rest//V1/products-render-info?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB02&store_id=1&currency_code=USD&fields=items[price_info]

0

As magento official documentation they are separately giving prices API which is as below :

So they are not including prices related data in product API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.