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 Product $Product * @param ProductClass $ProductClass * @param $quantity * @return \Eccube\Entity\OrderDetail */ public function getNewOrderDetail(Product $Product, ProductClass $ProductClass, $quantity) { $OrderDetail = new OrderDetail(); $TaxRule = $this->app['eccube.repository.tax_rule']->getByRule($Product, $ProductClass); $OrderDetail->setProduct($Product)->setProductClass($ProductClass)->setProductName($Product->getName())->setProductCode($ProductClass->getCode())->setPrice($ProductClass->getPrice02())->setQuantity($quantity)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $ClassCategory1 = $ProductClass->getClassCategory1(); if (!is_null($ClassCategory1)) { $OrderDetail->setClasscategoryName1($ClassCategory1->getName()); $OrderDetail->setClassName1($ClassCategory1->getClassName()->getName()); } $ClassCategory2 = $ProductClass->getClassCategory2(); if (!is_null($ClassCategory2)) { $OrderDetail->setClasscategoryName2($ClassCategory2->getName()); $OrderDetail->setClassName2($ClassCategory2->getClassName()->getName()); } $this->em->persist($OrderDetail); return $OrderDetail; }
/** * 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 インスタンス * @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 の配列 * @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; }
private function getCouponOrder(CouponCoupon $Coupon, $discount, $preOrderId) { $this->Customer = $this->createCustomer('*****@*****.**'); $Order = $this->createOrder($this->Customer); $Order->setPreOrderId($preOrderId); $details = $Coupon->getCouponDetails(); /** @var \Plugin\Coupon\Entity\CouponCouponDetail $CouponDetail */ $CouponDetail = $details[0]; $Product = $CouponDetail->getProduct(); $ProductClasses = $Product->getProductClasses(); $ProductClass = $ProductClasses[0]; $orderDetails = $Order->getOrderDetails(); foreach ($orderDetails as $OrderDetail) { $Order->removeOrderDetail($OrderDetail); } $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(1)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($Order); $Order->addOrderDetail($OrderDetail); $CouponOrder = new CouponCouponOrder(); $CouponOrder->setDelFlg(Constant::DISABLED); $CouponOrder->setDiscount($discount); $CouponOrder->setUserId($this->Customer->getId()); $CouponOrder->setCouponId($Coupon->getId()); $CouponOrder->setOrderId($Order->getId()); $CouponOrder->setPreOrderId($Order->getPreOrderId()); $CouponOrder->setCouponCd($Coupon->getCouponCd()); return $CouponOrder; }
public function testIsOrderInActiveCoupon() { /** @var \Plugin\Coupon\Entity\CouponCoupon $Coupon */ $Coupon = $this->getCoupon(); $Customer = $this->createCustomer(); $Order = $this->createOrder($Customer); $details = $Coupon->getCouponDetails(); /** @var \Plugin\Coupon\Entity\CouponCouponDetail $CouponDetail */ $CouponDetail = $details[0]; $Product = $CouponDetail->getProduct(); $ProductClasses = $Product->getProductClasses(); $ProductClass = $ProductClasses[0]; $orderDetails = $Order->getOrderDetails(); foreach ($orderDetails as $OrderDetail) { $Order->removeOrderDetail($OrderDetail); } $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(1)->setTaxRule($TaxRule->getCalcRule()->getId())->setTaxRate($TaxRule->getTaxRate()); $this->app['orm.em']->persist($OrderDetail); $OrderDetail->setOrder($Order); $Order->addOrderDetail($OrderDetail); $this->actual = $this->app['eccube.plugin.coupon.service.coupon']->isOrderInActiveCoupon($Order); $this->expected = true; $this->verify(); }