/** * @param \Eccube\Entity\Customer $Customer * @param null $id * @return \Eccube\Entity\CustomerAddress|mixed * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function findOrCreateByCustomerAndId(\Eccube\Entity\Customer $Customer, $id = null) { if (!$id) { $CustomerAddress = new \Eccube\Entity\CustomerAddress(); $CustomerAddress->setCustomer($Customer)->setDelFlg(0); } else { $qb = $this->createQueryBuilder('od')->andWhere('od.Customer = :Customer AND od.id = :id')->setParameters(array('Customer' => $Customer, 'id' => $id)); $CustomerAddress = $qb->getQuery()->getSingleResult(); } return $CustomerAddress; }
/** * お届け先の設定(非会員でも使用する) */ public function shippingEdit(Application $app, Request $request) { $cartService = $app['eccube.service.cart']; // カートチェック if (!$cartService->isLocked()) { // カートが存在しない、カートがロックされていない時はエラー return $app->redirect($app->url('cart')); } $Order = $app['eccube.repository.order']->findOneBy(array('pre_order_id' => $app['eccube.service.cart']->getPreOrderId())); $shippings = $Order->getShippings(); // 会員の場合、お届け先情報を新規登録 if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { $builder = $app['form.factory']->createBuilder('shopping_shipping'); } else { // 非会員の場合、お届け先を追加 $builder = $app['form.factory']->createBuilder('shopping_shipping', $shippings[0]); } $form = $builder->getForm(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); // 会員の場合、お届け先情報を新規登録 if ($app->isGranted('IS_AUTHENTICATED_FULLY')) { $customerAddress = new \Eccube\Entity\CustomerAddress(); $customerAddress->setCustomer($app->user())->setName01($data['name01'])->setName02($data['name02'])->setKana01($data['kana01'])->setKana02($data['kana02'])->setCompanyName($data['company_name'])->setTel01($data['tel01'])->setTel02($data['tel02'])->setTel03($data['tel03'])->setZip01($data['zip01'])->setZip02($data['zip02'])->setZipCode($data['zip01'] . $data['zip02'])->setPref($data['pref'])->setAddr01($data['addr01'])->setAddr02($data['addr02'])->setDelFlg(Constant::DISABLED); $app['orm.em']->persist($customerAddress); } foreach ($shippings as $shipping) { $shipping->setName01($data['name01'])->setName02($data['name02'])->setKana01($data['kana01'])->setKana02($data['kana02'])->setCompanyName($data['company_name'])->setTel01($data['tel01'])->setTel02($data['tel02'])->setTel03($data['tel03'])->setZip01($data['zip01'])->setZip02($data['zip02'])->setZipCode($data['zip01'] . $data['zip02'])->setPref($data['pref'])->setAddr01($data['addr01'])->setAddr02($data['addr02']); } // 配送先を更新 $app['orm.em']->flush(); return $app->redirect($app->url('shopping')); } } return $app->render('Shopping/shipping_edit.twig', array('form' => $form->createView())); }