DSGVO Magento

Wie ändert man den Namen im Kontaktformular in Magento 1 von einem Pflichtfeld in ein optionales Feld? Hintergrund: Im Rahmen der in 2018 wirksam gewordenen Datenschutzgrundverordnung (DSGVO) möchte man dem User die Möglichkeit geben, eine Nachricht an den Shopbetreiber zu übermitteln, ohne den Namen angeben zu müssen.

 

 So ändern wir zuerst das Namensfeld vom Pflichtfeld zum optionalen Feld in (Paket "econcess" und Template "default" auf eigene Bedürfnisse anzupassen)

 

\app\design\frontend\econcess\default\template\contacts\form.phtml

 

so dass im Ergebnis folgender Code übrig bleibt:

 

                    <label for="name"><?php echo Mage::helper('contacts')->__('Name') ?></label>

                    <div class="input-box">

                        <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->escapeHtml($this->helper('contacts')->getUserName()) ?>" class="input-text" type="text" />

                    </div>

 

Das allein wäre natürlich zu einfach. Zusätzlich müssen wir noch eine kleine Extension schreiben, die den IndexController überschreibt, um ein leeres Namenfeld zu erlauben. In unserem Falle ist dies die Extension Econcess_Contacts. Diese machen wir bekannt in

 

\app\etc\modules\Econcess_Contacts.xml

 

mit dem Inhalt

 

<?xml version="1.0"?>

<config>

    <modules>

        <Econcess_Contacts>

            <active>true</active>

            <codePool>local</codePool>

        </Econcess_Contacts>

    </modules>

</config>

 

Dann erstellen wir die Datei 

 

\app\code\local\Econcess\Contacts\etc\config.xml

 

mit dem Inhalt

 

<config>

    <modules>

        <Econcess_Contacts>

            <version>1.0.0</version>

        </Econcess_Contacts>

    </modules>

            <frontend>

                        <routers>

                                    <contacts>

                                               <args>

                                                           <modules>

                                                                       <econcess_contacts before="Mage_Contacts">Econcess_Contacts</econcess_contacts>

                                                           </modules>

                                               </args>

                                    </contacts>

                        </routers>

            </frontend>

</config>

 

und dann noch die Datei

 

\app\code\local\Econcess\Contacts\controllers\IndexController.php

 

mit dem Inhalt 

 

<?php

require_once(Mage::getModuleDir('controllers','Mage_Contacts').DS.'IndexController.php');

class Econcess_Contacts_IndexController extends Mage_Contacts_IndexController

{

    public function postAction()

    {

        $post = $this->getRequest()->getPost();

        if ( $post ) {

            $translate = Mage::getSingleton('core/translate');

            /* @var $translate Mage_Core_Model_Translate */

            $translate->setTranslateInline(false);

            try {

                $postObject = new Varien_Object();

                $postObject->setData($post);

                $error = false;

                if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {

                    //$error = true;

                }

                if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {

                    $error = true;

                }

                if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {

                    $error = true;

                }

                if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {

                    $error = true;

                }

                if ($error) {

                    throw new Exception();

                }

                $mailTemplate = Mage::getModel('core/email_template');

                /* @var $mailTemplate Mage_Core_Model_Email_Template */

                $mailTemplate->setDesignConfig(array('area' => 'frontend'))

                    ->setReplyTo($post['email'])

                    ->sendTransactional(

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),

                        Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),

                        null,

                        array('data' => $postObject)

                    );

                if (!$mailTemplate->getSentSuccess()) {

                    throw new Exception();

                }

                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));

                $this->_redirect('*/*/');

                return;

            } catch (Exception $e) {

                $translate->setTranslateInline(true);

                Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));

                $this->_redirect('*/*/');

                return;

            }

        } else {

            $this->_redirect('*/*/');

        }

    }

}

 

Hier wird also nur die boolesche $error-Variable auf "false" belassen, wenn Name leer, da dort auskommentiert.

 

Damit sind wir fertig. Getestet in Magento 1.9.1.0.