Configurable Product is returning Price Zero magento 2.x rest Api Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraREST API Order including a configurable productNeed REST api for “Add to Wishlist” in Magento 2Get all options for configurable product Magento 2.0 REST ApiMagento rest API configurable product and category listMagento 2: Creating configurable product using the REST APIPrice In Configurable Product is 0 in REST API Response : Magento 2Placing Multiple Orders in Magento 2.1 using REST APIMultiple Products in one Cart magento 2.1 REST ApiHow to get product quantity by using REST API product filterHow to Update Magento 2 configurable child products price by REST API

How do I check if a string is entirely made of the same substring?

Error: Syntax error. Missing ')' for CASE Statement

Justification for leaving new position after a short time

Book with legacy programming code on a space ship that the main character hacks to escape

What is the least dense liquid under normal conditions?

Israeli soda type drink

How to get even lighting when using flash for group photos near wall?

Mistake in years of experience in resume?

Is it acceptable to use working hours to read general interest books?

How to open locks without disable device?

What is the best way to deal with NPC-NPC combat?

My admission is revoked after accepting the admission offer

How to translate "red flag" into Spanish?

Economise space with floats

What's parked in Mil Moscow helicopter plant?

Second order approximation of the loss function (Deep learning book, 7.33)

Map material from china not allowed to leave the country

With indentation set to `0em`, when using a line break, there is still an indentation of a size of a space

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

What do you call the part of a novel that is not dialog?

Function to calculate red-edgeNDVI in Google Earth Engine

Why did Israel vote against lifting the American embargo on Cuba?

Where did Arya get these scars?

Protagonist's race is hidden - should I reveal it?



Configurable Product is returning Price Zero magento 2.x rest Api



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraREST API Order including a configurable productNeed REST api for “Add to Wishlist” in Magento 2Get all options for configurable product Magento 2.0 REST ApiMagento rest API configurable product and category listMagento 2: Creating configurable product using the REST APIPrice In Configurable Product is 0 in REST API Response : Magento 2Placing Multiple Orders in Magento 2.1 using REST APIMultiple Products in one Cart magento 2.1 REST ApiHow to get product quantity by using REST API product filterHow to Update Magento 2 configurable child products price by REST API



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Why Price is zero in response.



I am hitting Url:



https://example.com/index.php/rest/V1/products/sku


Response:




"id": 176,
"sku": "8544501",
"name": "BATA-8544501",
"attribute_set_id": 4,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2018-01-12 07:25:07",
"updated_at": "2018-01-12 07:25:07",
"weight": 0.5,
"extension_attributes":
"configurable_product_options": [

"id": 73,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [

"value_index": 10

],
"product_id": 176
,

"id": 74,
"attribute_id": "135",
"label": "Size",
"position": 1,
"values": [

"value_index": 4
,

"value_index": 5
,

"value_index": 6
,

"value_index": 7
,

"value_index": 8

],
"product_id": 176

],
"configurable_product_links": [
171,
172,
173,
174,
175
]
,
"product_links": [],
"options": [],
"media_gallery_entries": [

"id": 285,
"media_type": "image",
"label": null,
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/8/5/854-4501-a_1_2.jpg"
,

"id": 286,
"media_type": "image",
"label": null,
"position": 2,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-b_2.jpg"
,

"id": 287,
"media_type": "image",
"label": null,
"position": 3,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-c_2.jpg"
,

"id": 288,
"media_type": "image",
"label": null,
"position": 4,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-d_2.jpg"
,

"id": 289,
"media_type": "image",
"label": null,
"position": 5,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-e_2.jpg"

],
"tier_prices": [],
"custom_attributes": [

"attribute_code": "meta_title",
"value": "BATA-8544501"
,

"attribute_code": "meta_keyword",
"value": "BATA-8544501"
,

"attribute_code": "meta_description",
"value": " "
,

"attribute_code": "image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "small_image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "thumbnail",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "category_ids",
"value": [
"83",
"97",
"121"
]
,

"attribute_code": "options_container",
"value": "container2"
,

"attribute_code": "required_options",
"value": "1"
,

"attribute_code": "has_options",
"value": "1"
,

"attribute_code": "url_key",
"value": "bata-8544501"
,

"attribute_code": "tax_class_id",
"value": "2"
,

"attribute_code": "gift_message_available",
"value": "2"
,

"attribute_code": "size",
"value": "4"

]



