Skip to content

Commit

Permalink
Merge pull request #693 from coreshop/issue-689
Browse files Browse the repository at this point in the history
[FrontendBundle] translate flash messages in the controller to make them more consistant
  • Loading branch information
dpfaffenbauer authored Nov 12, 2018
2 parents 81033bf + f38c347 commit b2798e0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Within V2

## 2.0.0-RC.1
- Flash Messages are translated in the Controllers now, not in views anymore. If you have custom Flash Messages, translate them in your Controller instead of the view.

## 2.0.0-beta.4
- Completely remove FOSRestBundle, you still can use it, but you need to install it yourself. CoreShop only used the BodyListener to decode POST/PUT Requests, this Listener is now added by CoreShop if FOSRestBundle is not installed.

Expand Down
12 changes: 6 additions & 6 deletions src/CoreShop/Bundle/FrontendBundle/Controller/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function summaryAction(Request $request)
$voucherCode = $this->getCartPriceRuleVoucherRepository()->findByCode($code);

if (!$voucherCode instanceof CartPriceRuleVoucherCodeInterface) {
$this->addFlash('error', 'coreshop.ui.error.voucher.not_found');
$this->addFlash('error', $this->get('translator')->trans('coreshop.ui.error.voucher.not_found'));
return $this->renderTemplate($this->templateConfigurator->findTemplate('Cart/summary.html'), [
'cart' => $this->getCart(),
'form' => $form->createView()
Expand All @@ -72,12 +72,12 @@ public function summaryAction(Request $request)

if ($this->getCartPriceRuleProcessor()->process($cart, $priceRule, $voucherCode)) {
$this->getCartManager()->persistCart($cart);
$this->addFlash('success', 'coreshop.ui.success.voucher.stored');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.success.voucher.stored'));
} else {
$this->addFlash('error', 'coreshop.ui.error.voucher.invalid');
$this->addFlash('error', $this->get('translator')->trans('coreshop.ui.error.voucher.invalid'));
}
} else {
$this->addFlash('success', 'coreshop.ui.cart_updated');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.cart_updated'));
}

$this->get('event_dispatcher')->dispatch('coreshop.cart.update', new GenericEvent($cart));
Expand Down Expand Up @@ -188,7 +188,7 @@ public function addItemAction(Request $request)

$this->get('coreshop.tracking.manager')->trackCartAdd($this->getCart(), $product, $quantity);

$this->addFlash('success', 'coreshop.ui.item_added');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.item_added'));

return $this->redirect($redirect);
}
Expand All @@ -210,7 +210,7 @@ public function removeItemAction(Request $request)
return $this->redirectToRoute('coreshop_index');
}

$this->addFlash('success', 'coreshop.ui.item_removed');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.item_removed'));

$this->getCartModifier()->removeItem($this->getCart(), $cartItem);
$this->getCartManager()->persistCart($this->getCart());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function addressAction(Request $request)
$customer->addAddress($address);
$customer->save();

$this->addFlash('success', sprintf('coreshop.ui.customer.address_successfully_%s', $eventType === 'add' ? 'added' : 'updated'));
$this->addFlash('success', $this->get('translator')->trans(sprintf('coreshop.ui.customer.address_successfully_%s', $eventType === 'add' ? 'added' : 'updated')));
return $this->redirect($handledForm->get('_redirect')->getData() ?: $this->generateCoreShopUrl($customer, 'coreshop_customer_addresses'));
}
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function addressDeleteAction(Request $request)

$address->delete();

$this->addFlash('success', 'coreshop.ui.customer.address_successfully_deleted');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.customer.address_successfully_deleted'));
return $this->redirectToRoute('coreshop_customer_addresses');
}

Expand Down Expand Up @@ -252,7 +252,7 @@ public function settingsAction(Request $request)
$event
);

$this->addFlash('success', 'coreshop.ui.customer.profile_successfully_updated');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.customer.profile_successfully_updated'));
return $this->redirectToRoute('coreshop_customer_profile');
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ public function changePasswordAction(Request $request)
$event
);

$this->addFlash('success', 'coreshop.ui.customer.password_successfully_changed');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.customer.password_successfully_changed'));
return $this->redirectToRoute('coreshop_customer_profile');
}
}
Expand Down Expand Up @@ -336,9 +336,9 @@ public function confirmNewsletterAction(Request $request)
$event
);

$this->addFlash('success', 'coreshop.ui.newsletter_confirmed');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.newsletter_confirmed'));
} else {
$this->addFlash('error', 'coreshop.ui.newsletter_confirmation_error');
$this->addFlash('error', $this->get('translator')->trans('coreshop.ui.newsletter_confirmation_error'));
}

return $this->renderTemplate($this->templateConfigurator->findTemplate('Customer/confirm_newsletter.html'), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function passwordResetRequestAction(Request $request)
$dispatcher = $this->container->get('event_dispatcher');
$dispatcher->dispatch('coreshop.customer.request_password_reset', new RequestPasswordChangeEvent($customer, $resetLink));

$this->addFlash('success', 'coreshop.ui.password_reset_request_success');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.password_reset_request_success'));

return $this->redirectToRoute('coreshop_login');
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public function passwordResetAction(Request $request)
$customer->setPassword($resetPassword['password']);
$customer->save();

$this->addFlash('success', 'coreshop.ui.password_reset_success');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.password_reset_success'));

$dispatcher = $this->container->get('event_dispatcher');
$dispatcher->dispatch('coreshop.customer.password_reset', new GenericEvent($customer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function addItemAction(Request $request)

$this->getWishlistModifier()->addItem($this->getWishlist(), $product, $quantity);

$this->addFlash('success', 'coreshop.ui.item_added');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.item_added'));

$redirect = $request->get('_redirect', $this->generateCoreShopUrl($this->getWishlist(), 'coreshop_wishlist_summary'));
return $this->redirect($redirect);
Expand All @@ -61,7 +61,7 @@ public function removeItemAction(Request $request)
return $this->redirectToRoute('coreshop_index');
}

$this->addFlash('success', 'coreshop.ui.item_removed');
$this->addFlash('success', $this->get('translator')->trans('coreshop.ui.item_removed'));

$this->getWishlistModifier()->updateItemQuantity($this->getWishlist(), $product, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% for label, message_data in app.flashes(['success', 'error']) %}
{% for message in message_data %}
{% if label == 'error' %}
{{ messages.error(message) }}
{{ messages.error(message, false) }}
{% else %}
{{ messages.dynamic(message, label)}}
{{ messages.dynamic(message, label, false)}}
{% endif %}
{% endfor %}
{% endfor %}

0 comments on commit b2798e0

Please sign in to comment.