Select Page

How to add additional action buttons in the Admin Orders main buttons bar

Ravindra Gautam
Published: May 26, 2022

In this blog, we are about to learn, how to add additional action buttons in the admin orders main buttons bar for extra actions.

First of all, we need to register a new hook named ‘actionGetAdminOrderButtons’

We use this hook to display additional action buttons into the admin orders main buttons bar.

Now we use the statement followed by the imported class namespace above the class declaration:

use PrestaShopBundle\Controller\Admin\Sell\Order\ActionsBarButton;

Now we define the definition of hook functionality as Follows:

    /**
     * Add buttons to main buttons bar
     */
    public function hookActionGetAdminOrderButtons(array $params)
    {
        $order = new Order($params['id_order']);
        /** @var \Symfony\Bundle\FrameworkBundle\Routing\Router $router */
        $router = $this->get('router');
        /** @var ActionsBarButtonsCollection $bar */
        $bar = $params['actions_bar_buttons_collection'];
        $createAnOrderUrl = $router->generate('admin_orders_create');
        $bar->add(
            new ActionsBarButton(
                'btn-info', ['href' => $createAnOrderUrl], 'Create an order'
            )
        );
        $viewCustomerUrl = $router->generate('admin_customers_view', ['customerId'=> (int)$order->id_customer]);
        $bar->add(
            new ActionsBarButton(
                'btn-secondary', ['href' => $viewCustomerUrl], 'View customer'
            )
        );
        $shopLink =  Context::getContext()->shop->getBaseURL(true);
        $bar->add(
            new ActionsBarButton(
                'btn-link', ['href' => $shopLink], 'Go to Shop'
            )
        );
        $productLink =  Context::getContext()->link->getAdminLink('AdminProducts');
        $bar->add(
            new ActionsBarButton(
                'btn-dark', ['href' => $productLink], 'Go to Catalog'
            )
        );        
    }

You will get results as follows:

Additional action buttons
Additional action buttons

With $router = $this->get('router'); we inject the router capable to generate URL links to controller actions from routes and their parameters. For example:

<?php
$viewCustomerUrl = $router->generate('admin_customers_view', ['customerId'=> (int)$order->id_customer]);

And also we use ActionsBarButtonsCollection to add our new ActionsBarButton buttons. And just with this small function, we get a nice result (View customer and More actions buttons added).

There are two types of display buttons:
1. Display the individual action button like View customer
2. Display one action button and other all buttons will be displayed as a dropdown “… More actions”

Note: The second type of display will be automatically set when there are more than two action buttons otherwise it will be shown as individual action buttons

That’s all about this blog.

If any issue or doubt in the above step, please feel free to let us know in the comment section.

We would be happy to help.

You can also explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at [email protected].

Source: webkul.com