Skip to content

Commit

Permalink
[FrontendBundle] check if getClickedButton method exists
Browse files Browse the repository at this point in the history
  • Loading branch information
breakone committed Apr 6, 2022
1 parent 76e46d8 commit 7eedfb1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/CoreShop/Bundle/FrontendBundle/Controller/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ public function summaryAction(Request $request): Response
if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']) && $form->isSubmitted()) {
if ($form->isValid()) {
$cart = $form->getData();
$submit = $form->getClickedButton();
$code = $form->get('cartRuleCoupon')->getData();

if ($submit && 'submit_voucher' === $submit->getName()) {
$code = $form->get('cartRuleCoupon')->getData();
if(method_exists($form, 'getClickedButton')) {
$submit = $form->getClickedButton();
$validateVoucherCode = $submit && 'submit_voucher' === $submit->getName();
} else {
$validateVoucherCode = (bool)$code;
}

if ($validateVoucherCode) {
$voucherCode = $this->getCartPriceRuleVoucherRepository()->findByCode($code ?? '');

if (!$voucherCode instanceof CartPriceRuleVoucherCodeInterface) {
Expand Down

0 comments on commit 7eedfb1

Please sign in to comment.