Skip to content

Commit

Permalink
create standalone contact page (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
malyMiso authored Dec 2, 2019
2 parents 6ac5a8a + 486792a commit ab41237
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 84 deletions.
4 changes: 4 additions & 0 deletions config/shopsys-routing/routing_front_cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ front_cart:
path: /kosik/
defaults: { _controller: App\Controller\Front\CartController:indexAction }

front_contact:
path: /kontakt/
defaults: { _controller: App\Controller\Front\ContactFormController:indexAction }

front_customer_edit:
path: /zakaznik/upravit-udaje/
defaults: { _controller: App\Controller\Front\CustomerController:editAction }
Expand Down
4 changes: 4 additions & 0 deletions config/shopsys-routing/routing_front_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ front_cart:
path: /cart/
defaults: { _controller: App\Controller\Front\CartController:indexAction }

front_contact:
path: /contact/
defaults: { _controller: App\Controller\Front\ContactFormController:indexAction }

front_customer_edit:
path: /customer/edit/
defaults: { _controller: App\Controller\Front\CustomerController:editAction }
Expand Down
53 changes: 20 additions & 33 deletions src/Controller/Front/ContactFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\ContactForm\ContactFormData;
use Shopsys\FrameworkBundle\Model\ContactForm\ContactFormFacade;
use Shopsys\FrameworkBundle\Model\ContactForm\ContactFormSettingsFacade;
use Shopsys\FrameworkBundle\Model\LegalConditions\LegalConditionsFacade;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class ContactFormController extends FrontBaseController
Expand All @@ -29,70 +29,57 @@ class ContactFormController extends FrontBaseController
*/
private $domain;

/**
* @var \Shopsys\FrameworkBundle\Model\ContactForm\ContactFormSettingsFacade
*/
private $contactFormSettingsFacade;

/**
* @param \Shopsys\FrameworkBundle\Model\ContactForm\ContactFormFacade $contactFormFacade
* @param \Shopsys\FrameworkBundle\Model\LegalConditions\LegalConditionsFacade $legalConditionsFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\ContactForm\ContactFormSettingsFacade $contactFormSettingsFacade
*/
public function __construct(
ContactFormFacade $contactFormFacade,
LegalConditionsFacade $legalConditionsFacade,
Domain $domain
Domain $domain,
ContactFormSettingsFacade $contactFormSettingsFacade
) {
$this->contactFormFacade = $contactFormFacade;
$this->legalConditionsFacade = $legalConditionsFacade;
$this->domain = $domain;
$this->contactFormSettingsFacade = $contactFormSettingsFacade;
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*/
public function sendAction(Request $request)
public function indexAction(Request $request)
{
$privacyPolicyArticle = $this->legalConditionsFacade->findPrivacyPolicy($this->domain->getId());
$domainId = $this->domain->getId();
$privacyPolicyArticle = $this->legalConditionsFacade->findPrivacyPolicy($domainId);

$form = $this->createForm(ContactFormType::class, new ContactFormData(), [
'action' => $this->generateUrl('front_contact_form_send'),
]);
$form = $this->createForm(ContactFormType::class, new ContactFormData());
$form->handleRequest($request);

$message = '';
if ($form->isSubmitted() && $form->isValid()) {
$contactFormData = $form->getData();

try {
$this->contactFormFacade->sendMail($contactFormData);
$form = $this->createForm(ContactFormType::class, new ContactFormData(), [
'action' => $this->generateUrl('front_contact_form_send'),
]);
$message = t('Thank you, your message has been sent.');
$this->getFlashMessageSender()->addSuccessFlash(t('Thank you, your message has been sent.'));
} catch (\Shopsys\FrameworkBundle\Model\Mail\Exception\MailException $ex) {
$message = t('Error occurred when sending email.');
$this->getFlashMessageSender()->addErrorFlash(t('Error occurred when sending email.'));
}
}

$contactFormHtml = $this->renderView('Front/Content/ContactForm/contactForm.html.twig', [
'form' => $form->createView(),
'privacyPolicyArticle' => $privacyPolicyArticle,
]);

return new JsonResponse([
'contactFormHtml' => $contactFormHtml,
'message' => $message,
]);
}

public function indexAction()
{
$privacyPolicyArticle = $this->legalConditionsFacade->findPrivacyPolicy($this->domain->getId());

$form = $this->createForm(ContactFormType::class, new ContactFormData(), [
'action' => $this->generateUrl('front_contact_form_send'),
]);
return $this->redirect($this->generateUrl('front_contact'));
}

return $this->render('Front/Content/ContactForm/contactForm.html.twig', [
return $this->render('Front/Content/ContactForm/index.html.twig', [
'form' => $form->createView(),
'privacyPolicyArticle' => $privacyPolicyArticle,
'mainText' => $this->contactFormSettingsFacade->getMainText($domainId),
]);
}
}
4 changes: 0 additions & 4 deletions src/DataFixtures/Demo/ArticleDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ protected function getDataForArticles(string $locale): array
self::ATTRIBUTE_TEXT_KEY => t('Morbi posuere mauris dolor, quis accumsan dolor ullamcorper eget. Phasellus at elementum magna, et pretium neque. Praesent tristique lorem mi, eget varius quam aliquam eget. Vivamus ultrices interdum nisi, sed placerat lectus fermentum non. Phasellus ac quam vitae nisi aliquam vestibulum. Sed rhoncus tortor a arcu sagittis placerat. Nulla lectus nunc, ultrices ac faucibus sed, accumsan nec diam. Nam auctor neque quis tincidunt tempus. Nunc eget risus tristique, lobortis metus vitae, pellentesque leo. Vivamus placerat turpis ac dolor vehicula tincidunt. Sed venenatis, ante id ultrices convallis, lacus elit porttitor dolor, non porta risus ipsum ac justo. Integer id pretium quam, id placerat nulla.', [], 'dataFixtures', $locale),
self::ATTRIBUTE_PLACEMENT_KEY => Article::PLACEMENT_NONE,
self::REFERENCE_NAME_KEY => self::ARTICLE_COOKIES,
], [
self::ATTRIBUTE_NAME_KEY => t('Contact', [], 'dataFixtures', $locale),
self::ATTRIBUTE_TEXT_KEY => t('Donec at dolor mi. Nullam ornare, massa in cursus imperdiet, felis nisl auctor ante, vel aliquet tortor lacus sit amet ipsum. Proin ultrices euismod elementum. Integer sodales hendrerit tortor, vel semper turpis interdum eu. Phasellus quam tortor, feugiat vel condimentum vel, tristique et ipsum. Duis blandit lectus in odio cursus rutrum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam pulvinar massa at imperdiet venenatis. Maecenas convallis lobortis quam in fringilla. Mauris gravida turpis eget sapien imperdiet pulvinar. Nunc velit urna, fringilla nec est sit amet, accumsan varius nunc. Morbi sed tincidunt diam, sit amet laoreet nisl. Nulla tempus id lectus non lacinia.\n\nVestibulum interdum adipiscing iaculis. Nunc posuere pharetra velit. Nunc ac ante non massa scelerisque blandit sit amet vel velit. Integer in massa sed augue pulvinar malesuada. Pellentesque laoreet orci augue, in fermentum nisl feugiat ut. Nunc congue et nisi a interdum. Aenean mauris mi, interdum vel lacus et, placerat gravida augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sagittis ipsum et consequat euismod. Praesent a ipsum dapibus, aliquet justo a, consectetur magna. Phasellus imperdiet tempor laoreet. Sed a accumsan lacus, accumsan faucibus dolor. Praesent euismod justo quis ipsum aliquam suscipit. Sed quis blandit urna.', [], 'dataFixtures', $locale),
self::ATTRIBUTE_PLACEMENT_KEY => Article::PLACEMENT_FOOTER,
],
];
}
Expand Down
27 changes: 27 additions & 0 deletions src/Migrations/Version20191121171000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Shopsys\MigrationBundle\Component\Doctrine\Migrations\AbstractMigration;

