Order process step 3: choose delivery mode.

@throws NotFoundHttpException

@return RedirectResponse|Response
496828
public function deliveryStepAction()
    {
        $request = $this->getCurrentRequest();
        $basket = $this->get('sonata.basket');

        if (0 === $basket->countBasketElements()) {
            return new RedirectResponse($this->generateUrl('sonata_basket_index'));
        }

        $customer = $basket->getCustomer();

        if (!$customer) {
            throw new NotFoundHttpException('customer not found');
        }

        try {
            $form = $this->createForm(ShippingType::class, $basket, [
                'validation_groups' => ['delivery'],
            ]);
        } catch (UndeliverableCountryException $ex) {
            $countryName = Intl::getRegionBundle()->getCountryName($ex->getAddress()->getCountryCode());
            $message = $this->get('translator')->trans('undeliverable_country', ['%country%' => $countryName], 'SonataBasketBundle');
            $this->get('session')->getFlashBag()->add('error', $message);

            return new RedirectResponse($this->generateUrl('sonata_basket_index'));
        }

        $template = 'SonataBasketBundle:Basket:delivery_step.html.twig';

        if ('POST' === $request->getMethod()) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                // save the basket
                $this->get('sonata.basket.factory')->save($form->getData());

                return new RedirectResponse($this->generateUrl('sonata_basket_payment_address'));
            }
        }

        $this->get('sonata.seo.page')->setTitle($this->get('translator')->trans('basket_delivery_title', [], 'SonataBasketBundle'));

        return $this->render($template, [
            'basket' => $basket,
            'form' => $form->createView(),
            'customer' => $customer,
        ]);
    }
883341
public function paymentStepAction()
    {
        $request = $this->getCurrentRequest();
        $basket = $this->get('sonata.basket');

        if (0 === $basket->countBasketElements()) {
            return new RedirectResponse($this->generateUrl('sonata_basket_index'));
        }

        $customer = $basket->getCustomer();

        if (!$customer) {
            throw new HttpException('Invalid customer');
        }

        if (null === $basket->getBillingAddress()) {
            // If no payment address is specified, we assume it's the same as the delivery
            $billingAddress = clone $basket->getDeliveryAddress();
            $billingAddress->setType(AddressInterface::TYPE_BILLING);
            $basket->setBillingAddress($billingAddress);
        }

        $form = $this->createForm(PaymentType::class, $basket, [
            'validation_groups' => ['delivery'],
        ]);

        if ('POST' === $request->getMethod()) {
            $form->handleRequest($request);

            if ($form->isValid()) {
                // save the basket
                $this->get('sonata.basket.factory')->save($basket);

                return new RedirectResponse($this->generateUrl('sonata_basket_final'));
            }
        }

        $this->get('sonata.seo.page')->setTitle($this->get('translator')->trans('basket_payment_title', [], 'SonataBasketBundle'));

        return $this->render('SonataBasketBundle:Basket:payment_step.html.twig', [
            'basket' => $basket,
            'form' => $form->createView(),
            'customer' => $customer,
        ]);
    }
928728
public function notFound(): Response
    {
        $this->response->setStatus(404);
        $this->response->setBody('<html><title>404 Not found</title>404 Not found</html>');
        return $this->response;
    }
481089
protected function notFound()
    {
        $errmsg = sprintf('[%s][%s]method not found: %s:%s. handlers: %s', $this->request->getMethod(), UriHelper::getCurrentUrl(), get_class($this), $this->getLongName(), implode('|', $this->getHandleStack()));
        Ioc::logger('router')->error($errmsg);
        
        $handler = Ioc::get('notFoundHandler');
        return $handler($this->request, $this->response);
    }
850974
public function finishDeliveryExecution()
    {
        $deliveryExecution = null;
        if ($this->hasRequestParameter('deliveryExecution')) {
            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution(
                $this->getRequestParameter('deliveryExecution')
            );
            if ($deliveryExecution->getState() !== DeliveryExecution::STATE_FINISHIED) {
                $stateService = $this->getServiceManager()->get(StateServiceInterface::SERVICE_ID);
                $stateService->finish($deliveryExecution);
            }
        }
        $redirectUrl = LTIDeliveryTool::singleton()->getFinishUrl($this->getLtiMessage($deliveryExecution), $deliveryExecution);
        $this->redirect($redirectUrl);
    }
395268
public function resolveAllAction()
    {
        $this->getEntityManager()->getRepository(Exception::class)->markAllAsResolved();

        $indexUrl = $this->getAdminListConfigurator()->getIndexUrl();

        return new RedirectResponse(
            $this->generateUrl(
                $indexUrl['path'],
                isset($indexUrl['params']) ? $indexUrl['params'] : array()
            )
        );
    }
