Configurable Product is returning Price Zero magento 2.x 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|improve this answer
























    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|improve this answer




























      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|improve this answer


























        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|improve this answer













        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|improve this answer












        share|improve this answer



        share|improve this answer










        answered 11 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

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto