<?php
/**
* Created by Elements.at New Media Solutions GmbH
*
*/
namespace App\Controller\Shop;
use App\Ecommerce\CartManager\CartPriceModificator\CashbackInsurance;
use App\Ecommerce\CartManager\SessionCart;
use App\Ecommerce\Checkout\PersonalisationDataHandler;
use App\Ecommerce\Checkout\Step\ConfirmStep;
use App\Ecommerce\Checkout\Step\PaymentStep;
use App\Form\AddressDataType;
use App\Form\CheckoutConfirmType;
use App\Form\PaymentType;
use App\Form\ProductDataItemType;
use App\Model\Shop\Checkout\AddressData;
use App\Model\Shop\Checkout\PaymentData;
use App\Model\Shop\Checkout\TicketPersonalisationData;
use App\Model\Shop\Ticket\TicketProduct;
use App\Model\Type\PaymentMethodB2CType;
use App\Service\Shop\VoucherService;
use Carbon\Carbon;
use Elements\Bundle\IncertBundle\PriceSystem\IncertPriceModificator;
use Elements\Bundle\IncertBundle\Service\IncertService;
use Elements\Bundle\TicketShopFrameworkBundle\Ecommerce\Checkout\Step\Address;
use Elements\Bundle\TicketShopFrameworkBundle\Ecommerce\Checkout\Step\ProductData;
use Elements\Bundle\TicketShopFrameworkBundle\Model\DataObject\OnlineShopOrder;
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\CartInterface;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Model\Asset\Image;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Model\DataObject\CustomerContact;
use Pimcore\Model\DataObject\Fieldcollection\Data\IncertVoucher;
use Pimcore\Model\DataObject\Service;
use Pimcore\Model\User;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class CheckoutController
*
* @Route("/{_locale}/shop/checkout")
*
* @package App\Controller\Shop
*/
class CheckoutController extends AbstractShopController
{
/**
* @Route("/login", name="checkout_login")
*
* @param Request $request
*
* @return Response
*
* @throws \Exception
*/
public function loginAction(Request $request): Response
{
$trackingManager = $this->factory->getTrackingManager();
$trackingManager->trackCheckout($this->getCart());
if (!empty($this->userManagerService->loginPrecheck($request))) {
$trackingManager->forwardTrackedCodesAsFlashMessage();
return $this->redirect($this->generateUrl('checkout_address'));
}
return $this->render('shop/checkout/login.html.twig');
}
/**
* Step 1
*
* @Route("/address", name="checkout_address")
*
* @param Request $request
* @param Factory $factory
*
* @return Response
*/
public function addressAction(Request $request, Factory $factory): Response
{
//if cart empty or not checkoutable , redirect to cart list
if (!$this->getCart()->isCheckoutable()) {
return $this->redirectToRoute('cart_list');
}
$cart = $this->getCart();
$checkoutManager = $factory->getCheckoutManager($cart);
/** @var Address $addressStep */
$addressStep = $checkoutManager->getCheckoutStep(Address::STEP_NAME);
$addressData = $addressStep->getData();
$form = $this->createForm(AddressDataType::class, $addressData);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
/** @var AddressData $addressData */
$addressData = $form->getData();
// skidata doesn't allow fullStreetNames over 64 chars (62 chars + 2 empty spaces)
$fullCustomerStreet = trim($addressData->getCustomerStreet() . ' ' . $addressData->getCustomerStreetNumber() . ' ' . $addressData->getCustomerStreetAddon());
$fullDeliverySteet = trim($addressData->getDeliveryStreet() . ' ' . $addressData->getDeliveryStreetNumber() . ' ' . $addressData->getDeliveryStreetAddon());
if (strlen($fullCustomerStreet) > 64) {
$this->addFlash('error', 'checkout.address.full-customer_street-too-long');
return $this->redirectToRoute('checkout_address');
}
if (strlen($fullDeliverySteet) > 64) {
$this->addFlash('error', 'checkout.address.full-delivery_street-too-long');
return $this->redirectToRoute('checkout_address');
}
$checkoutManager->commitStep($addressStep, $addressData);
if (!$addressStep->isValid()) {
return $this->redirectToRoute('checkout_address');
}
$trackingManager = $this->factory->getTrackingManager();
/** @phpstan-ignore-next-line */
$trackingManager->trackShippingInfo($this->getCart());
$trackingManager->forwardTrackedCodesAsFlashMessage();
if ($cart->needsPersonalisation()) {
return $this->redirectToRoute('checkout_personalization');
} else {
$personalisationStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
$checkoutManager->commitStep($personalisationStep, []);
return $this->redirectToRoute('checkout_payment');
}
} catch (\Throwable $throwable) {
return $this->redirectToRoute('checkout_address');
}
}
// $factory->getTrackingManager()->trackCheckout($cart);
return $this->render('shop/checkout/address.html.twig', [
'form' => $form->createView(),
]);
}
/**
* Step 2.1
*
* @Route("/personalization", name="checkout_personalization")
*
* @param Request $request
* @param Factory $factory
*
* @return Response
*/
public function personalizationAction(Request $request, Factory $factory): Response
{
//if cart empty or not checkoutable , redirect to cart list
if (!$this->getCart()->isCheckoutable()) {
return $this->redirectToRoute('cart_list');
}
$cart = $this->getCart();
$checkoutManager = $factory->getCheckoutManager($cart);
$productDataStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
if (!$cart->needsPersonalisation()) {
$productDataStep->commit([]);
return $this->redirectToRoute('checkout_payment');
}
//previous step is not finished
/** @phpstan-ignore-next-line */
if (!$checkoutManager->getCheckoutStep(Address::STEP_NAME)->isComplete()) {
return $this->redirectToRoute('checkout_address');
}
if ($request->get('submit')) {
/** @var ProductData $productDataStep */
$productDataStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
if ($productDataStep->isComplete()) {
$checkoutManager->commitStep($productDataStep, $productDataStep->getData());
return $this->redirectToRoute('checkout_payment');
}
}
return $this->render('shop/checkout/personalization.html.twig', [
'productDataStep' => $productDataStep,
]);
}
/**
* Step 2.2
*
* @Route("/personalization/{itemKey}", name="checkout_personalization_item")
*
* @param Request $request
* @param string $itemKey
* @param PersonalisationDataHandler $personalisationDataHandler
* @param FormFactoryInterface $formFactory
* @param Factory $factory
*
* @return Response
*
* @throws \Exception
*/
public function personalizeItem(
Request $request,
string $itemKey,
PersonalisationDataHandler $personalisationDataHandler,
FormFactoryInterface $formFactory,
Factory $factory
): Response {
/** @var Customer|User|null $user */
$user = $this->getUser();
$cart = $this->getCart();
$checkoutManager = $factory->getCheckoutManager($cart);
$isLoggedIn = $user instanceof Customer;
$isEditingContact = $request->get('edit');
$createNewPerson = false;
$contactId = $request->get('contactId');
$isPersonalized = $request->get('isPersonalized');
/** @var ProductData $productDataStep */
$productDataStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
/** @var Address $addressStep */
$addressStep = $checkoutManager->getCheckoutStep(Address::STEP_NAME);
$addressData = $addressStep->getData();
if ($addressData) {
$deliveryCountry = $addressData->isUseDeliveryAddress() ? $addressData->getDeliveryCountry() : $addressData->getCustomerCountry();
} else {
$deliveryCountry = null;
}
$cartItem = $cart->getItem($itemKey);
/** @var TicketProduct $product */
$product = $cartItem->getProduct();
/** @var Customer|CustomerContact|null $contact */
$contact = Concrete::getById($contactId);
/** @var TicketPersonalisationData $itemData */
$itemData = $productDataStep->getDataForItem($cartItem) ?: new TicketPersonalisationData();
$itemData->setCartItem($cartItem);
$itemData->setContactId((int)$contactId);
$itemData->setIsHTAConsumer((bool)$product->getTicketConsumerCategory()->getIsSwisspassHTAConsumer());
if ($isLoggedIn) {
$personalisationDataHandler->setProfilePictureDirectory(
Service::createFolderByPath("/protected/{$user->getEmail()}-{$user->getId()}")
);
if (empty($contact) && $contactId === '0') {
$createNewPerson = true;
}
if (in_array($contact, $user->getContacts()) || $contact === $user) {
$itemData->setFirstname($contact->getFirstname());
$itemData->setLastname($contact->getLastname());
$itemData->setProfilePictureAsset($contact->getImage());
if ($contact === $user) {
$itemData->setBirthday($contact->getBirthdate());
if ($keycard = $contact->getKeyCard()) {
$itemData->setKeycard($keycard->getNumber());
}
} else {
$itemData->setBirthday($contact->getBirthday());
if ($keycard = $contact->getActiveKeycard()) {
$itemData->setKeycard($keycard->getNumber());
}
}
}
}
$form = $formFactory->createNamed('productData-' . $cartItem->getItemKey(),
ProductDataItemType::class, $itemData, [
'item' => $cartItem,
'deliveryCountry' => $deliveryCountry,
'useDeliveryAddress' => $addressData?->isUseDeliveryAddress(),
'isLoggedIn' => $isLoggedIn,
'validityDate'=> $product->getTicketStartDate(),
]);
$params = [
'user' => $user,
'isLoggedIn' => $isLoggedIn,
'cartItem' => $cartItem,
'createNewPerson' => $createNewPerson,
'contact' => $contact,
'productDataStep' => $productDataStep,
];
$form->handleRequest($request);
if ($form->isSubmitted()) {
$profilePictureFile = null;
if ($form->has('profilePicture') && $form->get('profilePicture')->isValid()) {
$profilePictureFile = $form->get('profilePicture')->getData();
}
if ($form->isValid()) {
$isNew = false;
$personalisationDataHandler->handleData($cartItem, $itemData, $profilePictureFile);
if ($isLoggedIn && ($createNewPerson || $isEditingContact)) {
if (!$contact && $createNewPerson) {
$key = Service::getValidKey("{$itemData->getFirstname()} {$itemData->getLastname()}", 'object');
$contact = CustomerContact::getByPath($user->getFullPath() . '/' . $key);
if (empty($contact)) {
$isNew = true;
$contact = new CustomerContact();
$contact->setPublished(true);
$contact->setKey($key);
$contact->setParent($user);
}
}
$contact->setFirstname($itemData->getFirstname());
$contact->setLastname($itemData->getLastname());
if ($itemData->getBirthday()) {
if ($contact === $user) {
$contact->setBirthdate(Carbon::parse($itemData->getBirthday()));
} else {
$contact->setBirthday(Carbon::parse($itemData->getBirthday()));
}
}
if ($image = Image::getById($itemData->getAssetId())) {
$contact->setImage($image);
}
$contact->save();
$itemData->setContactId($contact->getId());
if ($isNew) {
$newContactsArray = array_merge($user->getContacts(), [$contact]);
$user->setContacts($newContactsArray);
$user->save();
}
}
$teaserResultContent = $this->renderTemplate('shop/includes/personalization/personalization-result.html.twig')->getContent();
$footerTopContent = $this->renderTemplate('shop/includes/checkout/checkout-cart-footer-top.html.twig', [
'step' => 'personalization',
])->getContent();
$footerBottomContent = $this->renderTemplate('shop/includes/checkout/checkout-cart-footer-details.html.twig', [
'redirectUri' => $this->generateUrl('checkout_personalization'),
])->getContent();
return $this->json([
'success' => true,
'content' => [
'teaser-result' => $teaserResultContent,
'checkout-footer-top' => $footerTopContent,
'checkout-footer-bottom' => $footerBottomContent,
],
]);
} else {
// in case of invalid, at least upload the picture if exists to make it easier for user ;)
$personalisationDataHandler->handleData($cartItem, $itemData, $profilePictureFile, true);
$params['form'] = $form->createView();
$failedContent = $this->renderTemplate('shop/includes/personalization/personalization-modal-content-result.html.twig', $params)->getContent();
$content = ['failed-form-result' => $failedContent];
}
} elseif ($contactId !== null && !$isPersonalized) {
$params['form'] = $form->createView();
$content = $this->renderTemplate('shop/includes/personalization/personalization-person-result.html.twig', $params)->getContent();
} else {
$params['form'] = $form->createView();
$content = $this->renderTemplate('shop/includes/personalization/personalization-modal-content.html.twig', $params)->getContent();
}
return $this->json([
'success' => true,
'content' => $content,
]);
}
/**
* Step 3
*
* @Route("/payment", name="checkout_payment")
*
* @param Request $request
* @param Factory $factory
*
* @return Response
*/
public function paymentAction(Request $request, Factory $factory, VoucherService $voucherService): Response
{
//if cart empty or not checkoutable , redirect to cart list
if (!$this->getCart()->isCheckoutable()) {
return $this->redirectToRoute('cart_list');
}
$cart = $this->getCart();
$checkoutManager = $factory->getCheckoutManager($cart);
/** @var ProductData $personalizationStep */
$personalizationStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
if (!$personalizationStep->isComplete()) {
return $this->redirectToRoute('checkout_personalization');
} else {
//if a personalized ticket is removed, we have to commit this step again
$checkoutManager->commitStep($personalizationStep, $personalizationStep->getData() ?: []);
}
/** @var PaymentStep $paymentStep */
$paymentStep = $checkoutManager->getCheckoutStep(PaymentStep::STEP_NAME);
$paymentData = $paymentStep->getData() ?: new PaymentData();
$paymentData->setOrderLanguage($request->getLocale());
$this->preselectCashbackPriceModificator($cart);
if ($cart->getPriceCalculator()->getGrandTotal()->getAmount()->isZero()) {
$paymentData->setNeedsPayment(false);
} else {
$paymentData->setNeedsPayment(true);
}
$form = $this->createForm(PaymentType::class, $paymentData);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$checkoutManager->commitStep($paymentStep, $data);
$paymentType = PaymentMethodB2CType::search($data->getPaymentMethod()) ?: $data->getPaymentMethod();
$trackingManager = $this->factory->getTrackingManager();
/** @phpstan-ignore-next-line */
$trackingManager->trackPaymentInfo($this->getCart(), $paymentType);
$trackingManager->forwardTrackedCodesAsFlashMessage();
return $this->redirectToRoute('checkout_confirm');
}
$incertVouchers = $cart->getCheckoutData(IncertPriceModificator::CHECKOUT_DATA_NAME) ?: [];
$params['incertVouchers'] = $voucherService->getIncertVoucherData($incertVouchers, $cart);
$params['pimcoreVouchers'] = $voucherService->getPimcoreVoucherData($cart);
$params['form'] = $form->createView();
return $this->render('shop/checkout/payment.html.twig', $params);
}
/**
* Step 4
*
* @Route("/confirm", name="checkout_confirm")
*
* @param Request $request
* @param Factory $factory
*
* @return Response
*/
public function confirmAction(
Request $request,
Factory $factory
): Response {
//if cart empty or not checkoutable , redirect to cart list
if (!$this->getCart()->isCheckoutable()) {
return $this->redirectToRoute('cart_list');
}
$cart = $this->getCart();
$checkoutManager = $factory->getCheckoutManager($cart);
$confirmOrderStep = $checkoutManager->getCheckoutStep(ConfirmStep::STEP_NAME);
$form = $this->createForm(CheckoutConfirmType::class, $confirmOrderStep->getData());
$form->handleRequest($request);
/** @phpstan-ignore-next-line */
if (!$checkoutManager->getCheckoutStep(ProductData::STEP_NAME)->isComplete()) {
return $this->redirectToRoute('checkout_personalization');
}
/** @phpstan-ignore-next-line */
if (!$checkoutManager->getCheckoutStep(PaymentStep::STEP_NAME)->isComplete()) {
return $this->redirectToRoute('checkout_payment');
}
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$checkoutManager->commitStep($confirmOrderStep, $data);
return $this->redirectToRoute('payment_init');
}
$addressStep = $checkoutManager->getCheckoutStep(Address::STEP_NAME);
$paymentStep = $checkoutManager->getCheckoutStep(PaymentStep::STEP_NAME);
$productDataStep = $checkoutManager->getCheckoutStep(ProductData::STEP_NAME);
return $this->render('shop/checkout/confirm.html.twig', [
'addressData' => $addressStep->getData(),
'paymentData' => $paymentStep->getData(),
'productData' => $productDataStep->getData(),
'form' => $form->createView(),
]);
}
/**
* @Route("/complete", name="checkout_complete")
*
* @param Request $request
*
* @return RedirectResponse|Response
*/
public function completeAction(Request $request)
{
$order = null;
if (!$this->editmode) {
$session = $request->getSession();
$orderId = $session->get('last_order_id');
$order = OnlineShopOrder::getById($orderId);
if ($order) {
if ($order->getOrderState() != $order::ORDER_STATE_COMMITTED) {
return $this->redirectToRoute('cart_list');
}
$this->factory->getTrackingManager()->trackCheckoutComplete($order);
}
}
return $this->renderTemplate('shop/checkout/complete.html.twig', ['order' => $order]);
}
/**
* @Route("/validate-voucher", name="checkout_validate_voucher", methods={"POST"})
*
* @param Request $request
* @param IncertService $incertService
* @param VoucherService $voucherService
*
* @return JsonResponse
*
* @throws \Exception
*/
public function validateVoucher(Request $request, IncertService $incertService, VoucherService $voucherService): JsonResponse
{
/** @var SessionCart $cart */
$cart = $this->getCart();
$voucherData = $cart->getVoucherTokenCodes();
$checkoutManager = Factory::getInstance()->getCheckoutManager($cart);
$requestBody = json_decode($request->getContent(), true);
$voucherAction = $requestBody['action'] ?? '';
$voucherId = $requestBody['voucher'] ?? '';
$voucherId = trim($voucherId);
$voucherType = $requestBody['type'] ?? '';
$html = [];
$errors = [];
$pimcoreErrors = [];
$infos = [];
$incertVouchers = $cart->getCheckoutData(IncertPriceModificator::CHECKOUT_DATA_NAME) ?: [];
if ($voucherId) {
if ($voucherType == 'incert') {
/** @var array<mixed> $incertVouchers */
$currentIncertVoucher = [];
if ($voucherAction == 'remove') {
if ($incertVouchers) {
/** @var IncertVoucher $incertVoucher */
foreach ($incertVouchers as $incertVoucher) {
if ($incertVoucher->getVoucherCode() != $voucherId) {
$currentIncertVoucher[] = $incertVoucher;
}
}
if (count($currentIncertVoucher) > 0) {
/** @phpstan-ignore-next-line */
$cart->setCheckoutData(IncertPriceModificator::CHECKOUT_DATA_NAME, $currentIncertVoucher);
} else {
/** @phpstan-ignore-next-line */
$cart->setCheckoutData(IncertPriceModificator::CHECKOUT_DATA_NAME, false);
}
$cart->save();
$cart->modified();
$infos[] = 'checkout.payment.removed-voucher';
$incertVouchers = $currentIncertVoucher;
}
} elseif ($voucherAction == 'add') {
try {
$voucher = $incertService->getIncertVoucherData($voucherId);
if (!$voucher->isValid()) {
$errors[] = $incertService->getVoucherStatusMessage($voucher->getVoucherStatus());
} else {
// Check that voucher isn't already added - Voucher is unique per Order
/** @var IncertVoucher $voucherInfo */
foreach ($incertVouchers as $voucherInfo) {
if ($voucherInfo->getVoucherCode() === $voucher->getVoucherCode()) {
$errors[] = 'checkout.payment.addvoucher.duplicate';
break;
}
}
if (empty($errors)) {
$voucherItem = new IncertVoucher();
$voucherItem->setCurrency($voucher->getCurrency());
$voucherItem->setVoucherCode($voucher->getVoucherCode());
$voucherItem->setOriginalRedeemedAmount($voucher->getInitialAmount());
$voucherItem->setRedeemedAmount($voucher->getInitialAmount() - $voucher->getCurrentAmount());
$voucherItem->setAmount($voucher->getCurrentAmount());
$voucherItem->setStatus('valid');
$voucherItem->setPartlyRedeemable($voucher->isPartlyRedeemable());
$incertVouchers[] = $voucherItem;
/** @phpstan-ignore-next-line */
$cart->setCheckoutData(IncertPriceModificator::CHECKOUT_DATA_NAME, $incertVouchers);
$cart->save();
}
}
} catch (\Exception $e) {
$errors[] = 'checkout.payment.addvoucher.unavailable';
}
}
}
if ($voucherType == 'discount') {
if ($voucherAction == 'remove') {
$cart->removeVoucherToken($voucherId);
$infos[] = 'checkout.payment.removed-voucher';
}
if ($voucherAction == 'add') {
try {
$success = $cart->addVoucherToken($voucherId);
if (!$success) {
$pimcoreErrors[] = 'checkout.payment.addvoucher.could-not-be-added';
}
} catch (\Exception $e) {
$pimcoreErrors[] = 'checkout.payment.error-voucher-code' . $e->getCode();
}
}
}
}
$requestBody = json_decode($request->getContent(), true);
//cashback
if (isset($requestBody['cashback'])) {
$cart->setCheckoutData('cashback', $requestBody['cashback']);
$cart->save();
$cart->modified();
}
//merch mailing
if (isset($requestBody['certified_mail_merchandise'])) {
$cart->setCheckoutData('certified_mail_merchandise', $requestBody['certified_mail_merchandise'] ?: null);
$cart->save();
$cart->modified();
}
$voucherResult = $this->renderTemplate('shop/includes/checkout/voucher.html.twig', [
'vouchers' => $voucherService->getPimcoreVoucherData($cart),
'type' => 'discount',
'errors' => $pimcoreErrors,
]);
$html['voucher-result-discount'] = $voucherResult->getContent();
$voucherResult = $this->renderTemplate('shop/includes/checkout/voucher.html.twig', [
'vouchers' => $voucherService->getIncertVoucherData($incertVouchers, $cart),
'type' => 'incert',
'errors' => $errors,
'infos' => $infos,
]);
$html['voucher-result'] = $voucherResult->getContent();
$footerTopContent = $this->renderTemplate('shop/includes/checkout/checkout-cart-footer-top.html.twig', [
'step' => 'payment',
])->getContent();
$html['checkout-footer-top'] = $footerTopContent;
$footerBottomContent = $this->renderTemplate('shop/includes/checkout/checkout-cart-footer-details.html.twig', [
'redirectUri' => $this->generateUrl('checkout_payment'),
])->getContent();
$html['checkout-footer-bottom'] = $footerBottomContent;
/** @var PaymentStep $paymentStep */
$paymentStep = $checkoutManager->getCheckoutStep(PaymentStep::STEP_NAME);
$paymentData = $paymentStep->getData() ?: new PaymentData();
//commit payment step if value is zero and voucher was used
if ($cart->getPriceCalculator()->getGrandTotal()->getAmount()->isZero()) {
$checkoutManager->commitStep($paymentStep, $voucherData);
$paymentData->setNeedsPayment(false);
} else {
$paymentData->setNeedsPayment(true);
}
$paymentBlockResult = $this->renderTemplate('shop/includes/checkout/payment-block.html.twig', [
'form' => $this->createForm(PaymentType::class, $paymentData)->createView(),
]);
$html['payments'] = $paymentBlockResult->getContent();
$data = [
'success' => true,
'html' => $html,
];
return new JsonResponse($data);
}
/**
* @Route("/configure-cart-modificators", name="checkout_cart_modificators", methods={"POST"})
*
* @param Request $request
* @param Factory $factory
*
* @return JsonResponse
*/
public function configureCartPriceModificators(Request $request, Factory $factory): JsonResponse
{
$cart = $this->getCart();
$html = '';
//form cart summary
if ($request->get('action') == 'remove') {
$name = $request->get('name');
/** @phpstan-ignore-next-line */
$cart->setCheckoutData($name, false);
$cart->save();
$cart->modified();
$checkoutManager = $factory->getCheckoutManager($cart);
$confirmOrderStep = $checkoutManager->getCheckoutStep(ConfirmStep::STEP_NAME);
$form = $this->createForm(CheckoutConfirmType::class, $confirmOrderStep->getData());
$html = $this->renderTemplate('shop/includes/cart/cart-summary.html.twig', [
'hideForm' => $request->get('hide-form'),
'showCheckoutLink' => $request->get('show-checkout-link'),
'showPaymentMethods' => $request->get('show-payment-methods'),
'form' => $form->createView(),
])->getContent();
}
$data = [
'success' => true,
'html' => $html,
];
return new JsonResponse($data);
}
protected function preselectCashbackPriceModificator(CartInterface $cart): void
{
//Preselection for Optional price modificators such as Cashback
$data = $cart->getCheckoutData('cashback');
$currentData = $data;
foreach ($cart->getPriceCalculator()->getModificators() as $modificator) {
if ($modificator instanceof CashbackInsurance) {
if ($data === null && $modificator->isOptionPreSelected()) {
$data = true;
}
}
}
if ($currentData != $data) {
$cart->setCheckoutData('cashback', $data);
$cart->save();
}
}
/**
* @Route("/register-modal", name="checkout_register_modal")
*
* @param Request $request
*
* @return JsonResponse
*/
public function registerModal(Request $request): JsonResponse
{
$template = $this->renderTemplate('shop/includes/checkout/register-modal.html.twig');
$data = [
'success' => true,
'html' => $template->getContent(),
];
return new JsonResponse($data);
}
}