There is zero in price, It should return base price. Is there any solution?










share|improve this question
























  • Did you solve your issue?

    – Gem
    Apr 30 '18 at 6:22











  • for configure product you need to pass attribute ID and Attribute VALUE in body param.

    – Aaditya
    Sep 24 '18 at 8:24

















1















Why Price is zero in response.



I am hitting Url:



https://example.com/index.php/rest/V1/products/sku


Response:




"id": 176,
"sku": "8544501",
"name": "BATA-8544501",
"attribute_set_id": 4,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2018-01-12 07:25:07",
"updated_at": "2018-01-12 07:25:07",
"weight": 0.5,
"extension_attributes":
"configurable_product_options": [

"id": 73,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [

"value_index": 10

],
"product_id": 176
,

"id": 74,
"attribute_id": "135",
"label": "Size",
"position": 1,
"values": [

"value_index": 4
,

"value_index": 5
,

"value_index": 6
,

"value_index": 7
,

"value_index": 8

],
"product_id": 176

],
"configurable_product_links": [
171,
172,
173,
174,
175
]
,
"product_links": [],
"options": [],
"media_gallery_entries": [

"id": 285,
"media_type": "image",
"label": null,
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/8/5/854-4501-a_1_2.jpg"
,

"id": 286,
"media_type": "image",
"label": null,
"position": 2,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-b_2.jpg"
,

"id": 287,
"media_type": "image",
"label": null,
"position": 3,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-c_2.jpg"
,

"id": 288,
"media_type": "image",
"label": null,
"position": 4,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-d_2.jpg"
,

"id": 289,
"media_type": "image",
"label": null,
"position": 5,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-e_2.jpg"

],
"tier_prices": [],
"custom_attributes": [

"attribute_code": "meta_title",
"value": "BATA-8544501"
,

"attribute_code": "meta_keyword",
"value": "BATA-8544501"
,

"attribute_code": "meta_description",
"value": " "
,

"attribute_code": "image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "small_image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "thumbnail",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "category_ids",
"value": [
"83",
"97",
"121"
]
,

"attribute_code": "options_container",
"value": "container2"
,

"attribute_code": "required_options",
"value": "1"
,

"attribute_code": "has_options",
"value": "1"
,

"attribute_code": "url_key",
"value": "bata-8544501"
,

"attribute_code": "tax_class_id",
"value": "2"
,

"attribute_code": "gift_message_available",
"value": "2"
,

"attribute_code": "size",
"value": "4"

]



There is zero in price, It should return base price. Is there any solution?










share|improve this question
























  • Did you solve your issue?

    – Gem
    Apr 30 '18 at 6:22











  • for configure product you need to pass attribute ID and Attribute VALUE in body param.

    – Aaditya
    Sep 24 '18 at 8:24













1












1








1








Why Price is zero in response.



I am hitting Url:



https://example.com/index.php/rest/V1/products/sku


Response:




"id": 176,
"sku": "8544501",
"name": "BATA-8544501",
"attribute_set_id": 4,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2018-01-12 07:25:07",
"updated_at": "2018-01-12 07:25:07",
"weight": 0.5,
"extension_attributes":
"configurable_product_options": [

"id": 73,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [

"value_index": 10

],
"product_id": 176
,

"id": 74,
"attribute_id": "135",
"label": "Size",
"position": 1,
"values": [

"value_index": 4
,

"value_index": 5
,

"value_index": 6
,

"value_index": 7
,

"value_index": 8

],
"product_id": 176

],
"configurable_product_links": [
171,
172,
173,
174,
175
]
,
"product_links": [],
"options": [],
"media_gallery_entries": [

"id": 285,
"media_type": "image",
"label": null,
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/8/5/854-4501-a_1_2.jpg"
,

"id": 286,
"media_type": "image",
"label": null,
"position": 2,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-b_2.jpg"
,

"id": 287,
"media_type": "image",
"label": null,
"position": 3,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-c_2.jpg"
,

"id": 288,
"media_type": "image",
"label": null,
"position": 4,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-d_2.jpg"
,

"id": 289,
"media_type": "image",
"label": null,
"position": 5,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-e_2.jpg"

],
"tier_prices": [],
"custom_attributes": [

"attribute_code": "meta_title",
"value": "BATA-8544501"
,

"attribute_code": "meta_keyword",
"value": "BATA-8544501"
,

"attribute_code": "meta_description",
"value": " "
,

"attribute_code": "image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "small_image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "thumbnail",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "category_ids",
"value": [
"83",
"97",
"121"
]
,

"attribute_code": "options_container",
"value": "container2"
,

"attribute_code": "required_options",
"value": "1"
,

"attribute_code": "has_options",
"value": "1"
,

"attribute_code": "url_key",
"value": "bata-8544501"
,

"attribute_code": "tax_class_id",
"value": "2"
,

"attribute_code": "gift_message_available",
"value": "2"
,

"attribute_code": "size",
"value": "4"

]



