Modify "Add to shopping cart" button in plugin

That is not much complicated. You just need to subsribe the PostDispatch Detail Event. See below my code (assuming your namespaced 5.2 is called MyCompany):

file custom/plugins/CompanyPlugin/CompanyPlugin.php:

 'onPostDispatchDetail'
        ];
    }

    public function install(InstallContext $context)
    {
        // prepare plugin, e. g. create own db tables
    }

    public function uninstall(UninstallContext $context)
    {
        // clean up, e. g. drop plugin db tables
    }

    public function onPostDispatchDetail(\Enlight_Event_EventArgs $arguments)
    {
        /**
         * @var $controller \Shopware_Controllers_Frontend_Index
         */
        $controller = $arguments->getSubject();
        /**
         * @var $request \Zend_Controller_Request_Http
         */
        $request = $controller->Request();
        /**
         * @var $response \Zend_Controller_Response_Http
         */
        $response = $controller->Response();

        /**
         * @var $view \Enlight_View_Default
         */
        $view = $controller->View();

        // do your database article check here, in sArticles you will find the most article data you may need that are already fetched from the database by shopware itself (you are in after action event)
        $sArticle = $view->getAssign('sArticle');

        // add your own plugin template here, that it overrides the themes' template:
        $view->Engine()->addTemplateDir(
            $this->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'Themes' . DIRECTORY_SEPARATOR
        );

        $sArticle['someCustomVar'] = 'hello article detail page!';
        $view->assign('someCustomVar', $sArticle);
    }
}

Then you need to create the file index.tpl under custom/plugins/CompanyPlugin/Resources/Themes/frontend/detail/index.tpl

Because Shopware will look up for templates in the path custom/plugins/CompanyPlugin/Resources/Themes, as we defined earlier in our main Plugin class, we need to place it there relative to the Bare’s Theme folder structure. Otherwise Shopware will not find your template and will use the Theme’s template.

 

You may want to inherit from the Bare’s template, because you want just to override one block, not the whole file. So, just override this block: shopware/index.tpl at 5.2 · shopware/shopware · GitHub

 

 

Best Regards,

 

derwunner