public function paymentStepAction()
{
$basket = $this->get('sonata.basket');
if ($basket->countBasketElements() == 0) {
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('sonata_basket_payment', $basket, array('validation_groups' => array('delivery')));
if ($this->get('request')->getMethod() == 'POST') {
$form->bind($this->get('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', array(), 'SonataBasketBundle'));
return $this->render('SonataBasketBundle:Basket:payment_step.html.twig', array('basket' => $basket, 'form' => $form->createView(), 'customer' => $customer));
}