43928
public function successAction(Request $request)
    {
        $orderId = $request
            ->query
            ->get('id', false);

        $successRoute = $this
            ->redirectionRoutes
            ->getRedirectionRoute('success');

        $redirectUrl = $this
            ->urlGenerator
            ->generate(
                $successRoute->getRoute(),
                $successRoute->getRouteAttributes(
                    $orderId
                )
            );

        return new RedirectResponse($redirectUrl);
    }
1180018
public function processPayment()
    {
        $redsysMethod = $this
            ->redsysMethodFactory
            ->create();

        /**
         * At this point, order must be created given a cart, and placed in PaymentBridge.
         *
         * So, $this->paymentBridge->getOrder() must return an object
         */
        $this
            ->paymentEventDispatcher
            ->notifyPaymentOrderLoad(
                $this->paymentBridge,
                $redsysMethod
            );

        /**
         * Order Not found Exception must be thrown just here.
         */
        if (!$this->paymentBridge->getOrder()) {
            throw new PaymentOrderNotFoundException();
        }

        /**
         * Order exists right here.
         */
        $this
            ->paymentEventDispatcher
            ->notifyPaymentOrderCreated(
                $this->paymentBridge,
                $redsysMethod
            );

        return $this
            ->redsysFormTypeBuilder
            ->buildForm();
    }
621234
public function process() {
		$route = $this->findFirstMatchingRoute();
		if( !$route ) {
			// Not found, look for an alternative (with /)
			$route = $this->findFirstMatchingRoute(true);
			if( $route ) {
				// Alternative found, try to redirect to this one
				$r = $this->redirect($route);
				if( $r ) {
					// Redirect
					return $r;
				}
				// Unable to redirect, throw not found
				$route = null;
			}
		}
		return $this->processRoute($route);
	}
176263
public function process()
	{
		$context = $this->_getContext();
		$view = $this->getView();

		try
		{
			if( ( $id = $view->param( 'ca-delivery-delete', null ) ) !== null )
			{
				$customerAddressManager = MShop_Factory::createManager( $context, 'customer/address' );
				$address = $customerAddressManager->getItem( $id );

				if( $address->getRefId() != $context->getUserId() ) {
					throw new Client_Html_Exception( sprintf( 'Address with ID "%1$s" not found', $id ) );
				}

				$customerAddressManager->deleteItem( $id );
			}

			// only start if there's something to do
			if( $view->param( 'ca-delivery-option', null ) === null ) {
				return;
			}

			$basketCtrl = Controller_Frontend_Factory::createController( $context, 'basket' );

			/** client/html/common/address/delivery/disable-new
			 * Disables the option to enter a different delivery address for an order
			 *
			 * Besides the billing address, customers can usually enter a different
			 * delivery address as well. To suppress displaying the form fields for
			 * a delivery address, you can set this configuration option to "1".
			 *
			 * @param boolean A value of "1" to disable, "0" enables the delivery address form
			 * @since 2014.03
			 * @category User
			 * @category Developer
			 * @see client/html/common/address/delivery/salutations
			 * @see client/html/common/address/delivery/mandatory
			 * @see client/html/common/address/delivery/optional
			 * @see client/html/common/address/delivery/hidden
			 */
			$disable = $view->config( 'client/html/common/address/delivery/disable-new', false );
			$type = MShop_Order_Item_Base_Address_Abstract::TYPE_DELIVERY;

			if( ( $option = $view->param( 'ca-delivery-option', 'null' ) ) === 'null' && $disable === false ) // new address
			{
				$params = $view->param( 'ca-delivery', array() );
				$invalid = $this->_checkFields( $params );

				if( count( $invalid ) > 0 )
				{
					$view->deliveryError = $invalid;
					throw new Client_Html_Exception( sprintf( 'At least one delivery address part is missing or invalid' ) );
				}

				$basketCtrl->setAddress( $type, $params );
			}
			else if( ( $option = $view->param( 'ca-delivery-option', 'null' ) ) !== '-1' ) // existing address
			{
				$customerAddressManager = MShop_Factory::createManager( $context, 'customer/address' );
				$address = $customerAddressManager->getItem( $option );

				if( $address->getRefId() != $context->getUserId() ) {
					throw new Client_Html_Exception( sprintf( 'Address with ID "%1$s" not found', $option ) );
				}

				$invalid = array();
				$params = $view->param( 'ca-delivery-' . $option, array() );

				if( !empty( $params ) )
				{
					$list = array();
					$invalid = $this->_checkFields( $params );

					foreach( $params as $key => $value ) {
						$list[ str_replace( 'order.base', 'customer', $key ) ] = $value;
					}

					$address->fromArray( $list );
					$customerAddressManager->saveItem( $address );
				}

				if( count( $invalid ) > 0 )
				{
					$view->deliveryError = $invalid;
					throw new Client_Html_Exception( sprintf( 'At least one delivery address part is missing or invalid' ) );
				}

				$basketCtrl->setAddress( $type, $address );
			}
			else
			{
				$basketCtrl->setAddress( $type, null );
			}

			parent::process();
		}
		catch( Controller_Frontend_Exception $e )
		{
			$view->deliveryError = $e->getErrorList();
			throw $e;
		}
	}
