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

Magento 2 grand total not including shipping until reload #10144

Closed haydencarlson closed 7 years ago

haydencarlson commented 7 years ago

Preconditions

Magento 2.0, PHP 7.0.20-2, MySQL 5.7.18 Running Ubuntu

Steps to reproduce


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
    $grandTotal = $cart->getQuote()->getGrandTotal();

This is in my ConfigProvider. I console.log checkoutConfig.payment.[my_gateway]

On the first load of the checkout when I get the grand total it does not include shipping cost. If I reload page or click go to checkout again I get the correct amount.

The totals are properly shown on the checkout page just not through the method renderer.

Expected result

Correct Grand total.

haydencarlson commented 7 years ago

Has anyone else had this issue?

haydencarlson commented 7 years ago

BMUP

minesh0111 commented 7 years ago

@haydencarlson yes grand total does not include shipping amount. checked in version 2.1.5

haydencarlson commented 7 years ago

But it only does it on first load. If I reload the checkout it gets the right price

haydencarlson commented 7 years ago

Is this a bug in CE 2.1.5

haydencarlson commented 7 years ago

Bump...

magento-engcom-team commented 7 years ago

Hi @haydencarlson \Magento\Quote\Api\CartTotalRepositoryInterface is supposed to be used to obtain totals.

kashukov commented 2 years ago

CartTotalRepositoryInterface doesn't work. How to reproduce:

1) add 7 'Jupiter All-Weather Trainer' items from the default store (Magento ver. 2.4.2-p1).

2)

private $cartTotalsRepository;

public function __construct(
    ...
    CartTotalRepositoryInterface $cartTotalsRepository,
    ...
)
{
    ...
    $this->cartTotalsRepository = $cartTotalsRepository;
}

$objectManager = ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');
$quote = $cart->getQuote();
$quoteTotals = $this->cartTotalsRepository->get($quote->getId());
$totalAmount = $quoteTotals->getGrandTotal();

$totalAmount here is different in comparison with the order total on checkout page. It doesn't include the shipping amount. If checkout page is refreshed then $totalAmount becomes correct.

kashukov commented 2 years ago

Can be solved by cache cleaning. At least it works locally.

$objectManager = ObjectManager::getInstance();
$cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
foreach ($cacheFrontendPool as $cacheFrontend) {
    $cacheFrontend->getBackend()->clean();
}