magento-react-native
magento-react-native copied to clipboard
Single item placed in cart after successful order placement doesn't show Price
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)
- Use my store url and access token
- Try adding single item in Cart from list in
HomeScreen - Open Cart screen
- Try removing item from cart add different product in Cart from
HomeScreen
Screenshots

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
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.
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.
because of if (sum > 0) {
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.
I found a similar issue from the project I worked on before, the reproducing steps were
- Complete an order
- Add one product to the cart.
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>
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.
I'll keep it open for now. I'll create a Magento extension for the fix.
sure no problem