1

I'm a beginner in Magento and I try to create a page on which I get all orders of a customer payed with a custom payment method.

Now, the page work but I want the page to looks like a real customer admin page, and to display the navigation on the left.

My custom layout (devis_index_index.xml)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <block class="Opsone\KgAdmin\Block\Index" name="devis_index_index" template="Opsone_KgAdmin::index.phtml" />
    </referenceContainer>
</page>

and my template (index.phtml)

<?php $items = $this->getOrderCollection(); ?>

<div class="o-main-box">
    <?php if ($items != 'disconnect' && count($items)): ?>
        <div class="table-wrapper orders-history">
            <table class="data table table-order-items history" id="my-orders-table">
                <caption class="table-caption"><?= /* @escapeNotVerified */ __('Orders') ?></caption>
                <thead>
                    <tr>
                        <th scope="col" class="col id"><?= /* @escapeNotVerified */ __('Devis #') ?></th>
                        <th scope="col" class="col date"><?= /* @escapeNotVerified */ __('Date') ?></th>
                        <?= /* @noEscape */ $block->getChildHtml('extra.column.header') ?>
                        <th scope="col" class="col shipping"><?= /* @escapeNotVerified */ __('Ship To') ?></th>
                        <th scope="col" class="col total"><?= /* @escapeNotVerified */ __('Total du devis') ?></th>
                        <th scope="col" class="col status"><?= /* @escapeNotVerified */ __('Status') ?></th>
                        <th scope="col" class="col actions"><?= /* @escapeNotVerified */ __('Action') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach ($items as $_order) : ?>
                        <tr>
                            <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= /* @escapeNotVerified */ $_order->getRealOrderId() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @escapeNotVerified */ $block->formatDate($_order->getCreatedAt()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Ship To')) ?>" class="col shipping"><?= $_order->getShippingAddress() ? $block->escapeHtml($_order->getShippingAddress()->getName()) : '&nbsp;' ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @escapeNotVerified */ $_order->formatPrice($_order->getGrandTotal()) ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status"><?= /* @escapeNotVerified */ $_order->getStatusLabel() ?></td>
                            <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                                <a href="<?= $block->getUrl('sales/order/view', ['order_id' => $_order->getRealOrderId()]); ?>" class="action view">
                                    <span><?= /* @escapeNotVerified */ __('Voir le devis') ?></span>
                                </a>
                            </td>
                        </tr>
                    <?php
                    endforeach;
                    ?>
                </tbody>
            </table>
        </div>
        <?php elseif ($items != 'disconnect' && !count($items)) : ?>
        <div class="message info empty"><span><?= /* @escapeNotVerified */ __('Vous n\'avez aucun devis en cours') ?></span></div>
        <?php else: ?>
        <div class="message info empty"><span><?= /* @escapeNotVerified */ __('Merci de vous connecter pour accéder à vos devis') ?></span></div>
    <?php endif ?>
</div>

The navigation I try to display

Thank you :)

1 Answer 1

0

In your devis_index_index.xml change content to following:

<?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">
    <update handle="customer_account"/>
    <referenceContainer name="content">
        <block class="Opsone\KgAdmin\Block\Index" name="devis_index_index" template="Opsone_KgAdmin::index.phtml" />
    </referenceContainer>
</page>

so remove layout="1column" and add <update handle="customer_account"/>.

Also as good practice, consider removing your custom block Opsone\KgAdmin\Block\Index, and instead move functionalities included inside to View Model like in Magento 2: How to Add a viewModel to a core block? - you can do same with your own when adding block. Then you will have to add view_model as argument to your block and remove class="Opsone\KgAdmin\Block\Index" also.

Best regards and good luck :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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