Jump to content

Hook do strony z zamówieniami


_eSCe_

Recommended Posts

Cześć wszystkim,

piszę moduł, w którym chcę zrobić automatyzację zmian hurtowych na liście zamówień.

Aktualnie zrobiłem to tak, przykład hurtowej zmiany cen:

\views\PrestaShop\Admin\Sell\Order\Order\index.html.twig - nadpisałem sobie index i dodałem sobie modala ze zmianą ceny:

{% include '@PrestaShop/Admin/Sell/Order/Order/Blocks/change_orders_price_modal.html.twig' %}

 

W module dodałem sobie akcję bulk:

        $definition->getBulkActions()->add(

                (new ButtonBulkAction('subscribe_newsletter'))

                    ->setName('Subscribe newsletter')

                    ->setOptions([

                        'class' => 'dropdown-item js-bulk-modal-form-submit-btn',

                        'attributes'  => [

                              'data-modal-id' => "changeOrdersPricesModal",

                        ],

                    ])

            );

 

Modal się wyświetla, przekierowuje akcję na kontroler Symfony, który ma ogarnąć hurtową zamianę. Mam natomiast problem z przekazaniem danych do głównego widoku z listą zamówień tak żeby zrenderować modala:

'changeOrderPricesForm' => $changeOrderPricesForm->createView(),

 

Chodzi konkretnie o kontroller OrderController.

    public function indexAction(Request $request, OrderFilters $filters)
    {
        $orderKpiFactory = $this->get('prestashop.core.kpi_row.factory.orders');
        $orderGrid = $this->get('prestashop.core.grid.factory.order')->getGrid($filters);

        $changeOrderStatusesForm = $this->createForm(ChangeOrdersStatusType::class);
        $changeOrderPricesForm = $this->createForm(ChangeOrdersPriceType::class);

        return $this->render(
            '@PrestaShop/Admin/Sell/Order/Order/index.html.twig',
            [
                'orderGrid' => $this->presentGrid($orderGrid),
                'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
                'enableSidebar' => true,
                'changeOrderStatusesForm' => $changeOrderStatusesForm->createView(),
                'changeOrderPricesForm' => $changeOrderPricesForm->createView(),
                'orderKpi' => $orderKpiFactory->build(),
                'layoutHeaderToolbarBtn' => $this->getOrderToolbarButtons(),
            ]
        );
    }

 

Czy jest jakiś hook, gdzie mogę wstrzyknąć ten formularz do głównego szablonu zamówień lub jakiś sposób jak to zrobić?

Nie chciałbym nadpisywać oryginalnego kontrolera zamówień.

Dzięki za pomoc ;)

Edited by _eSCe_ (see edit history)
Link to comment
Share on other sites

Nikt nie pomoże?

 

Użyłem na razie dekoratora kontrolera:

# modules/lo_adminproductscolumns/config/services.yml
services:
  _defaults:
    public: true

  custom_controller:
    class: 'lo_adminproductscolumns\Controller\OrderAdminController'
    decorates: 'PrestaShopBundle\Controller\Admin\Sell\Order\OrderController'
    arguments: ['@custom_controller.inner']

No i kontroller:

<?php

namespace lo_adminproductscolumns\Controller;

use Symfony\Component\HttpFoundation\Request;
use PrestaShop\PrestaShop\Core\Search\Filters\OrderFilters;
use PrestaShopBundle\Controller\Admin\Sell\Order\OrderController;
use PrestaShopBundle\Form\Admin\Sell\Order\ChangeOrdersStatusType;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use lo_adminproductscolumns\Form\Admin\Sell\Order\ChangeOrdersPriceType;


class OrderAdminController extends FrameworkBundleAdminController
{
    /**
     * @var OrderController
     */
    private $decoratedController;

    public function __construct(OrderController $decoratedController)
    {
        $this->decoratedController = $decoratedController;
    }


    public function indexAction(Request $request, OrderFilters $filters)
    {
        $orderKpiFactory = $this->get('prestashop.core.kpi_row.factory.orders');
        $orderGrid = $this->get('prestashop.core.grid.factory.order')->getGrid($filters);

        $changeOrderStatusesForm = $this->createForm(ChangeOrdersStatusType::class);
        $changeOrderPricesForm = $this->createForm(ChangeOrdersPriceType::class);

        return $this->render(
            '@PrestaShop/Admin/Sell/Order/Order/index.html.twig',
            [
                'orderGrid' => $this->presentGrid($orderGrid),
                'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
                'enableSidebar' => true,
                'changeOrderStatusesForm' => $changeOrderStatusesForm->createView(),
                'changeOrderPricesForm' => $changeOrderPricesForm->createView(),
                'orderKpi' => $orderKpiFactory->build(),
                'layoutHeaderToolbarBtn' => $this->getOrderToolbarButtons(),
            ]
        );
    }

        /**
     * @return array
     */
    private function getOrderToolbarButtons(): array
    {
        $toolbarButtons = [];

        $isSingleShopContext = $this->get('prestashop.adapter.shop.context')->isSingleShopContext();

        $toolbarButtons['add'] = [
            'href' => $this->generateUrl('admin_orders_create'),
            'desc' => $this->trans('Add new order', 'Admin.Orderscustomers.Feature'),
            'icon' => 'add_circle_outline',
            'disabled' => !$isSingleShopContext,
        ];

        if (!$isSingleShopContext) {
            $toolbarButtons['add']['help'] = $this->trans(
                'You can use this feature in a single shop context only. Switch context to enable it.',
                'Admin.Orderscustomers.Feature'
            );
            $toolbarButtons['add']['href'] = '#';
        }

        return $toolbarButtons;
    }
}

W ten sposób wszystko działa, ale nie podoba mi się rozwiązanie z dekoracją całej metody indexAction().

Może macie jakieś inne pomysły?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...