256380
public function process()
	{
		$context = $this->getContext();

		try
		{
			if( $context->getUserId() != null )
			{
				$basket = \Aimeos\Controller\Frontend::create( $context, 'basket' )->get();
				$addresses = $basket->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY );

				$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' );
				$item = $cntl->uses( ['customer/address'] )->get();

				foreach( $addresses as $pos => $address )
				{
					if( $address->getAddressId() == '' )
					{
						$addrItem = $cntl->createAddressItem( $address->toArray() );
						$cntl->addAddressItem( $addrItem )->store();
						$basket->addAddress( $address->setAddressId( $addrItem->getId() ), $pos );
					}
				}
			}
		}
		catch( \Exception $e )
		{
			$msg = sprintf( 'Unable to save address for customer "%1$s": %2$s', $context->getUserId(), $e->getMessage() );
			$context->getLogger()->log( $msg, \Aimeos\MW\Logger\Base::INFO );
		}

		parent::process();
	}
389856
public function redirect()
    {
        $state = null;

        if ($this->usesState()) {
            $this->request->session()->put('state', $state = $this->getState());
        }

        return new RedirectResponse($this->getAuthUrl($state));
    }
1330954
public function redirectToRoute()
    {
        if ($this->getRequest()
                 ->isXmlHttpRequest()) {
            return [
                'redirect' => call_user_func_array(
                    [
                        $this->url(),
                        'fromRoute',
                    ],
                    func_get_args()
                ),
            ];
        }

        return call_user_func_array(
            [
                $this->redirect(),
                'toRoute',
            ],
            func_get_args()
        );
    }
1363578
public function executeAction()
    {
        /**
         * The execute action will generate the Paypal web
         * checkout form before redirecting.
         */
        $formView = $this
            ->paypalWebCheckoutManager
            ->generatePaypalForm();

        $data = $this
            ->engine
            ->render('PaypalWebCheckoutBundle:Payment:process.html.twig', [
                'form' => $formView,
            ]);

        return new Response($data);
    }
649586
public function activateAction()
    {
        $object = $this->getObject();
        
        if (method_exists($object, 'setActive') && method_exists($object, 'getActive')) {
            $object->setActive(($object->getActive()==1) ? 0 : 1);
        }
        
        $this->admin->update($object);        
        
        return new RedirectResponse($this->admin->generateUrl('list'));
    }
197337
public function finalReviewStepAction()
    {
        $request = $this->getCurrentRequest();
        $basket = $this->get('sonata.basket');

        $violations = $this
            ->get('validator')
            ->validate($basket, ['elements', 'delivery', 'payment']);

        if ($violations->count() > 0) {
            // basket not valid

            // todo : add flash message rendering in template
            foreach ($violations as $violation) {
                $this->get('session')->getFlashBag()->add('error', 'Error: '.$violation->getMessage());
            }

            return new RedirectResponse($this->generateUrl('sonata_basket_index'));
        }

        if ('POST' === $request->getMethod()) {
            if ($request->get('tac')) {
                // send the basket to the payment callback
                return $this->forward('SonataPaymentBundle:Payment:sendbank');
            }
        }

        $this->get('sonata.seo.page')->setTitle($this->get('translator')->trans('basket_review_title', [], 'SonataBasketBundle'));

        return $this->render('SonataBasketBundle:Basket:final_review_step.html.twig', [
            'basket' => $basket,
            'tac_error' => 'POST' === $request->getMethod(),
        ]);
    }
458154
public function cancelExecution()
    {

        $deliveryExecution = $this->getCurrentDeliveryExecution();
        /** @var DeliveryExecutionStateService $deliveryExecutionStateService */
        $deliveryExecutionStateService = $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
        $reason = [
            'reasons' => ['category' => 'Examinee', 'subCategory' => 'Navigation'],
        ];
        if ($deliveryExecution->getState()->getUri() === DeliveryExecutionState::STATE_AUTHORIZED) {
            $reason['comment'] = __('Automatically reset by the system due to the test taker choosing not to proceed with the authorized test.');
        } else {
            $reason['comment'] = __('Automatically reset by the system due to authorization request being cancelled by test taker.');
        }
        $deliveryExecutionStateService->cancelExecution(
            $deliveryExecution,
            $reason
        );
        return $this->redirect($this->getReturnUrl());
    }