Shopware 5 Plugin Deep Dive: Resolving Critical Bugs in the Garantielabel (GARAN) Extension

Community Insight: Resolving Critical Bugs in Shopware 5 Garantielabel (GARAN) Plugin

This Shopware forum thread serves as a crucial support channel for the 'Garantielabel (GARAN)' plugin, specifically highlighting and resolving significant technical issues encountered by users. The discussion centers around detailed bug reports and proposed solutions, primarily from user 'sacrofano', which were then addressed by the plugin developer, 'marcus.kreusch'. The thread demonstrates a collaborative effort to enhance the stability and functionality of a third-party Shopware 5 extension.

Key Issues and Solutions

The core of the discussion revolves around two major bugs that impacted the user experience and stability of Shopware 5 stores utilizing the GARAN plugin:

1. 'Add to Cart' Infinite Spinner / 500 Error

Problem Description: Users experienced an endless loading spinner when clicking 'Add to Cart', preventing the cross-selling modal window from opening, despite the item being successfully added to the cart. This indicated a critical failure in the AJAX process.

Root Cause Analysis: 'sacrofano' identified that the OncoCommercialGaran.php plugin file prematurely aborted its execution in the onCheckoutPostDispatch method if the action was not 'confirm'. Consequently, during an AJAX call (specifically ajaxAddArticleCart), the necessary template folder for the plugin was not registered. This led to a Smarty crash when attempting to load nested_label.tpl within the box-basic.tpl of the cross-selling product box.

Proposed Solution: The fix involved ensuring that the template directory registration occurs at the very beginning of the onCheckoutPostDispatch function, before any conditional returns. This guarantees the template folder is always registered, regardless of the checkout step or AJAX context.

/** @return void */
    public function onCheckoutPostDispatch(Enlight_Controller_ActionEventArgs $args)
    {
        $c>getSubject();
        $view = $controller->View();

        // FIX: Wir melden den Template-Ordner IMMER an, egal in welchem Schritt
        // des Checkouts wir uns befinden. Das verhindert den Absturz im AJAX-Fenster.
        $view->addTemplateDir($this->getPath() . '/Resources/views');

        // Danach geht die normale Logik weiter:
        if ($controller->Request()->getActionName() !== 'confirm') {
            return;
        }

        $basket = $view->getAssign('sBasket');
        $items = is_array($basket) && isset($basket['content']) ? $basket['content'] : null;

        $view->assign('oncoCommercialGaran', [
            'map' => $this->buildLabelMap($this->collectOrderNumbers($items)),
            'portalUrl' => self::PORTAL_URL,
        ]);
    } 

2. Smarty Security Error in Product Listing (box-basic.tpl)

Problem Description: The shop would intermittently throw a 503 error or a 'directory not allowed by security setting' message, particularly within product listings.

Root Cause Analysis: The issue stemmed from an illegal Smarty nesting within the box-basic.tpl template (e.g., {if {config name="displayListingBuyButton"} ...}), which caused the Smarty compiler to crash. Additionally, there was a lack of isset() checks for variables, especially when the plugin's variables were not passed in cross-selling contexts.

Proposed Solution: The solution involved correcting the Smarty syntax by utilizing the native Shopware $theme variable and implementing robust isset() checks to ensure variables exist before being accessed, thereby preventing compiler errors and undefined variable issues.

{block name="onco_commercial_garan_listing_label"}
    {if $theme.displayListingBuyButton && isset($oncoCommercialGaran) && isset($oncoCommercialGaran.map[$sArticle.ordernumber])}
        {* ... *}
    {/if}
{/block}

3. Modal Window Positioning Issue

A minor UI bug was also reported by 'sacrofano', where the Garantielabel modal window was initially mispositioned (vertically cut off) on the first click, only correcting itself on subsequent clicks. This was attributed to the SVG not being in the browser's cache during the initial position calculation. A JavaScript-based solution was mentioned, but the full code was not provided in the snippet.

Outcome and Impact

The plugin developer, 'marcus.kreusch', acknowledged 'sacrofano's valuable feedback and confirmed that the issues were addressed in version 1.0.2 of the plugin. He noted that his implemented solution was designed to be more universally compatible across different themes, third-party plugins, and Shopware versions. A GitHub commit link was provided, detailing the changes made to improve template registration and fix modal positioning.

This thread is a testament to effective community support and highlights common pitfalls in Shopware 5 plugin development, offering concrete solutions that can benefit other developers facing similar challenges with template handling, Smarty security, and AJAX interactions.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools