Skip to content

Commit

Permalink
custom validation for eticket and cashOnDelivery in paymentShippingStep.
Browse files Browse the repository at this point in the history
Added translation for forms_error in twig template.
  • Loading branch information
David Alexa committed Jan 29, 2016
1 parent 998d7dc commit c101cc3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sylius\Component\Core\Model\ShippingMethod;
use Sylius\Component\Core\Model\UserInterface;
use Sylius\Component\Core\SyliusCheckoutEvents;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;

/**
Expand Down Expand Up @@ -86,6 +87,14 @@ public function forwardAction(ProcessContextInterface $context)
$formShipping = $this->createCheckoutShippingForm($order, $formShippingPre->get('country')->getData());
$formShipping->handleRequest($request);

if ($formPayment->isSubmitted() && $formShipping->isSubmitted()) {
// custom validation for pandaticket cashOnDelivery and eTicket combination
// TODO remove when relations between payment and delivery will be available
if ($order->getLastPayment()->getMethod()->getGateway() == 'cashOnDelivery' && $order->getLastShipment()->getMethod()->getCategory()->isGenerateTickets()) {
$formPayment->get('paymentMethod')->addError(new FormError('funlife.eshop.form.payment.cash_on_delivery'));
}
}

if ($formPayment->isValid() && $formShipping->isValid() && (!$this->requireAddress($order) || $formAddressing->isValid())) {
$compareAddr = new Address();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,21 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$choiceList = $methodType->getConfig()->getOption('choice_list');

$requireAddress = array();
$generateTickets = array();
/** @var ShippingMethod $shippingMethod */
$i = 0;
foreach ($choiceList->getChoices() as $shippingMethod) {
if ($shippingMethod->getRequireAddress()) {
$requireAddress[] = $i;
}
if ($shippingMethod->getCategory()->isGenerateTickets()) {
$generateTickets[] = $i;
}
$i++;
}

$view->vars['shipping_methods_requiring_address'] = json_encode(array('ids' => $requireAddress));
$view->vars['shipping_methods_generates_eticket'] = json_encode(array('ids' => $generateTickets));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
{% spaceless %}
{% if errors|length > 0 %}
{% for error in errors %}
<div class="alert alert-danger">{{ error.message }}</div>
<div class="alert alert-danger">{{ error.message|trans(error.messageParameters, 'validators') }}</div>
{% endfor %}
{% endif %}
{% endspaceless %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h3>{{ 'sylius.checkout.shipping.header'|trans|raw }}</h3>

{{ form_errors(form.shipments) }}
<div class="well" id="shippings" data-shippings-requires-addressing="{{ form.vars.shipping_methods_requiring_address }}">
<div class="well" id="shippings" data-shippings-requires-addressing="{{ form.vars.shipping_methods_requiring_address }}" data-shippings-generates-eticket="{{ form.vars.shipping_methods_generates_eticket }}">

<fieldset>
{{ form_row(form.country, {'attr': {'autocomplete': 'off'}}) }}
Expand Down

0 comments on commit c101cc3

Please sign in to comment.