public function copyToOrderFromCustomer(\Eccube\Entity\Order $Order, \Eccube\Entity\Customer $Customer = null) { if (is_null($Customer)) { return $Order; } if ($Customer->getId()) { $Order->setCustomer($Customer); } $Order->setName01($Customer->getName01())->setName02($Customer->getName02())->setKana01($Customer->getKana01())->setKana02($Customer->getKana02())->setCompanyName($Customer->getCompanyName())->setEmail($Customer->getEmail())->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())->setSex($Customer->getSex())->setBirth($Customer->getBirth())->setJob($Customer->getJob()); return $Order; }
/** * Order オブジェクトを生成して返す. * * @param \Eccube\Entity\Customer $Customer Customer インスタンス * @return \Eccube\Entity\Order */ public function createOrder(Customer $Customer) { $faker = $this->getFaker(); $quantity = $faker->randomNumber(2); $Order = new Order(); $Order->setCustomer($Customer)->setCharge(0)->setDeliveryFeeTotal(0)->setDiscount(0)->setOrderStatus($this->app['eccube.repository.order_status']->find($this->app['config']['order_processing']))->setDelFlg(Constant::DISABLED); $Order->copyProperties($Customer); $this->app['orm.em']->persist($Order); $this->app['orm.em']->flush(); $Shipping = new Shipping(); $Shipping->copyProperties($Customer); $Order->addShipping($Shipping); $Shipping->setOrder($Order); $this->app['orm.em']->persist($Shipping); $Product = $this->createProduct(); $ProductClasses = $Product->getProductClasses(); $ProductClass = $ProductClasses[0]; $OrderDetail = new OrderDetail(); $TaxRule = $this->app['eccube.repository.tax_rule']->getByRule(); // デフォルト課税規則 $OrderDetail->setProduct($Product)->setProductClass($ProductClass)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($Order); $Order->addOrderDetail($OrderDetail); $ShipmentItem = new ShipmentItem(); $ShipmentItem->setShipping($Shipping)->setOrder($Order)->setProductClass($ProductClass)->setProduct($Product)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity); $this->app['orm.em']->persist($ShipmentItem); $subTotal = $OrderDetail->getPriceIncTax() * $OrderDetail->getQuantity(); // TODO 送料, 手数料の加算 $Order->setSubTotal($subTotal); $Order->setTotal($subTotal); $Order->setPaymentTotal($subTotal); $this->app['orm.em']->flush(); return $Order; }
/** * Order オブジェクトを生成して返す. * * @param \Eccube\Entity\Customer $Customer Customer インスタンス * @param array $ProductClasses 明細行となる ProductClass の配列 * @return \Eccube\Entity\Order */ public function createOrder(Customer $Customer, array $ProductClasses = array()) { $faker = $this->getFaker(); $quantity = $faker->randomNumber(2); $Pref = $this->app['eccube.repository.master.pref']->find(1); $Order = new Order($this->app['eccube.repository.order_status']->find($this->app['config']['order_processing'])); $Order->setCustomer($Customer); $Order->copyProperties($Customer); $Order->setPref($Pref); $this->app['orm.em']->persist($Order); $this->app['orm.em']->flush($Order); $Delivery = $this->app['eccube.repository.delivery']->find(1); $Shipping = new Shipping(); $Shipping->copyProperties($Customer); $Shipping->setPref($Pref)->setDelivery($Delivery); $Order->addShipping($Shipping); $Shipping->setOrder($Order); $this->app['orm.em']->persist($Shipping); $this->app['orm.em']->flush($Shipping); if (empty($ProductClassess)) { $Product = $this->createProduct(); $ProductClasses = $Product->getProductClasses(); } $subTotal = 0; foreach ($ProductClasses as $ProductClass) { $Product = $ProductClass->getProduct(); $OrderDetail = new OrderDetail(); $TaxRule = $this->app['eccube.repository.tax_rule']->getByRule(); // デフォルト課税規則 $OrderDetail->setProduct($Product)->setProductClass($ProductClass)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($Order); $this->app['orm.em']->flush($OrderDetail); $Order->addOrderDetail($OrderDetail); $ShipmentItem = new ShipmentItem(); $ShipmentItem->setShipping($Shipping)->setOrder($Order)->setProductClass($ProductClass)->setProduct($Product)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity); $Shipping->addShipmentItem($ShipmentItem); $this->app['orm.em']->persist($ShipmentItem); $this->app['orm.em']->flush($ShipmentItem); $subTotal += $OrderDetail->getPriceIncTax() * $OrderDetail->getQuantity(); } // TODO 送料, 手数料の加算 $Order->setSubTotal($subTotal); $Order->setTotal($subTotal); $Order->setPaymentTotal($subTotal); $this->app['orm.em']->flush($Order); return $Order; }
/** * Order オブジェクトを生成して返す. * * @param \Eccube\Entity\Customer $Customer Customer インスタンス * @param array $ProductClasses 明細行となる ProductClass の配列 * @param \Eccube\Entity\Delivery $Delivery Delivery インスタンス * @param integer $add_charge Order に加算される手数料 * @param integer $add_discount Order に加算される値引き額 * @return \Eccube\Entity\Order */ public function createOrder(Customer $Customer, array $ProductClasses = array(), Delivery $Delivery = null, $add_charge = 0, $add_discount = 0, $statusType = null) { $faker = $this->getFaker(); $quantity = $faker->randomNumber(2); $Pref = $this->app['eccube.repository.master.pref']->find($faker->numberBetween(1, 47)); $Payments = $this->app['eccube.repository.payment']->findAll(); if (!$statusType) { $statusType = 'order_processing'; } $OrderStatus = $this->app['eccube.repository.order_status']->find($this->app['config'][$statusType]); $Order = new Order($OrderStatus); $Order->setCustomer($Customer); $Order->copyProperties($Customer); $Order->setPref($Pref)->setPayment($Payments[$faker->numberBetween(0, count($Payments) - 1)])->setPaymentMethod($Order->getPayment()->getMethod())->setMessage($faker->text())->setNote($faker->text()); $this->app['orm.em']->persist($Order); $this->app['orm.em']->flush($Order); if (!is_object($Delivery)) { $Delivery = $this->createDelivery(); foreach ($Payments as $Payment) { $PaymentOption = new PaymentOption(); $PaymentOption->setDeliveryId($Delivery->getId())->setPaymentId($Payment->getId())->setDelivery($Delivery)->setPayment($Payment); $Payment->addPaymentOption($PaymentOption); $this->app['orm.em']->persist($PaymentOption); $this->app['orm.em']->flush($PaymentOption); } $this->app['orm.em']->flush($Payment); } $DeliveryFee = $this->app['eccube.repository.delivery_fee']->findOneBy(array('Delivery' => $Delivery, 'Pref' => $Pref)); $fee = 0; if (is_object($DeliveryFee)) { $fee = $DeliveryFee->getFee(); } $Shipping = new Shipping(); $Shipping->copyProperties($Customer); $Shipping->setPref($Pref)->setDelivery($Delivery)->setDeliveryFee($DeliveryFee)->setShippingDeliveryFee($fee)->setShippingDeliveryName($Delivery->getName()); $Order->addShipping($Shipping); $Shipping->setOrder($Order); $this->app['orm.em']->persist($Shipping); $this->app['orm.em']->flush($Shipping); if (empty($ProductClasses)) { $Product = $this->createProduct(); $ProductClasses = $Product->getProductClasses(); } foreach ($ProductClasses as $ProductClass) { $Product = $ProductClass->getProduct(); $OrderDetail = new OrderDetail(); $TaxRule = $this->app['eccube.repository.tax_rule']->getByRule(); // デフォルト課税規則 $OrderDetail->setProduct($Product)->setProductClass($ProductClass)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($Order); $this->app['orm.em']->flush($OrderDetail); $Order->addOrderDetail($OrderDetail); $ShipmentItem = new ShipmentItem(); $ShipmentItem->setShipping($Shipping)->setOrder($Order)->setProductClass($ProductClass)->setProduct($Product)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity); $Shipping->addShipmentItem($ShipmentItem); $this->app['orm.em']->persist($ShipmentItem); $this->app['orm.em']->flush($ShipmentItem); } $subTotal = $Order->calculateSubTotal(); // TODO 送料無料条件は考慮していない. 必要であれば Order から再集計すること. $Order->setDeliveryFeeTotal($Shipping->getShippingDeliveryFee()); $Order->setSubTotal($subTotal); $Order->setCharge($Order->getCharge() + $add_charge); $Order->setDiscount($Order->getDiscount() + $add_discount); $total = $Order->getTotalPrice(); $Order->setTotal($total); $Order->setPaymentTotal($total); $tax = $Order->calculateTotalTax(); $Order->setTax($tax); $this->app['orm.em']->flush($Order); return $Order; }