There is zero in price, It should return base price. Is there any solution?










share|improve this question
















Why Price is zero in response.



I am hitting Url:



https://example.com/index.php/rest/V1/products/sku


Response:




"id": 176,
"sku": "8544501",
"name": "BATA-8544501",
"attribute_set_id": 4,
"price": 0,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"created_at": "2018-01-12 07:25:07",
"updated_at": "2018-01-12 07:25:07",
"weight": 0.5,
"extension_attributes":
"configurable_product_options": [

"id": 73,
"attribute_id": "93",
"label": "Color",
"position": 0,
"values": [

"value_index": 10

],
"product_id": 176
,

"id": 74,
"attribute_id": "135",
"label": "Size",
"position": 1,
"values": [

"value_index": 4
,

"value_index": 5
,

"value_index": 6
,

"value_index": 7
,

"value_index": 8

],
"product_id": 176

],
"configurable_product_links": [
171,
172,
173,
174,
175
]
,
"product_links": [],
"options": [],
"media_gallery_entries": [

"id": 285,
"media_type": "image",
"label": null,
"position": 1,
"disabled": false,
"types": [
"image",
"small_image",
"thumbnail"
],
"file": "/8/5/854-4501-a_1_2.jpg"
,

"id": 286,
"media_type": "image",
"label": null,
"position": 2,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-b_2.jpg"
,

"id": 287,
"media_type": "image",
"label": null,
"position": 3,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-c_2.jpg"
,

"id": 288,
"media_type": "image",
"label": null,
"position": 4,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-d_2.jpg"
,

"id": 289,
"media_type": "image",
"label": null,
"position": 5,
"disabled": false,
"types": [],
"file": "/8/5/854-4501-e_2.jpg"

],
"tier_prices": [],
"custom_attributes": [

"attribute_code": "meta_title",
"value": "BATA-8544501"
,

"attribute_code": "meta_keyword",
"value": "BATA-8544501"
,

"attribute_code": "meta_description",
"value": " "
,

"attribute_code": "image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "small_image",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "thumbnail",
"value": "/8/5/854-4501-a_1_2.jpg"
,

"attribute_code": "category_ids",
"value": [
"83",
"97",
"121"
]
,

"attribute_code": "options_container",
"value": "container2"
,

"attribute_code": "required_options",
"value": "1"
,

"attribute_code": "has_options",
"value": "1"
,

"attribute_code": "url_key",
"value": "bata-8544501"
,

"attribute_code": "tax_class_id",
"value": "2"
,

"attribute_code": "gift_message_available",
"value": "2"
,

"attribute_code": "size",
"value": "4"

]



There is zero in price, It should return base price. Is there any solution?







magento2 rest android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 24 '18 at 8:31









Aaditya

4,52621139




4,52621139










asked Jan 29 '18 at 14:58









Shozib RasoolShozib Rasool

539




539












  • Did you solve your issue?

    – Gem
    Apr 30 '18 at 6:22











  • for configure product you need to pass attribute ID and Attribute VALUE in body param.

    – Aaditya
    Sep 24 '18 at 8:24

















  • Did you solve your issue?

    – Gem
    Apr 30 '18 at 6:22











  • for configure product you need to pass attribute ID and Attribute VALUE in body param.

    – Aaditya
    Sep 24 '18 at 8:24
















Did you solve your issue?

– Gem
Apr 30 '18 at 6:22





Did you solve your issue?

– Gem
Apr 30 '18 at 6:22













for configure product you need to pass attribute ID and Attribute VALUE in body param.

– Aaditya
Sep 24 '18 at 8:24





for configure product you need to pass attribute ID and Attribute VALUE in body param.

– Aaditya
Sep 24 '18 at 8:24










1 Answer
1






active

oldest

votes


















0














This is a known bug.



