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:
@@ -50,6 +50,7 @@ class Simple_withdrawalbutton extends Module
|
||||
&& $this->installTab()
|
||||
&& $this->registerHook('displayFooter')
|
||||
&& $this->registerHook('displayCustomerAccount')
|
||||
&& $this->registerHook('actionFrontControllerSetMedia')
|
||||
&& Configuration::updateValue(self::CONF_SHOP_EMAIL, (string) Configuration::get('PS_SHOP_EMAIL'))
|
||||
&& Configuration::updateValue(self::CONF_RATE_LIMIT, '5')
|
||||
&& Configuration::updateValue(self::CONF_PRIVACY_URL, '')
|
||||
@@ -295,6 +296,20 @@ class Simple_withdrawalbutton extends Module
|
||||
return $this->display(__FILE__, 'views/templates/hook/customer_account.tpl');
|
||||
}
|
||||
|
||||
public function hookActionFrontControllerSetMedia()
|
||||
{
|
||||
if (
|
||||
Tools::getValue('module') === $this->name
|
||||
&& Tools::getValue('controller') === 'withdraw'
|
||||
) {
|
||||
$this->context->controller->registerStylesheet(
|
||||
'cyp-withdrawal',
|
||||
'modules/' . $this->name . '/views/css/withdrawal.css',
|
||||
['media' => 'all', 'priority' => 200]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getWithdrawalLink()
|
||||
{
|
||||
return $this->context->link->getModuleLink($this->name, 'withdraw', [], true);
|
||||
@@ -342,6 +357,43 @@ class Simple_withdrawalbutton extends Module
|
||||
return $idOrder > 0 ? $idOrder : null;
|
||||
}
|
||||
|
||||
public function lookupOrderInfoByReference($orderReference)
|
||||
{
|
||||
$orderReference = $this->cleanText($orderReference, 64);
|
||||
if ($orderReference === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sql = 'SELECT `id_order`, `date_add`, `id_customer`
|
||||
FROM `' . _DB_PREFIX_ . 'orders`
|
||||
WHERE `reference` = "' . pSQL($orderReference) . '"
|
||||
AND `id_shop` = ' . (int) $this->context->shop->id . '
|
||||
ORDER BY `id_order` DESC';
|
||||
|
||||
$row = Db::getInstance()->getRow($sql);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id_order' => (int) $row['id_order'],
|
||||
'date_add' => $row['date_add'],
|
||||
'id_customer' => (int) $row['id_customer'],
|
||||
];
|
||||
}
|
||||
|
||||
public function computeWithdrawalDeadline($orderDateAdd, $isoCode = 'de')
|
||||
{
|
||||
$timestamp = strtotime((string) $orderDateAdd);
|
||||
if (!$timestamp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$deadline = strtotime('+14 days', $timestamp);
|
||||
|
||||
return ($isoCode === 'de') ? date('d.m.Y', $deadline) : date('d/m/Y', $deadline);
|
||||
}
|
||||
|
||||
public function hashForPrivacy($value)
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
|
||||
Reference in New Issue
Block a user