class Version20191121171000 extends AbstractMigration
{
/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function up(Schema $schema)
{
$this->sql('DELETE FROM friendly_urls WHERE slug=\'contact\'');
$this->sql('DELETE FROM articles WHERE name=\'Contact\' AND placement=\'footer\'');
}

/**
* @param \Doctrine\DBAL\Schema\Schema $schema
*/
public function down(Schema $schema)
{
}
}
30 changes: 0 additions & 30 deletions src/Resources/scripts/frontend/contactForm.js

This file was deleted.

46 changes: 46 additions & 0 deletions templates/Front/Content/ContactForm/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends 'Front/Layout/layoutWithPanel.html.twig' %}

{% block title %}
{{ 'Contact'|trans }}
{% endblock %}

{% block main_content %}
<div class="h2">{{ 'Contact us'|trans }}</div>

<div class="in-user-text margin-bottom-20">
{{ mainText|raw }}
</div>

{{ form_start(form) }}

{{ form_errors(form) }}

{{ form_row(form.name, { label: 'Full name'|trans }) }}
{{ form_row(form.email, { label: 'Email'|trans }) }}
{{ form_row(form.message, { label: 'Message'|trans }) }}
<dl class="form-line">
<dt></dt>
<dd>
<div class="form-choice">
{{ form_widget(form.privacyPolicy, { attr: { class: "css-checkbox" }} )}}
<label for="{{ form.privacyPolicy.vars.id }}" class="css-checkbox__image">
{% if privacyPolicyArticle is not null %}
{% set articleUrl = url('front_article_detail', {'id': privacyPolicyArticle.id}) %}
{{ 'I agree with <a href="%url%" target="_blank">privacy policy</a>.'|trans({'%url%': articleUrl})|raw }}
{% else %}
{{ 'I agree with privacy policy.'|trans }}
{% endif %}
</label>
<span class="js-validation-errors-list js-validation-error-list-{{ form.privacyPolicy.vars.id }} form-error form-error--choice display-none">
<span class="form-error__icon">
<i class="svg svg-warning"></i>
</span>
<ul class="form-error__list"></ul>
</span>
</div>
</dd>
</dl>
{{ form_widget(form.send, { label: 'Send'|trans }) }}