This issue is raised in github and the bug seems to be open:
https://github.com/magento/magento2/issues/10644



The Magento 2 REST API returns price zero for configurable products. Conceptually a Configurable Product doesn’t have a price associated with it, only the child products associated with it will have the price.



Solution:



The first step in resolving this problem is to find the code which returns 0.



This is the core code that returns the price as 0:



//Classname MagentoConfigurableProductModelProductTypeConfigurablePrice
public function getPrice($product)

if (!empty($product))
$simpleProductOption = $product->getCustomOption('simple_product');
if (!empty($simpleProductOption))
$simpleProduct = $simpleProductOption->getProduct();
if (!empty($simpleProduct))
return $simpleProduct->getPrice();



return 0;

}


The Above core code function needs to be Hooked using Interceptor Plugin Approach.



In the new Plugin function we need to send the final price of the configurable product.



You'll need the following XML in your module's di.xml file:



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoConfigurableProductModelProductTypeConfigurablePrice">
<plugin name="namespace_configurableapiprice_plugin_product_type_configurable_price" type="NameSpaceConfigurableApiPricePluginProductTypeConfigurablePrice"/>
</type>
</config>


Here is the needed plugin using the around method to hook in to the existing function, since we need the product object argument to get the final price like this:



<?php

namespace NameSpaceConfigurableApiPricePluginProductTypeConfigurable;

class Price

public function aroundGetPrice($subject, $proceed, $product)

if($product->getTypeId() == "configurable")
return $product->getFinalPrice();

else
$returnValue = $proceed($product);
return $returnValue;





Hope it helps.





