-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Products added to cart with REST API give total prices equal to zero #2991
Comments
The problem comes here: |
@degaray Could you please provide more detailed steps to reproduce the issue? How did you create your quote and customer? |
1.- I create a new instance of Magento2 using
I get an auth token. 3.- I create a product calling:
4.- I create a user using
4.1- I login using 5.- I create a cart using: 6.- I add an item to the cart using:
7.- I finally call
|
You can find further reference to this issue in this question: http://magento.stackexchange.com/questions/97373/items-added-to-cart-with-no-price-on-magento2 |
@degaray Thank you for reporting this issue. We have created an internal ticket |
…omer using API #2991 added unit tests
@degaray Closing this ticket, since the fix is already delivered with the linked commits. Please feel free to reopen if you have any additional questions regarding this. |
This issue is not fixed! I have tried 2.0.5 and it did not work. I added the extra line as in bdd8d3b and the bug still appears. This is a VERY serious bug. As I cannot collect the value of the cart, thus I cannot get the list of payment methods, use coupons, or update the cart information from the server. |
Same here. I have tried 2.0.7 and it did not work. |
Update. You can user rest/V1/carts/mine/billing-address to add address to cart. Then add item to cart so you can have item with the correct price.
|
Yes @manuelDistefano however, don't you think that is a bug? Specially if you are selling virtual products? |
Yes @degaray, it's a problem for sure, and i'm selling virtual products too. But i can use this "workaround" until they fix it. |
@ishakhsuvarov Can you reopen ticket? Bug is not fixed... |
@ishakhsuvarov Please tell me how to extend model Repository.php from core file to my project. I tried extending the model but than add to product api is giving error as below. message": "Source class "%1" for "%2" generation does not exist.", |
Any one has a solution of this issue? i am using 2.1.0 and 0 price issue which degaray mentioned above is still there |
@tejashp77 use this event >> sales_quote_save_before
Please note that the region id must not be null ** For virtual products, you don't need to set shipping address |
from API call it not goes to 'sales_quote_save_before' event. i have tried by put events.xml in etc folder and etc/frontend both. |
just put it in etc/events.xml should be enough. This is how i put the event. It should be tricked when your customer add a product to cart. please check again :) |
Reopened the ticket due to several reports of reproducing the issue. |
@ulftietze |
@cyberkiller6
Problem here is, that this does not fix the issue with the initialize adding a product directly after creating the quote. |
here i am to annoy you :D you said to me i should do that if you dont react ^^ Greetz, |
Hi @ulftietze |
Hey Guys, i've found a temporary workaround, which works at least in my scope to prevent this behavior. In /**
* {@inheritdoc}
*/
public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
{
/** @var \Magento\Quote\Model\Quote $quote */
$cartId = $cartItem->getQuoteId();
$quote = $this->quoteRepository->getActive($cartId);
$quote->getShippingAddress();
$quoteItems = $quote->getItems();
$quoteItems[] = $cartItem;
$quote->setItems($quoteItems);
$this->quoteRepository->save($quote);
$quote->collectTotals();
return $quote->getLastAddedItem();
} @okorshenko thanks for reopening this 👍 have a nice week, |
Thank you for your suggestion but I can not make it work for me. Would you mind if I can see how you add item to cart. I want to add shopping bag item to cart when customer click [Proceed to Checkout] in Cart page. Then redirect to confirm page. This is my code, but it's always redirect to cart page again, I don't want that. If I try to not redirect to cart, the price will be 0. public function addShoppingBag()
{
$shoppingBagSku = $this->helper->getShoppingBagSku();
$shoppingBagProduct = $this->productRepository->get($shoppingBagSku);
$params = array(
'product' => $shoppingBagProduct->getId(),
'qty' => 1
);
$request = new \Magento\Framework\DataObject();
$request->setData($params);
$this->cart->addProduct($shoppingBagProduct, $request);
$this->cart->save();
$this->cart->getQuote()->setTotalsCollectedFlag(false)->collectTotals()->save();
} |
Hey @hoangtuan21193, i think this is the wrong point to discuss about custom errors here. Anyway, i'm not like a bad person :D If you take a look at the last fix in the core, also included in this issue. Dunno if this works, but make sure that before you save the quote, you call this function: If you have more problems on this, you may create an stackoverflow question and send me the link ^^ Have a nice day, |
Thank you for your response, I tried your suggestion but no luck. Have a nice day too! 💯 |
Hi @TomashKhamlai. Thank you for working on this issue.
|
@TomashKhamlai Thank you for verifying the issue. Unfortunately, not enough information was provided to created internal ticket. Please consider adding the following:
Once all required information is added, please add label |
@TomashKhamlai Thank you for verifying the issue. Based on the provided information internal tickets |
I believe the main problem with this is in the $old = $this->getShippingAddress();
if (!empty($old)) {
$old->addData($address->getData());
} else {
$this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
}
My suggestion is to add check there like this: $old = $this->getShippingAddress();
if (!empty($old)) {
$old->addData($address->getData());
if ($address->isDeleted()) {
$old->setId(null);
}
} else {
$this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
} or always reset id field |
Hi @degaray. Thank you for your report and collaboration! The issue was fixed by Magento team. The fix will be available with the upcoming |
@magento-team |
Preconditions (*)
Steps to reproduce (*)
1.Execute:
Expected result (*)
Actual result (*)
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:I get the following response:
Also when I call
[GET] /products
I get the right price in the response, this is the response I get:Any guesses why this might be?
The text was updated successfully, but these errors were encountered: