/** * @deprecated since 3.0.0, to be removed in 3.1 */ public function findOrCreate(array $conditions) { $DeliveryTime = $this->findOneBy($conditions); if ($DeliveryTime instanceof \Eccube\Entity\DeliveryTime) { return $DeliveryTime; } $DeliveryTime = new \Eccube\Entity\DeliveryTime(); $DeliveryTime->setDelivery($conditions['Delivery']); return $DeliveryTime; }
public function edit(Application $app, $id = 0) { /* @var $Delivery \Eccube\Entity\Delivery */ $Delivery = $app['eccube.repository.delivery']->findOrCreate($id); // FormType: DeliveryFeeの生成 $Prefs = $app['eccube.repository.master.pref']->findAll(); foreach ($Prefs as $Pref) { $DeliveryFee = $app['eccube.repository.delivery_fee']->findOrCreate(array('Delivery' => $Delivery, 'Pref' => $Pref)); if (!$DeliveryFee->getFee()) { $Delivery->addDeliveryFee($DeliveryFee); } } $DeliveryFees = $Delivery->getDeliveryFees(); $DeliveryFeesIndex = array(); foreach ($DeliveryFees as $DeliveryFee) { $Delivery->removeDeliveryFee($DeliveryFee); $DeliveryFeesIndex[$DeliveryFee->getPref()->getId()] = $DeliveryFee; } ksort($DeliveryFeesIndex); foreach ($DeliveryFeesIndex as $timeId => $DeliveryFee) { $Delivery->addDeliveryFee($DeliveryFee); } // FormType: DeliveryTimeの生成 $DeliveryTimes = $Delivery->getDeliveryTimes(); $loop = 16 - count($DeliveryTimes); for ($i = 1; $i <= $loop; $i++) { $DeliveryTime = new \Eccube\Entity\DeliveryTime(); $DeliveryTime->setDelivery($Delivery); $Delivery->addDeliveryTime($DeliveryTime); } $form = $app['form.factory']->createBuilder('delivery', $Delivery)->getForm(); // 支払方法をセット $Payments = array(); foreach ($Delivery->getPaymentOptions() as $PaymentOption) { $Payments[] = $PaymentOption->getPayment(); } $form['delivery_times']->setData($Delivery->getDeliveryTimes()); $form['payments']->setData($Payments); // 登録ボタン押下 if ($app['request']->getMethod() === 'POST') { $form->handleRequest($app['request']); if ($form->isValid()) { $DeliveryData = $form->getData(); // 配送時間の登録 $DeliveryTimes = $form['delivery_times']->getData(); foreach ($DeliveryTimes as $DeliveryTime) { if (is_null($DeliveryTime->getDeliveryTime())) { $Delivery->removeDeliveryTime($DeliveryTime); $app['orm.em']->remove($DeliveryTime); } } // お支払いの登録 $PaymentOptions = $app['eccube.repository.payment_option']->findBy(array('delivery_id' => $id)); // 消す foreach ($PaymentOptions as $PaymentOption) { $DeliveryData->removePaymentOption($PaymentOption); $app['orm.em']->remove($PaymentOption); } $app['orm.em']->persist($DeliveryData); $app['orm.em']->flush(); // いれる $PaymentsData = $form->get('payments')->getData(); foreach ($PaymentsData as $PaymentData) { $PaymentOption = new \Eccube\Entity\PaymentOption(); $PaymentOption->setPaymentId($PaymentData->getId())->setPayment($PaymentData)->setDeliveryId($DeliveryData->getId())->setDelivery($DeliveryData); $DeliveryData->addPaymentOption($PaymentOption); $app['orm.em']->persist($DeliveryData); } $app['orm.em']->persist($DeliveryData); $app['orm.em']->flush(); $app->addSuccess('admin.register.complete', 'admin'); return $app->redirect($app->url('admin_setting_shop_delivery')); } } return $app->render('Setting/Shop/delivery_edit.twig', array('form' => $form->createView(), 'delivery_id' => $id)); }