/**
* お届け先の設定(非会員でも使用する)
*/
public function shippingEdit(Application $app, Request $request, $id)
{
// 配送先住所最大値判定
$Customer = $app->user();
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
$addressCurrNum = count($app->user()->getCustomerAddresses());
$addressMax = $app['config']['deliv_addr_max'];
if ($addressCurrNum >= $addressMax) {
throw new NotFoundHttpException();
}
}
// カートチェック
if (!$app['eccube.service.cart']->isLocked()) {
// カートが存在しない、カートがロックされていない時はエラー
return $app->redirect($app->url('cart'));
}
$Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
if (!$Order) {
$app->addError('front.shopping.order.error');
return $app->redirect($app->url('shopping_error'));
}
$Shipping = $Order->findShipping($id);
if (!$Shipping) {
throw new NotFoundHttpException();
}
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
$Shipping->clearCustomerAddress();
}
$CustomerAddress = new CustomerAddress();
if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
$CustomerAddress->setCustomer($Customer);
} else {
$CustomerAddress->setFromShipping($Shipping);
}
$builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// 会員の場合、お届け先情報を新規登録
$Shipping->setFromCustomerAddress($CustomerAddress);
if ($Customer instanceof Customer) {
$app['orm.em']->persist($CustomerAddress);
}
// 配送料金の設定
$app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
// 配送先を更新
$app['orm.em']->flush();
return $app->redirect($app->url('shopping'));
}
return $app->render('Shopping/shipping_edit.twig', array('form' => $form->createView(), 'shippingId' => $id));
}