{{ form_end(form) }}
{% endblock %}
1 change: 1 addition & 0 deletions templates/Front/Layout/footer.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{{ getShopInfoPhoneNumber() }}
{{ getShopInfoEmail() }}
{{ render(controller('App\\Controller\\Front\\ArticleController:footerAction')) }}
<a class="menu__item__link" href="{{ url('front_contact') }}">{{ 'Contact'|trans }}</a>
</div>
</footer>
</div>
Expand Down
4 changes: 0 additions & 4 deletions templates/Front/Layout/layoutWithPanel.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

{% block panel_content %}{% endblock %}

<div id="js-contact-form-container">
{{ render(controller('App\\Controller\\Front\\ContactFormController:indexAction')) }}
</div>

{{ render(controller('App\\Controller\\Front\\AdvertController:boxAction',{'positionName' : 'leftSidebar'})) }}
</div>
</div>
Expand Down
6 changes: 0 additions & 6 deletions translations/dataFixtures.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,6 @@ msgstr "Konektory"
msgid "Construction"
msgstr "Konstrukce"

msgid "Contact"
msgstr "Kontakty"

msgid "Coupon valued to 100 Czech crowns. You can cash it at any exchange office"
msgstr "Poukázka na 100 Kč. Můžete ji využít v libovolné směnárně."

Expand Down Expand Up @@ -694,9 +691,6 @@ msgstr "Typ displeje"
msgid "Done"
msgstr "Vyřízena"

msgid "Donec at dolor mi. Nullam ornare, massa in cursus imperdiet, felis nisl auctor ante, vel aliquet tortor lacus sit amet ipsum. Proin ultrices euismod elementum. Integer sodales hendrerit tortor, vel semper turpis interdum eu. Phasellus quam tortor, feugiat vel condimentum vel, tristique et ipsum. Duis blandit lectus in odio cursus rutrum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam pulvinar massa at imperdiet venenatis. Maecenas convallis lobortis quam in fringilla. Mauris gravida turpis eget sapien imperdiet pulvinar. Nunc velit urna, fringilla nec est sit amet, accumsan varius nunc. Morbi sed tincidunt diam, sit amet laoreet nisl. Nulla tempus id lectus non lacinia.\\n\\nVestibulum interdum adipiscing iaculis. Nunc posuere pharetra velit. Nunc ac ante non massa scelerisque blandit sit amet vel velit. Integer in massa sed augue pulvinar malesuada. Pellentesque laoreet orci augue, in fermentum nisl feugiat ut. Nunc congue et nisi a interdum. Aenean mauris mi, interdum vel lacus et, placerat gravida augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sagittis ipsum et consequat euismod. Praesent a ipsum dapibus, aliquet justo a, consectetur magna. Phasellus imperdiet tempor laoreet. Sed a accumsan lacus, accumsan faucibus dolor. Praesent euismod justo quis ipsum aliquam suscipit. Sed quis blandit urna."
msgstr "Donec at dolor mi. Nullam ornare, massa in cursus imperdiet, felis nisl auctor ante, vel aliquet tortor lacus sit amet ipsum. Proin ultrices euismod elementum. Integer sodales hendrerit tortor, vel semper turpis interdum eu. Phasellus quam tortor, feugiat vel condimentum vel, tristique et ipsum. Duis blandit lectus in odio cursus rutrum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam pulvinar massa at imperdiet venenatis. Maecenas convallis lobortis quam in fringilla. Mauris gravida turpis eget sapien imperdiet pulvinar. Nunc velit urna, fringilla nec est sit amet, accumsan varius nunc. Morbi sed tincidunt diam, sit amet laoreet nisl. Nulla tempus id lectus non lacinia.\\n\\nVestibulum interdum adipiscing iaculis. Nunc posuere pharetra velit. Nunc ac ante non massa scelerisque blandit sit amet vel velit. Integer in massa sed augue pulvinar malesuada. Pellentesque laoreet orci augue, in fermentum nisl feugiat ut. Nunc congue et nisi a interdum. Aenean mauris mi, interdum vel lacus et, placerat gravida augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sagittis ipsum et consequat euismod. Praesent a ipsum dapibus, aliquet justo a, consectetur magna. Phasellus imperdiet tempor laoreet. Sed a accumsan lacus, accumsan faucibus dolor. Praesent euismod justo quis ipsum aliquam suscipit. Sed quis blandit urna."

