0

in the home page show, the number of orders that are placed and when the user placed the order that number should increase in home page for eg the current order placed are 500 and when user place the order it should 501 shown in home page in magento2

  • You want to display the order count of the logged in user or overall order count you want to display in home page? – Jeeva Chezhiyan Apr 4 '19 at 10:01
  • overall order count – Ashish Ramchandani Apr 4 '19 at 10:08
0

Try this,

Create a helper and add the below code to it,

Helper path be like

app/code/Vendor/Module/Helper/Data.php

<?php
namespace Vendor\Module\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
public function __construct(
    \Magento\Sales\Model\OrderFactory $orderFactory
) {
    $this->orderFactory = $orderFactory;
}
public function getCollection()
{
    $total = $this->orderFactory->create()->getCollection();
    return $total->getSize();
}

}

then in your phtml you can call like below

echo $this->helper('Vendor\Module\Helper\Data')->getCollection();

you can call any of the phtml in the home page to get this information.

To call a phtml only on home page follow the below steps

create a cms_index_index.xml in the below path

app/code/Vendor/Module/view/frontend/layout/cms_index_index.xml

then add the below code to it

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
   <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template"  name="sales_total" template="Vendor_Module::total.phtml">
        </block>
    </referenceContainer>
</body>
</page>

Vendor_Module - this should you namespace_modulename

And also place total.phtml in the below path

app/code/Vendor/Module/view/frontend/templates/total.phtml

Hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.