Elcodi\Store\CartCouponBundle\Controller\CouponController::applyAction PHP Метод

applyAction() публичный Метод

Add coupon to cart
public applyAction ( Form $couponApplyFormType ) : array
$couponApplyFormType Symfony\Component\Form\Form Coupon Apply type
Результат array
    public function applyAction(Form $couponApplyFormType)
    {
        $translator = $this->get('translator');
        $couponCode = $couponApplyFormType->get('code')->getData();
        /**
         * @var CartInterface $cart
         */
        $cart = $this->get('elcodi.wrapper.cart')->get();
        try {
            $this->get('elcodi.manager.cart_coupon')->addCouponByCode($cart, $couponCode);
            $message = $translator->trans('store.coupon.applied.message_ok');
            $this->addFlash('info', $message);
        } catch (AbstractCouponException $e) {
            $message = $translator->trans('store.coupon.applied.message_ko');
            $this->addFlash('error', $message);
        }
        return $this->redirectToRoute('store_cart_view');
    }