Magento 2 – Show Cart Items on Different Page Using PHTML PHP Code

cartcheckoutmagento2PHPphtml

I want to get items that added to checkout cart and show that/those in other page.

I have tried many different ways, but in Magento 2 im not been able to do it.

Can you help me out?

Thank you

Best Answer

Here is the simpliest example

Folder structure:

enter image description here

1 magento_root/app/code/Furman/NewChekout/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="Furman_NewChekout" setup_version="0.1.0">
    <sequence>
        <module name="Magento_Catalog"/>
        <module name="Magento_Checkout"/>

    </sequence>
</module>

2 magento_root/app/code/Furman/NewChekout/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Furman_NewChekout',
    __DIR__
);

3 magento_root/app/code/Furman/NewChekout/composer.json

{
"name": "furman/newchekout",
"description": "",
"require": {
    "php": "~5.5.0|~5.6.0|~7.0.0",

    "magento/magento-composer-installer": "*"
},
"suggest": {

},
"type": "magento2-module",
"version": "0.1.0",
"license": [

],
"autoload": {
    "files": [
        "registration.php"
    ],
    "psr-4": {
        "Furman\\NewChekout\\": ""
    }
},
"extra": {
    "map": [
        [
            "*",
            "Furman/NewChekout"
        ]
    ]
}
}

4 magento_root/app/code/Furman/NewChekout/etc/frontend/routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
    <route id="newcheckout" frontName="newcheckout">
        <module name="Furman_NewChekout"/>
    </route>
</router>
</config>

5 magento_root/app/code/Furman/NewChekout/Controller/Cart/Index.php

<?php

namespace Furman\NewChekout\Controller\Cart;

class Index extends \Magento\Checkout\Controller\Cart\Index
{

}

6 magento_root/app/code/Furman/NewChekout/view/frontend/layout/newcheckout_cart_index.xml

(all xml please copy from magento core file to your file: ./magento_root/vendor/magento/module-checkout/view/frontend/layout/checkout_cart_index.xml or from here )

And here is the result: enter image description here

You can also delete all blocks that you don't want to show, or set your own phtml in xml