mollie / Shopware

Official Mollie extension for Shopware
16 stars 18 forks source link

Class 'smarty' not found during plugin activation #11

Closed vrielsa closed 4 years ago

vrielsa commented 5 years ago

Hello

We've tried updating the installation of the Mollie plugin on our Shopware installation but got stuck after trying to activate the plugin. Clearing caches, autoload dumping, etc.. didn't work. We've also tried to install the plugin on a clean installation of our Shopware version, but we were unable to activate it on that as well, we were presented with the same error.

The only way we were able to activate the plugin is by requiring the smarty class file in MollieShopware.php.

Additional info:

Stack trace

Fatal error: Uncaught Error: Class 'Smarty' not found in /var/www/custom/plugins/MollieShopware/MollieShopware.php on line 270

Error: Class 'Smarty' not found in /var/www/custom/plugins/MollieShopware/MollieShopware.php on line 270

Call Stack:
    0.0002     351528   1. {main}() /var/www/bin/console:0
    0.0416    3965176   2. Shopware\Components\Console\Application->run(class Symfony\Component\Console\Input\ArgvInput, ???) /var/www/bin/console:38
    0.0601    4593880   3. Shopware\Components\Console\Application->doRun(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/vendor/symfony/console/Application.php:117
    0.2854   14475152   4. Shopware\Components\Console\Application->doRun(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/engine/Shopware/Components/Console/Application.php:127
    0.2856   14475152   5. Shopware\Components\Console\Application->doRunCommand(class Shopware\Commands\PluginActivateCommand, class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/vendor/symfony/console/Application.php:193
    0.2856   14475152   6. Shopware\Components\Console\Application->doRunCommand(class Shopware\Commands\PluginActivateCommand, class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/engine/Shopware/Components/Console/Application.php:135
    0.2856   14475152   7. Shopware\Commands\PluginActivateCommand->run(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/vendor/symfony/console/Application.php:843
    0.2859   14478048   8. Shopware\Commands\PluginActivateCommand->execute(class Symfony\Component\Console\Input\ArgvInput, class Symfony\Component\Console\Output\ConsoleOutput) /var/www/vendor/symfony/console/Command/Command.php:242
    0.3564   17038256   9. Shopware\Bundle\PluginInstallerBundle\Service\InstallerService->activatePlugin(class Shopware\Models\Plugin\Plugin) /var/www/engine/Shopware/Commands/PluginActivateCommand.php:88
    0.3571   17051704  10. Shopware\Bundle\PluginInstallerBundle\Service\PluginInstaller->activatePlugin(class Shopware\Models\Plugin\Plugin) /var/www/engine/Shopware/Bundle/PluginInstallerBundle/Service/InstallerService.php:248
    0.3571   17051816  11. MollieShopware\MollieShopware->activate(class Shopware\Components\Plugin\Context\ActivateContext) /var/www/engine/Shopware/Bundle/PluginInstallerBundle/Service/PluginInstaller.php:233
    2.0836   19290392  12. MollieShopware\MollieShopware->getPaymentOptions() /var/www/custom/plugins/MollieShopware/MollieShopware.php:231
vrielsa commented 5 years ago

Perhaps instead of instantiating Smarty yourselves, you could also consider using the template manager included in Shopware.

The getPaymentOptions methods could look a little like this:

protected function getPaymentOptions()
    {
        /** @var \Enlight_Template_Manager $templateManager */
        $templateManager = $this->container->get('template');

        $mollie = $this->getMollieClient();

        // TODO: get methods in the correct locale (de_DE en_US es_ES fr_FR nl_BE fr_BE nl_NL)
        $methods = $mollie->methods->allActive([
            'resource' => 'orders',
            'includeWallets' => 'applepay'
        ]);

        $options = [];
        $position = 0;

        // path to template dir for extra payment-mean options
        $paymentTemplateDir = __DIR__ . '/Resources/views/frontend/plugins/payment';

        foreach ($methods as $key => $method) {
            $name = 'mollie_' . $method->id;

            $templateManager->assign('method', $method);
            $templateManager->assign('router', Shopware()->Router());

            // template path
            $adTemplate = $paymentTemplateDir . '/methods/' . strtolower($method->id) . '.tpl';

            // set default template if no specific template exists
            if (!file_exists($adTemplate)) {
                $adTemplate =  $paymentTemplateDir . '/methods/main.tpl';
            }

            $additionalDescription = $templateManager->fetch('file:' . $adTemplate);

            $option = [
                'name' => $name,
                'description' => $method->description,
                'action' => 'frontend/Mollie',
                'active' => 1,
                'position' => $position,
                'additionalDescription' => $additionalDescription
            ];

            // check template exist
            if (file_exists($paymentTemplateDir . '/' . $name . '.tpl')) {
                $option['template'] = $name . '.tpl';
            }

            $options[] = $option;
        }

        return $options;
    }
iamreinder commented 5 years ago

Hi, this looks like a great solution. I'll look into your pull request later today.