msgid "DéLonghi ECAM 44.660.B. Start the morning with your favorite drink with the DeLonghi ECAM 44.660.B Eletta automatic coffee maker"
msgstr "DeLonghi ECAM 44.660 B Luxusní plnoautomatický kávovar Eletta Plus v černé barvě s nerezovými částmi,1450 W"

Expand Down
6 changes: 0 additions & 6 deletions translations/dataFixtures.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,6 @@ msgstr ""
msgid "Construction"
msgstr ""

msgid "Contact"
msgstr ""

msgid "Coupon valued to 100 Czech crowns. You can cash it at any exchange office"
msgstr ""

Expand Down Expand Up @@ -694,9 +691,6 @@ msgstr ""
msgid "Done"
msgstr ""

msgid "Donec at dolor mi. Nullam ornare, massa in cursus imperdiet, felis nisl auctor ante, vel aliquet tortor lacus sit amet ipsum. Proin ultrices euismod elementum. Integer sodales hendrerit tortor, vel semper turpis interdum eu. Phasellus quam tortor, feugiat vel condimentum vel, tristique et ipsum. Duis blandit lectus in odio cursus rutrum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam pulvinar massa at imperdiet venenatis. Maecenas convallis lobortis quam in fringilla. Mauris gravida turpis eget sapien imperdiet pulvinar. Nunc velit urna, fringilla nec est sit amet, accumsan varius nunc. Morbi sed tincidunt diam, sit amet laoreet nisl. Nulla tempus id lectus non lacinia.\\n\\nVestibulum interdum adipiscing iaculis. Nunc posuere pharetra velit. Nunc ac ante non massa scelerisque blandit sit amet vel velit. Integer in massa sed augue pulvinar malesuada. Pellentesque laoreet orci augue, in fermentum nisl feugiat ut. Nunc congue et nisi a interdum. Aenean mauris mi, interdum vel lacus et, placerat gravida augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed sagittis ipsum et consequat euismod. Praesent a ipsum dapibus, aliquet justo a, consectetur magna. Phasellus imperdiet tempor laoreet. Sed a accumsan lacus, accumsan faucibus dolor. Praesent euismod justo quis ipsum aliquam suscipit. Sed quis blandit urna."
msgstr ""

msgid "DéLonghi ECAM 44.660.B. Start the morning with your favorite drink with the DeLonghi ECAM 44.660.B Eletta automatic coffee maker"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions translations/messages.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ msgstr "Název firmy"
msgid "Company number"
msgstr "IČ"

msgid "Contact"
msgstr "Kontakt"

msgid "Contact us"
msgstr "Napište nám"

Expand Down
4 changes: 3 additions & 1 deletion translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ msgstr ""
msgid "Company number"
msgstr ""

msgid "Contact"
msgstr ""

msgid "Contact us"
msgstr ""

Expand Down Expand Up @@ -675,4 +678,3 @@ msgstr ""

msgid "{1}Load next %loadNextCount% product|[2,Inf]Load next %loadNextCount% products"
msgstr ""

0 comments on commit ab41237

Please sign in to comment.