magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.31k forks source link

2.3.1 REST-API: order: custom product price not accepted #22215

Closed Darkwolf81 closed 5 years ago

Darkwolf81 commented 5 years ago

Preconditions (*)

  1. Magento 2.3.0 / 2.3.1
  2. At least 1 product / customer

Steps to reproduce (*)

  1. Create an order with rest api
  2. Set custom price in cart_item

Expected result (*)

  1. The given price is used for this product

Actual result (*)

  1. price is ignored / overridden with the original price

I used the same logic in Magento 1, there the custom price is used in the order. In Magento 2 i tried to debug the problem. I saw in a price setter function when the price is set, first the custom price is used, then the function called again with the store price.

I used following code to set the custom price API: /rest/V1/carts/mine/items

$productData = [
    'cart_item' => [
        'quote_id' => $quote_id,
        'sku' => 'J-Park',
        'qty' => 1,
        'price' => '9.0',
        "productOption" => [
            "extensionAttributes" => [
                "customOptions" => [
                    [
                        "optionId" => $option_id,
                        "optionValue" => "My Text"
                    ]
                ]
            ]
        ]
    ]
];
m2-assistant[bot] commented 5 years ago

Hi @Darkwolf81. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@Darkwolf81 do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

Darkwolf81 commented 5 years ago

@magento-engcom-team give me 2.3-develop instance

magento-engcom-team commented 5 years ago

Hi @Darkwolf81. Thank you for your request. I'm working on Magento 2.3-develop instance for you

magento-engcom-team commented 5 years ago

Hi @Darkwolf81, here is your Magento instance. Admin access: https://i-22215-2-3-develop.instances.magento-community.engineering/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

Darkwolf81 commented 5 years ago

I could reproduct the issue in vanilla magento. Product price is 17 $, API custom price was 9 $, order is still 17 $.

m2-assistant[bot] commented 5 years ago

Hi @engcom-backlog-nazar. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

ghost commented 5 years ago

Hi @Darkwolf81, thank you for you report, you can use many ways to set custom price, one of this is observer and plugin.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_product_add_after">
        <observer name="customprice" instance="Test\Hello\Observer\CustomPrice" />
    </event>
</config>
namespaceTest\Hello\Observer;

    use Magento\Framework\Event\ObserverInterface;
    use Magento\Framework\App\RequestInterface;

    class CustomPrice implements ObserverInterface
    {
        public function execute(\Magento\Framework\Event\Observer $observer) {
            $item = $observer->getEvent()->getData('quote_item');         
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            $price = 100; //set your price here
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            $item->getProduct()->setIsSuperMode(true);
        }

    }

Thanks for collaboration.

Darkwolf81 commented 5 years ago

Thanks for this. I tried the code, but it dont work in the rest api, event is not fired. And i dont understand why this is not a bug. It is possible to tell a price value in the rest order product call. But it is ignored / overridden by the original price. That worked in Magento 1, and we use this for long time, then it should work in Magento 2, too.

teqt commented 5 years ago

I am running into the exact same issue.

How is this not a bug? API's are designed to utilize internal functionality without having to create plugins. Second, if that parameter is not supposed to do anything, then why does the parameter exist in the first place? Please, reopen this issue.

m2-assistant[bot] commented 5 years ago

Hi @shikhamis11. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

magento-engcom-team commented 5 years ago

:white_check_mark: Confirmed by @shikhamis11 Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-99855, MAGETWO-99856 were created

Issue Available: @shikhamis11, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] commented 5 years ago

Hi @shikhamis11. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


shikhamis11 commented 5 years ago

hi @Darkwolf81 & @teqt , while working on this issue I found that there is event available that is called during rest api and with this you can change the price of the product while add to cart in REST API <event name="sales_quote_item_set_product"> </event>

jimmy-lion commented 5 years ago

@magento-engcom-team I'm testing this on the 2.3-develop and this is not currently working. Where can I check tickets MAGETWO-99855 and MAGETWO-99856. Are they not public? Can you update me on the state of these? Thanks

@shikhamis11 did you manage to make this work without adding an observer? Thanks

fritzmg commented 5 years ago

Has the original issue been fixed at all? Is it possible to set a cart item's price when adding the item via the REST API?

danielrona commented 4 years ago

@shikhamis11 @magento-engcom-team

Is there any information on when this issue will be fixed? As this is still not working with 2.3.3

skast96 commented 4 years ago

This is still an issue in 2.3.5, which is really annoying...

0xMatt commented 3 years ago

bump

orismology commented 2 years ago

@shikhamis11 Why was this issue closed? This remains a bug in the API.

LeanderFS commented 2 years ago

This issue is also present when creating a negotiable quote (EE module) using the API. To circumvent the issue, I've tried a custom API endpoint which explicitly sets the custom_price value when adding items to a quote, but the custom price gets overridden later in the chain. Making it impossible to create an order using custom prices using the API.

What's the status of internal tickets MAGETWO-99856 and MAGETWO-99855?

4thePeace2 commented 1 year ago

Magento ver. 2.4.2 issue is still present. Can we have API V2 with fix in it? 4 years pass...