# Ajax-Template-Problem

**URL:** <https://forum.shopware.com/t/ajax-template-problem/34616>\
**Category:** Shopware 5\
**Created:** [19. Februar 2016 um 14:10 UTC](https://forum.shopware.com/t/ajax-template-problem/34616 "2016-02-19T14:10:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukas99](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@Lukas99](https://forum.shopware.com/u/Lukas99)\
**Post date:** [19. Februar 2016 um 14:10 UTC](https://forum.shopware.com/t/ajax-template-problem/34616/1 "2016-02-19T14:10:56Z")

</div>

Hallo Zusammen,

wir sind auf ein Problem bei der Überschreibung des Templates mit AJAX-Aufruf gestoßen:

&nbsp;

&nbsp;public function shippingPaymentAction()  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Load payment options, select option and details  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sPayments = $this-\>getPayments();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sFormData = array(‘payment’ =\> $this-\>View()-\>sUserData[‘additional’][‘user’][‘paymentID’]);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $getPaymentDetails = $this-\>admin-\>sGetPaymentMeanById($this-\>View()-\>sFormData[‘payment’]);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $paymentClass = $this-\>admin-\>sInitiatePaymentClass($getPaymentDetails);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($paymentClass instanceof \ShopwarePlugin\PaymentMethods\Components\BasePaymentMethod) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $data = $paymentClass-\>getCurrentPaymentDataAsArray(Shopware()-\>Session()-\>sUserId);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!empty($data)) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sFormData += $data;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($this-\>Request()-\>isPost()) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $values = $this-\>Request()-\>getPost();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $values[‘payment’] = $this-\>Request()-\>getPost(‘payment’);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $values[‘isPost’] = true;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sFormData = $values;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sBasket = $this-\>getBasket();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Load current and all shipping methods  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sDispatch = $this-\>getSelectedDispatch();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sDispatches = $this-\>getDispatches($this-\>View()-\>sFormData[‘payment’]);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sLaststock = $this-\>basket-\>sCheckBasketQuantities();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sShippingcosts = $this-\>View()-\>sBasket[‘sShippingcosts’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sShippingcostsDifference = $this-\>View()-\>sBasket[‘sShippingcostsDifference’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sAmount = $this-\>View()-\>sBasket[‘sAmount’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sAmountWithTax = $this-\>View()-\>sBasket[‘sAmountWithTax’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sAmountTax = $this-\>View()-\>sBasket[‘sAmountTax’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sAmountNet = $this-\>View()-\>sBasket[‘AmountNetNumeric’];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sRegisterFinished = !empty($this-\>session[‘sRegisterFinished’]);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\>View()-\>sTargetAction = ‘shippingPayment’;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($this-\>Request()-\>getParam(‘isXHR’)) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $this-\>View()-\>loadTemplate(‘frontend/checkout/shipping\_payment\_core.tpl’);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
}

&nbsp;

Wir möchten ein Plugin erstellen, das die Methode SHIPPINGPAYEMTNaCTION benutzen wird. Es sollte das über Ajax aufgerufene Template SHIPPIGN\_PAYEMNT\_CORE.TPL überschreiben.

&nbsp;

Aktuell haben wir die folgende Methode angewendet:

public function onCheckoutShippingPayment(Enlight\_Event\_Eventarguments $arguments)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $controller = $arguments-\>getSubject();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $request = $controller-\>Request();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $response = $controller-\>Response();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $view = $controller-\>View();

&nbsp;&nbsp;&nbsp; if ($request-\>getParam(‘isXHR’)) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $view-\>loadTemplate(‘checkout/shipping\_payment\_core\_override.tpl’);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

}

&nbsp;

Diese Lösung funktioniert, aber es wird immer wieder die Standard-Vorlage hervorgerufen…

Wie können wir das Template bei einem AJAX-Aufruf überschreiben?

&nbsp;

Danke im Voraus:)

&nbsp;

Mit freundlichen Grüßen

Jacek Jusiński

---

<div class="post-metadata">

**Author:** ![Heiner\_Lohaus](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@Heiner\_Lohaus](https://forum.shopware.com/u/Heiner_Lohaus)\
**Post date:** [4. März 2016 um 10:48 UTC](https://forum.shopware.com/t/ajax-template-problem/34616/2 "2016-03-04T10:48:03Z")

</div>

Hi Jacek,

du kannst auch einfach die Template-Datei in deinem Theme oder Plugin ersetzen oder erweitern.

Dafür brauchst du dann auch keine Plugin-Anpassung. Das geht mit einfachen&nbsp;Template-Anpassungen:

[https://developers.shopware.com/designers-guide/getting-started/#template-inheritance](https://developers.shopware.com/designers-guide/getting-started/#template-inheritance)

Einige Plugins machen nämlich selbst auch einen “loadTemplate” und überschreiben damit wieder deine Anpassung.

Gruß Heiner

---

<div class="post-metadata">

**Author:** ![katzefudder](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@katzefudder](https://forum.shopware.com/u/katzefudder)\
**Post date:** [4. August 2016 um 12:42 UTC](https://forum.shopware.com/t/ajax-template-problem/34616/3 "2016-08-04T12:42:17Z")

</div>

> [@Heiner Lohaus schrieb:](https://forum.shopware.com/profile/63/Heiner%20Lohaus "Heiner%20Lohaus")
> 
> du kannst auch einfach die Template-Datei in deinem Theme oder Plugin ersetzen oder erweitern.

Genau das macht er ja… für gewöhnliche Aufrufe via GET/POST funktioniert das, allerdings nicht, wenn entsprechende Methode via AJAX aufgerufen wird, dann wird das originäre&nbsp;Template ausgeliefert.  
Ich habe das gleiche Problem.

```
 {extends file="frontend/checkout/shipping\_payment\_core.tpl"} {block name="frontend\_checkout\_payment\_fieldset\_description" append} ... {/block} 

```

Das obige Beispiel funktioniert NICHT beim Aufruf via AJAX.
