Skip to content
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

Single item placed in cart after successful order placement doesn't show Price #77

Open
sanjeevyadavIT opened this issue Oct 8, 2019 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@sanjeevyadavIT
Copy link
Collaborator

Describe the bug
I'm not able to reproduce this bug every time, but 4-5 times I have encounter this bug, when I'm adding single 'Configurableitem to cart, sometimes, inCart` Screen price is not shown, but as soon as I add second item in cart or remove the same product and re-add again, price does show up.

Expected behavior
Price should be shown in Cart for items, and at bottom total price in Cart should also be shown

Current Behavior
In CartListItem price is 0
Also at bottom where total price in Cart is shown, is not showing

Steps to Reproduce
(Not 100% accurate)

  1. Use my store url and access token
  2. Try adding single item in Cart from list in HomeScreen
  3. Open Cart screen
  4. Try removing item from cart add different product in Cart from HomeScreen

Screenshots
error

Smartphone (please complete the following information):

  • Magento Version: [2.1.0]
  • Device: [Android Emulator Nexus 5X]
  • OS: [PIE]
  • Version [28]

Additional context
I will try to find a way to reproduce this app, if not close this issue if afterwards

@sanjeevyadavIT sanjeevyadavIT added the bug Something isn't working label Oct 8, 2019
@dimaportenko
Copy link
Owner

I don't think we doing any calculation of cart item price on the mobile app side. I remember I fixed something like this on the Magento side, but not 100% sure.

@sanjeevyadavIT
Copy link
Collaborator Author

true, but I don't know why but sometimes the price present in CartReducer inside quote: { items: [ { name: "Herra Pullover", price: 0 ... is zero so, this code

renderTotals() {
    const theme = this.context;
    const { items } = this.props.cart;
    const { totals } = styles;

    let sum = 0;
    if (items) {
      items.forEach((item) => {
        sum += item.price * item.qty;
      });
    }

    if (sum > 0) {
      return (
        <Text type="heading" style={totals(theme)}>
          Totals
          {' '}
          {sum.toFixed(2)}
        </Text>
      );
    }
  }

which is responsible to show total price in the cart is not getting render. Will try to reproduce.

@dimaportenko
Copy link
Owner

because of if (sum > 0) {

@sanjeevyadavIT
Copy link
Collaborator Author

yes, that is the problem, but that should never happen, the price in quote: { items: [ { name: "Herra Pullover", price: 0 ... should not be zero in first place.

@dimaportenko
Copy link
Owner

I found a similar issue from the project I worked on before, the reproducing steps were

  1. Complete an order
  2. Add one product to the cart.

@dimaportenko
Copy link
Owner

The fix was on the Magento side

// app/code/Custom/Rest/Plugin/Model/Quote/Item/RepositoryPlugin.php

<?php
/**
 * Created by PhpStorm.
 * User: Dmytro Portenko
 * Date: 10/16/18
 * Time: 10:36 PM
 */
namespace Custom\Rest\Plugin\Model\Quote\Item;
class RepositoryPlugin
{
    /**
     * Quote repository.
     *
     * @var \Magento\Quote\Api\CartRepositoryInterface
     */
    protected $quoteRepository;
    /**
     * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
     */
    public function __construct(
        \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
    ) {
        $this->quoteRepository = $quoteRepository;
    }
    public function beforeSave(
        \Magento\Quote\Model\Quote\Item\Repository $subject,
        \Magento\Quote\Api\Data\CartItemInterface $cartItem
    )
    {
        $cartId = $cartItem->getQuoteId();
        $quote = $this->quoteRepository->getActive($cartId);
        $quote->getShippingAddress();
    }
}

// app/code/Custom/Rest/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Model\Quote\Item\Repository">
        <plugin sortOrder="1" name="customRestRepository" type="Custom\Rest\Plugin\Model\Quote\Item\RepositoryPlugin"/>
    </type>
</config>

@sanjeevyadavIT
Copy link
Collaborator Author

I found a similar issue from the project I worked on before, the reproducing steps were

1. Complete an order

2. Add one product to the cart.

Yes you are right, just placed an order, and then added item to cart, and price was coming zero.

Also I don't know how to work with magento code on backend. I have never tried editing magento code itself. so will keep this point in mind.

@sanjeevyadavIT sanjeevyadavIT changed the title Sometimes single item in cart doesn't show Price Single item placed in cart after successful order placement doesn't show Price Oct 9, 2019
@dimaportenko
Copy link
Owner

I'll keep it open for now. I'll create a Magento extension for the fix.

@dimaportenko dimaportenko reopened this Oct 9, 2019
@sanjeevyadavIT
Copy link
Collaborator Author

sure no problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants