Set Pref
public setPref ( Eccube\Entity\Master\Pref $pref = null ) : |
||
$pref | Eccube\Entity\Master\Pref | |
Результат |
/** * 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; }