/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$basket = $builder->getData();
if (!$basket instanceof BasketInterface) {
throw new \RunTimeException('Please provide a BasketInterface instance');
}
$addresses = $this->addressManager->findBy(array('customer' => $basket->getCustomer()->getId(), 'type' => AddressInterface::TYPE_BILLING));
/*
* TODO: implement billing address choice
$builder->add('billingAddress', 'entity', array(
'class' => $this->addressManager->getClass(),
'choices' => $addresses,
'expanded' => true,
));
*/
$address = $basket->getBillingAddress() ?: current($addresses);
$basket->setBillingAddress($address ?: null);
$methods = $this->paymentSelector->getAvailableMethods($basket, $basket->getDeliveryAddress());
$choices = array();
foreach ($methods as $method) {
$choices[$method->getCode()] = $method->getName();
}
reset($methods);
$method = $basket->getPaymentMethod() ?: current($methods);
$basket->setPaymentMethod($method ?: null);
$sub = $builder->create('paymentMethod', 'choice', array('expanded' => true, 'choice_list' => new SimpleChoiceList($choices)));
$sub->addViewTransformer(new PaymentMethodTransformer($this->paymentPool), true);
$builder->add($sub);
}