public function copyToShippingFromCustomer(\Eccube\Entity\Shipping $Shipping, \Eccube\Entity\Customer $Customer = null) { if (is_null($Customer)) { return $Shipping; } $Shipping->setName01($Customer->getName01())->setName02($Customer->getName02())->setKana01($Customer->getKana01())->setKana02($Customer->getKana02())->setCompanyName($Customer->getCompanyName())->setTel01($Customer->getTel01())->setTel02($Customer->getTel02())->setTel03($Customer->getTel03())->setFax01($Customer->getFax01())->setFax02($Customer->getFax02())->setFax03($Customer->getFax03())->setZip01($Customer->getZip01())->setZip02($Customer->getZip02())->setZipCode($Customer->getZip01() . $Customer->getZip02())->setPref($Customer->getPref())->setAddr01($Customer->getAddr01())->setAddr02($Customer->getAddr02()); return $Shipping; }
public function setUp() { parent::setUp(); $faker = $this->getFaker(); $this->Member = $this->app['eccube.repository.member']->find(2); $this->Customer = $this->createCustomer(); $this->Order = $this->createOrder($this->Customer); $this->Product = $this->createProduct(); $ProductClasses = $this->Product->getProductClasses(); $this->ProductClass = $ProductClasses[0]; $quantity = 3; $TaxRule = $this->app['eccube.repository.tax_rule']->getByRule(); // デフォルト課税規則 $OrderDetail = new OrderDetail(); $OrderDetail->setProduct($this->Product)->setProductClass($this->ProductClass)->setProductName($this->Product->getName())->setProductCode($this->ProductClass->getCode())->setPrice($this->ProductClass->getPrice02())->setQuantity($quantity)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($this->Order); $this->Order->addOrderDetail($OrderDetail); // 1個ずつ別のお届け先に届ける for ($i = 0; $i < $quantity; $i++) { $Shipping = new Shipping(); $Shipping->copyProperties($this->Customer); $Shipping->setName01($faker->lastName)->setName02($faker->firstName)->setKana01('セイ'); $this->Order->addShipping($Shipping); $Shipping->setOrder($this->Order); $this->app['orm.em']->persist($Shipping); $ShipmentItem = new ShipmentItem(); $ShipmentItem->setShipping($Shipping)->setOrder($this->Order)->setProductClass($this->ProductClass)->setProduct($this->Product)->setProductName($this->Product->getName())->setProductCode($this->ProductClass->getCode())->setPrice($this->ProductClass->getPrice02())->setQuantity(1); $this->app['orm.em']->persist($ShipmentItem); } $subTotal = 0; foreach ($this->Order->getOrderDetails() as $OrderDetail) { $subTotal += $OrderDetail->getPriceIncTax() * $OrderDetail->getQuantity(); } $this->Order->setSubTotal($subTotal); $this->Order->setTotal($subTotal); $this->Order->setPaymentTotal($subTotal); $this->app['orm.em']->flush(); }
/** * お届け先情報を作成 * * @param \Eccube\Entity\Shipping $Shipping * @param \Eccube\Entity\Customer|null $Customer * @return \Eccube\Entity\Shipping */ public function copyToShippingFromCustomer(Shipping $Shipping, Customer $Customer = null) { if (is_null($Customer)) { return $Shipping; } $CustomerAddress = $this->app['eccube.repository.customer_address']->findOneBy(array('Customer' => $Customer), array('id' => 'ASC')); if (!is_null($CustomerAddress)) { $Shipping->setName01($CustomerAddress->getName01())->setName02($CustomerAddress->getName02())->setKana01($CustomerAddress->getKana01())->setKana02($CustomerAddress->getKana02())->setCompanyName($CustomerAddress->getCompanyName())->setTel01($CustomerAddress->getTel01())->setTel02($CustomerAddress->getTel02())->setTel03($CustomerAddress->getTel03())->setFax01($CustomerAddress->getFax01())->setFax02($CustomerAddress->getFax02())->setFax03($CustomerAddress->getFax03())->setZip01($CustomerAddress->getZip01())->setZip02($CustomerAddress->getZip02())->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())->setPref($CustomerAddress->getPref())->setAddr01($CustomerAddress->getAddr01())->setAddr02($CustomerAddress->getAddr02()); } else { $Shipping->setName01($Customer->getName01())->setName02($Customer->getName02())->setKana01($Customer->getKana01())->setKana02($Customer->getKana02())->setCompanyName($Customer->getCompanyName())->setTel01($Customer->getTel01())->setTel02($Customer->getTel02())->setTel03($Customer->getTel03())->setFax01($Customer->getFax01())->setFax02($Customer->getFax02())->setFax03($Customer->getFax03())->setZip01($Customer->getZip01())->setZip02($Customer->getZip02())->setZipCode($Customer->getZip01() . $Customer->getZip02())->setPref($Customer->getPref())->setAddr01($Customer->getAddr01())->setAddr02($Customer->getAddr02()); } return $Shipping; }
/** * 複数配送処理 */ public function shippingMultiple(Application $app, Request $request) { $cartService = $app['eccube.service.cart']; // カートチェック if (!$cartService->isLocked()) { // カートが存在しない、カートがロックされていない時はエラー return $app->redirect($app->url('cart')); } // カートチェック if (count($cartService->getCart()->getCartItems()) <= 0) { // カートが存在しない時はエラー return $app->redirect($app->url('cart')); } $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定 $compItemQuantities = array(); foreach ($Order->getShippings() as $Shipping) { foreach ($Shipping->getShipmentItems() as $ShipmentItem) { $itemId = $ShipmentItem->getProductClass()->getId(); $quantity = $ShipmentItem->getQuantity(); if (array_key_exists($itemId, $compItemQuantities)) { $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity; } else { $compItemQuantities[$itemId] = $quantity; } } } // 商品に紐づく商品情報を取得 $shipmentItems = array(); $productClassIds = array(); foreach ($Order->getShippings() as $Shipping) { foreach ($Shipping->getShipmentItems() as $ShipmentItem) { if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) { $shipmentItems[] = $ShipmentItem; } $productClassIds[] = $ShipmentItem->getProductClass()->getId(); } } $form = $app->form()->getForm(); $form->add('shipping_multiple', 'collection', array('type' => 'shipping_multiple', 'data' => $shipmentItems, 'allow_add' => true, 'allow_delete' => true)); $errors = array(); if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { $data = $form['shipping_multiple']; // 数量が超えていないか、同一でないとエラー $itemQuantities = array(); foreach ($data as $mulitples) { /** @var \Eccube\Entity\ShipmentItem $multipleItem */ $multipleItem = $mulitples->getData(); foreach ($mulitples as $items) { foreach ($items as $item) { $quantity = $item['quantity']->getData(); $itemId = $multipleItem->getProductClass()->getId(); if (array_key_exists($itemId, $itemQuantities)) { $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity; } else { $itemQuantities[$itemId] = $quantity; } } } } foreach ($compItemQuantities as $key => $value) { if (array_key_exists($key, $itemQuantities)) { if ($itemQuantities[$key] != $value) { $errors[] = array('message' => '数量の数が異なっています。'); // 対象がなければエラー return $app->render('Shopping/shipping_multiple.twig', array('form' => $form->createView(), 'shipmentItems' => $shipmentItems, 'compItemQuantities' => $compItemQuantities, 'errors' => $errors)); } } } // お届け先情報をdelete/insert $shippings = $Order->getShippings(); foreach ($shippings as $Shipping) { $Order->removeShipping($Shipping); $app['orm.em']->remove($Shipping); } foreach ($data as $mulitples) { /** @var \Eccube\Entity\ShipmentItem $multipleItem */ $multipleItem = $mulitples->getData(); foreach ($mulitples as $items) { foreach ($items as $item) { // 追加された配送先情報を作成 $Delivery = $multipleItem->getShipping()->getDelivery(); // 選択された情報を取得 $data = $item['customer_address']->getData(); if ($data instanceof CustomerAddress) { // 会員の場合、CustomerAddressオブジェクトを取得される $CustomerAddress = $data; } else { // 非会員の場合、選択されたindexが取得される $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); $customerAddresses = unserialize($customerAddresses); $CustomerAddress = $customerAddresses[$data]; $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId()); $CustomerAddress->setPref($pref); } $Shipping = new Shipping(); $Shipping->setName01($CustomerAddress->getName01())->setName02($CustomerAddress->getName02())->setKana01($CustomerAddress->getKana01())->setKana02($CustomerAddress->getKana02())->setCompanyName($CustomerAddress->getCompanyName())->setTel01($CustomerAddress->getTel01())->setTel02($CustomerAddress->getTel02())->setTel03($CustomerAddress->getTel03())->setFax01($CustomerAddress->getFax01())->setFax02($CustomerAddress->getFax02())->setFax03($CustomerAddress->getFax03())->setZip01($CustomerAddress->getZip01())->setZip02($CustomerAddress->getZip02())->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())->setPref($CustomerAddress->getPref())->setAddr01($CustomerAddress->getAddr01())->setAddr02($CustomerAddress->getAddr02())->setDelivery($Delivery)->setDelFlg(Constant::DISABLED)->setOrder($Order); $app['orm.em']->persist($Shipping); $ShipmentItem = new ShipmentItem(); $ProductClass = $multipleItem->getProductClass(); $Product = $multipleItem->getProduct(); $quantity = $item['quantity']->getData(); $ShipmentItem->setShipping($Shipping)->setOrder($Order)->setProductClass($ProductClass)->setProduct($Product)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity); $ClassCategory1 = $ProductClass->getClassCategory1(); if (!is_null($ClassCategory1)) { $ShipmentItem->setClasscategoryName1($ClassCategory1->getName()); $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName()); } $ClassCategory2 = $ProductClass->getClassCategory2(); if (!is_null($ClassCategory2)) { $ShipmentItem->setClasscategoryName2($ClassCategory2->getName()); $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName()); } $Shipping->addShipmentItem($ShipmentItem); $app['orm.em']->persist($ShipmentItem); // 配送料金の設定 $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); } } } // 配送先を更新 $app['orm.em']->flush(); return $app->redirect($app->url('shopping')); } } return $app->render('Shopping/shipping_multiple.twig', array('form' => $form->createView(), 'shipmentItems' => $shipmentItems, 'compItemQuantities' => $compItemQuantities, 'errors' => $errors)); }