cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

i want to Get all shopping cart items, subtotal, grand total, billing & shipping address in one step checkout magento 2 in storefront (Home Page) . according to the this link :https://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_step.html#add-your-step-to-the-...

I add new step in checkout page but also according to the this link :http://blog.chapagain.com.np/magento-2-get-all-shopping-cart-items-subtotal-grand-total-billing-ship...

in part of (Using Dependency Injection (DI)) , on that site I do not know where is the directory of (phtml) file and also (php) file.

3 REPLIES 3

Re: Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

Hello amir_khajepour

 

You have make separate extension for this in app/code/[Extension Namespace]/[Extension ModuleName] example (app/code/Conviator/AO/)

 

You can use this extension for the reference.

Url: https://github.com/sbodak/magento2-checkout-custom-form

 

You can use below basic module understanding.

Url : https://www.mageplaza.com/magento-2-module-development/

 

If the issue is solved, Click Kudos & Accept as Solution

Re: Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

You can get shopping cart details using block, Check link, Get details of Shopping cart items.

For create a simple  module, Refer link, Create Simple module in Magento 2

 

You need to start with basic module creation, Registration.php file is for register our module.  Create registration.php file,

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Rbj_Customer',
    __DIR__
);

Create module.xml file,app/code/Rbj/Customer/etc/module.xml,

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:Magento:framework:Module/etc/module.xsd">
    <module name="Rbj_Customer" setup_version="1.0.0"/>
</config>

Create Block file, app/code/Rbj/Customer/Block/ShoppingCart.php and template file at app/code/Rbj/Training/view/frontend/templates/index.phtml

Refer blogs for Block and template file data, Get details of Shopping cart items.


 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Magento 2: Get all shopping cart items, subtotal, grand total, billing & shipping address

@slope multiplayer

  • Inject the \Magento\Checkout\Model\Session class into your block or controller.
  • Use methods like getQuote() to retrieve the quote object.
  • Access cart items, totals, and addresses through the quote object.
PHP
<?php
namespace Vendor\Module\Block;

use Magento\Checkout\Model\Session;
use Magento\Framework\View\Element\Template\Context;

class YourBlock extends \Magento\Framework\View\Element\Template
{
    protected $checkoutSession;

    public function __construct(        Context $context,
        Session $checkoutSession,
        array $data = []
    ) {
        parent::__construct($context);
        $this->checkoutSession = $checkoutSession;
    }

    public function getCartItems()
    {
        $quote = $this->checkoutSession->getQuote();
        return $quote->getAllVisibleItems();
    }

    public function getSubtotal()
    {
        $quote = $this->checkoutSession->getQuote();
        return $quote->getSubtotal();
    }

    // ... other methods for grand total, billing address, shipping address
}