Add new Action in Controllers

Hi guys,

Little suggestion needed. I want to extend Listing class and add new action, not modify any existing ones. How to do that? e.g. I want to add showProductListAction to listing.php.

BR

Ahad

By decoration the listing service and adding the desired functionality. Example can be found in the developer documentation from Shopware.

If you need a function to really just call occassionally  you put it in your own controller.

@steinsoftware‍

Example will be helpful.

@abdul.ahad2k14‍

$this->subscribeEvent(
    'Enlight_Controller_Action_Frontend_Listing_showProductList',
    'onControllerActionFrontendListingShowProductList'
);

public function onControllerActionFrontendListingShowProductList(Enlight_Event_EventArgs $args)
{
    /** @var $controller Enlight_Controller_Action */
    $controller = $args->getSubject();
    $view = $controller->View();
    $request = $controller->Request();
    
    // Do Actions

    return true;
}

The listener must return true to avoid to redirection to the 404 page.

1 „Gefällt mir“

@Shyim‍

Just Curious, how did you figure this out? I mean is it mentioned anywhere in Shopware documentation? Because I tried every document page but nowhere I found such solution.

You are right it is not mentioned in the docs.

Searching in SourceCode is most the best solution =)