setFromShipping() public method

Set from Shipping.
public setFromShipping ( Shipping $Shipping ) : CustomerAddress
$Shipping Shipping
return CustomerAddress
 /**
  * お届け先の設定(非会員でも使用する)
  */
 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));
 }
Example #2
0
 /**
  * お届け先の設定(非会員でも使用する)
  */
 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()) {
         // カートが存在しない、カートがロックされていない時はエラー
         log_info('カートが存在しません');
         return $app->redirect($app->url('cart'));
     }
     $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
     if (!$Order) {
         log_info('購入処理中の受注情報がないため購入エラー');
         $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);
     $event = new EventArgs(array('builder' => $builder, 'Order' => $Order, 'Shipping' => $Shipping, 'CustomerAddress' => $CustomerAddress), $request);
     $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
     $form = $builder->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         log_info('お届け先追加処理開始', array('id' => $Order->getId(), 'shipping' => $id));
         // 会員の場合、お届け先情報を新規登録
         $Shipping->setFromCustomerAddress($CustomerAddress);
         if ($Customer instanceof Customer) {
             $app['orm.em']->persist($CustomerAddress);
             log_info('新規お届け先登録', array('id' => $Order->getId(), 'shipping' => $id, 'customer address' => $CustomerAddress->getId()));
         }
         // 配送料金の設定
         $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
         // 合計金額の再計算
         $app['eccube.service.shopping']->getAmount($Order);
         // 配送先を更新
         $app['orm.em']->flush();
         $event = new EventArgs(array('form' => $form, 'Shipping' => $Shipping, 'CustomerAddress' => $CustomerAddress), $request);
         $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
         log_info('お届け先追加処理完了', array('id' => $Order->getId(), 'shipping' => $id));
         return $app->redirect($app->url('shopping'));
     }
     return $app->render('Shopping/shipping_edit.twig', array('form' => $form->createView(), 'shippingId' => $id));
 }