share























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f211358%2fconfigurable-product-is-returning-price-zero-magento-2-x-rest-api%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is a known bug.



    This issue is raised in github and the bug seems to be open:
    https://github.com/magento/magento2/issues/10644



    The Magento 2 REST API returns price zero for configurable products. Conceptually a Configurable Product doesn’t have a price associated with it, only the child products associated with it will have the price.



    Solution:



    The first step in resolving this problem is to find the code which returns 0.



    This is the core code that returns the price as 0:



    //Classname MagentoConfigurableProductModelProductTypeConfigurablePrice
    public function getPrice($product)

    if (!empty($product))
    $simpleProductOption = $product->getCustomOption('simple_product');
    if (!empty($simpleProductOption))
    $simpleProduct = $simpleProductOption->getProduct();
    if (!empty($simpleProduct))
    return $simpleProduct->getPrice();



    return 0;

    }


    The Above core code function needs to be Hooked using Interceptor Plugin Approach.



    In the new Plugin function we need to send the final price of the configurable product.



    You'll need the following XML in your module's di.xml file:



    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoConfigurableProductModelProductTypeConfigurablePrice">
    <plugin name="namespace_configurableapiprice_plugin_product_type_configurable_price" type="NameSpaceConfigurableApiPricePluginProductTypeConfigurablePrice"/>
    </type>
    </config>


    Here is the needed plugin using the around method to hook in to the existing function, since we need the product object argument to get the final price like this:



    <?php

    namespace NameSpaceConfigurableApiPricePluginProductTypeConfigurable;

    class Price

    public function aroundGetPrice($subject, $proceed, $product)

    if($product->getTypeId() == "configurable")
    return $product->getFinalPrice();

    else
    $returnValue = $proceed($product);
    return $returnValue;





    Hope it helps.





    share



























      0














      This is a known bug.



      This issue is raised in github and the bug seems to be open:
      https://github.com/magento/magento2/issues/10644



      The Magento 2 REST API returns price zero for configurable products. Conceptually a Configurable Product doesn’t have a price associated with it, only the child products associated with it will have the price.



      Solution:



      The first step in resolving this problem is to find the code which returns 0.



      This is the core code that returns the price as 0:



      //Classname MagentoConfigurableProductModelProductTypeConfigurablePrice
      public function getPrice($product)

      if (!empty($product))
      $simpleProductOption = $product->getCustomOption('simple_product');
      if (!empty($simpleProductOption))
      $simpleProduct = $simpleProductOption->getProduct();
      if (!empty($simpleProduct))
      return $simpleProduct->getPrice();



      return 0;

      }


      The Above core code function needs to be Hooked using Interceptor Plugin Approach.



      In the new Plugin function we need to send the final price of the configurable product.



      You'll need the following XML in your module's di.xml file:



      <?xml version="1.0"?>
      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="MagentoConfigurableProductModelProductTypeConfigurablePrice">
      <plugin name="namespace_configurableapiprice_plugin_product_type_configurable_price" type="NameSpaceConfigurableApiPricePluginProductTypeConfigurablePrice"/>
      </type>
      </config>


      Here is the needed plugin using the around method to hook in to the existing function, since we need the product object argument to get the final price like this:



      <?php

      namespace NameSpaceConfigurableApiPricePluginProductTypeConfigurable;

      class Price

      public function aroundGetPrice($subject, $proceed, $product)

      if($product->getTypeId() == "configurable")
      return $product->getFinalPrice();

      else
      $returnValue = $proceed($product);
      return $returnValue;





      Hope it helps.





      share

























        0












        0








        0







        This is a known bug.



        This issue is raised in github and the bug seems to be open:
        https://github.com/magento/magento2/issues/10644



        The Magento 2 REST API returns price zero for configurable products. Conceptually a Configurable Product doesn’t have a price associated with it, only the child products associated with it will have the price.



        Solution:



        The first step in resolving this problem is to find the code which returns 0.



        This is the core code that returns the price as 0:



        //Classname MagentoConfigurableProductModelProductTypeConfigurablePrice
        public function getPrice($product)

        if (!empty($product))
        $simpleProductOption = $product->getCustomOption('simple_product');
        if (!empty($simpleProductOption))
        $simpleProduct = $simpleProductOption->getProduct();
        if (!empty($simpleProduct))
        return $simpleProduct->getPrice();



        return 0;

        }


        The Above core code function needs to be Hooked using Interceptor Plugin Approach.



        In the new Plugin function we need to send the final price of the configurable product.



        You'll need the following XML in your module's di.xml file:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoConfigurableProductModelProductTypeConfigurablePrice">
        <plugin name="namespace_configurableapiprice_plugin_product_type_configurable_price" type="NameSpaceConfigurableApiPricePluginProductTypeConfigurablePrice"/>
        </type>
        </config>


        Here is the needed plugin using the around method to hook in to the existing function, since we need the product object argument to get the final price like this:



        <?php

        namespace NameSpaceConfigurableApiPricePluginProductTypeConfigurable;

        class Price

        public function aroundGetPrice($subject, $proceed, $product)

        if($product->getTypeId() == "configurable")
        return $product->getFinalPrice();

        else
        $returnValue = $proceed($product);
        return $returnValue;





        Hope it helps.





        share













        This is a known bug.



        This issue is raised in github and the bug seems to be open:
        https://github.com/magento/magento2/issues/10644



        The Magento 2 REST API returns price zero for configurable products. Conceptually a Configurable Product doesn’t have a price associated with it, only the child products associated with it will have the price.



        Solution:



        The first step in resolving this problem is to find the code which returns 0.



        This is the core code that returns the price as 0:



        //Classname MagentoConfigurableProductModelProductTypeConfigurablePrice
        public function getPrice($product)

        if (!empty($product))
        $simpleProductOption = $product->getCustomOption('simple_product');
        if (!empty($simpleProductOption))
        $simpleProduct = $simpleProductOption->getProduct();
        if (!empty($simpleProduct))
        return $simpleProduct->getPrice();



        return 0;

        }


        The Above core code function needs to be Hooked using Interceptor Plugin Approach.



        In the new Plugin function we need to send the final price of the configurable product.



        You'll need the following XML in your module's di.xml file:



        <?xml version="1.0"?>
        <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="MagentoConfigurableProductModelProductTypeConfigurablePrice">
        <plugin name="namespace_configurableapiprice_plugin_product_type_configurable_price" type="NameSpaceConfigurableApiPricePluginProductTypeConfigurablePrice"/>
        </type>
        </config>


        Here is the needed plugin using the around method to hook in to the existing function, since we need the product object argument to get the final price like this:



        <?php

        namespace NameSpaceConfigurableApiPricePluginProductTypeConfigurable;

        class Price

        public function aroundGetPrice($subject, $proceed, $product)

        if($product->getTypeId() == "configurable")
        return $product->getFinalPrice();

        else
        $returnValue = $proceed($product);
        return $returnValue;





        Hope it helps.






        share











        share


        share










        answered 3 mins ago









        rubenromaorubenromao

        83




        83



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f211358%2fconfigurable-product-is-returning-price-zero-magento-2-x-rest-api%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2