Add CSS hook, URL ref prefill, order prefill, and Widerrufsfrist display

- Fix CSS loading: register stylesheet via actionFrontControllerSetMedia
  hook instead of initContent() — guaranteed to fire before page render
- Upgrade script registers new hook on existing installations
- Feature 1: pre-fill order_reference from ?ref= URL parameter
- Feature 2: pre-fill customer name/email from logged-in account when
  navigating with ?ref= (already worked; now order ref is also pre-filled)
- Feature 4: compute Widerrufsfrist (order date +14 days) from DB and
  display on form (when ref in URL), confirm, and success pages
- Feature 3: EN mail templates were already present

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Arne Weiss
2026-06-01 08:52:53 +02:00
parent c4b104108a
commit 058937bd64
7 changed files with 128 additions and 7 deletions
+23 -7
View File
@@ -26,12 +26,6 @@ class Simple_withdrawalbuttonWithdrawModuleFrontController extends ModuleFrontCo
{
parent::initContent();
$this->registerStylesheet(
'cyp-withdrawal',
'modules/' . $this->module->name . '/views/css/withdrawal.css',
['media' => 'all', 'priority' => 200]
);
$this->context->smarty->assign([
'errors_list' => $this->errorsList,
'form_data' => $this->formData,
@@ -40,6 +34,7 @@ class Simple_withdrawalbuttonWithdrawModuleFrontController extends ModuleFrontCo
'success_data' => $this->successData,
'privacy_url' => (string) Configuration::get(Simple_withdrawalbutton::CONF_PRIVACY_URL),
'revocation_url' => (string) Configuration::get(Simple_withdrawalbutton::CONF_REVOCATION_URL),
'withdrawal_deadline' => $this->computeDeadline(),
]);
if ($this->currentView === 'confirm') {
@@ -185,16 +180,37 @@ class Simple_withdrawalbuttonWithdrawModuleFrontController extends ModuleFrontCo
$customerEmail = (string) $this->context->customer->email;
}
$orderRef = $this->module->cleanText(Tools::getValue('ref'), 64);
return [
'customer_name' => $customerName,
'customer_email' => $customerEmail,
'order_reference' => '',
'order_reference' => $orderRef,
'withdrawal_scope' => 'full',
'withdrawal_items_text' => '',
'message' => '',
];
}
private function computeDeadline()
{
$ref = isset($this->formData['order_reference']) ? $this->formData['order_reference'] : '';
if ($ref === '') {
$ref = $this->module->cleanText(Tools::getValue('ref'), 64);
}
if ($ref === '') {
return '';
}
$orderInfo = $this->module->lookupOrderInfoByReference($ref);
if (!$orderInfo) {
return '';
}
$isoCode = Language::getIsoById((int) $this->context->language->id) ?: 'de';
return (string) $this->module->computeWithdrawalDeadline($orderInfo['date_add'], $isoCode);
}
private function validateData(array $data)
{
$errors = [];