Skip to content

Commit

Permalink
RATEPLUG-202: installment: unset user data on switch between installm…
Browse files Browse the repository at this point in the history
…ent methods
  • Loading branch information
rommelfreddy committed Aug 11, 2021
1 parent ca8cd23 commit 8828c41
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
data-allowDirectDebit="{$ratepay.calculator.rp_debitPayType.rp_paymentType_directDebit}"
>
<input type="hidden" name="rp-calculation-amount" value="{$sAmount}" />
<input type="hidden" name="ratepay[installment][paymentMethodId]" id="rp-calculation-type" value="{$form_data.payment}" />
<input type="hidden" name="ratepay[installment][type]" id="rp-calculation-type" value="{$form_data.ratepay.installment.type}" />
<input type="hidden" name="ratepay[installment][value]" id="rp-calculation-value" value="{$form_data.ratepay.installment.value}" />
<input type="hidden" name="ratepay[installment][paymentType]" id="rp-payment-type" value="{$form_data.ratepay.installment.paymentType}" />
Expand Down
41 changes: 25 additions & 16 deletions Subscriber/Frontend/PaymentShippingSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public function onShippingPaymentAction(Enlight_Hook_HookArgs $args)
return;
}

$billingAddress = $this->sessionHelper->getBillingAddress();
$shippingAddress = $this->sessionHelper->getShippingAddress();
$currency = $this->config->get('currency');

$sUserData = $view->getAssign('sUserData');
if (isset($sUserData['additional']['payment']['name'])) {
Expand All @@ -110,6 +107,11 @@ public function onShippingPaymentAction(Enlight_Hook_HookArgs $args)
}

if (PaymentMethods::exists($paymentMethodName)) {

$billingAddress = $this->sessionHelper->getBillingAddress();
$shippingAddress = $this->sessionHelper->getShippingAddress();
$currency = $this->config->get('currency');

$paymentMethodConfig = $this->profileConfigService->getPaymentConfiguration((new PaymentConfigSearch())
->setPaymentMethod($paymentMethodName)
->setBackend(false)
Expand All @@ -128,21 +130,28 @@ public function onShippingPaymentAction(Enlight_Hook_HookArgs $args)
'agb' => 'https://www.ratepay.com/legal'
];

$view->assign('ratepay', array_merge($view->getAssign('ratepay') ? : [], $data));
}
$view->assign('ratepay', array_merge($view->getAssign('ratepay') ?: [], $data));

// fix static form data
$viewParams = $view->getAssign();
if (isset($viewParams['sFormData']['ratepay'])) {
$bankData = $this->sessionHelper->getBankData($billingAddress);
$accountHolders = BankDataUtil::getAvailableAccountHolder($billingAddress, $bankData);
$viewParams['sFormData']['ratepay']['bank_account']['accountHolder'] = [
'list' => $accountHolders,
'selected' => $bankData && $bankData->getAccountHolder() ? $bankData->getAccountHolder() : $accountHolders[0]
];
// fix static form data
$sFormData = $view->getAssign('sFormData');
if (isset($sFormData['ratepay'])) {
$ratepayData = &$sFormData['ratepay'];

$bankData = $this->sessionHelper->getBankData($billingAddress);
$accountHolders = BankDataUtil::getAvailableAccountHolder($billingAddress, $bankData);
$ratepayData['bank_account']['accountHolder'] = [
'list' => $accountHolders,
'selected' => $bankData && $bankData->getAccountHolder() ? $bankData->getAccountHolder() : $accountHolders[0]
];

if (isset($ratepayData['installment']['paymentMethodId']) && (int)$ratepayData['installment']['paymentMethodId'] !== $paymentMethodConfig->getPaymentMethod()->getId()) {
// installment fields has to be reset if the payment method has been changed
unset($ratepayData['installment']);
}

$view->assign('sFormData', $sFormData);
}
}
$view->assign($viewParams);
}


}
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<li>fixes issues during a b2b order with Shopware 5.7</li>
<li>removes empty vat-id in PaymentRequest</li>
<li>fixes issue with third-party plugin (Product Sets powered by Pickware) (feature flag)</li>
<li>Fix switch between payment methods of instalment</li>
</ul>
]]>
</changes>
Expand All @@ -38,6 +39,7 @@
<li>Fehlerbehebung bei einer B2B Bestellung in Shopware 5.7</li>
<li>Leere Steuer-ID im PaymentRequest entfernt</li>
<li>Behebt einen Fehler mit einem Drittanbieterplugin (Stücklisten / Sets powered by Pickware) (feature flag)</li>
<li>Behebt einen Fehler beim Wechsel zwischen den Zahlungsmethoden der Ratenzahlungen</li>
</ul>
]]>
</changes>
Expand Down

0 comments on commit 8828c41

Please sign in to comment.