public function testFind()
 {
     $code = '20PCT';
     $name = '20% Off orders over $100';
     $value = 20;
     $minOrderValue = 10000;
     $maxOrderValue = 100000;
     $promotionType = PromotionType::fixed();
     $originalCoupon = new Coupon($code);
     $originalCoupon->setName($name);
     $originalCoupon->setValue($value);
     $originalCoupon->setType($promotionType);
     $originalCoupon->setMinOrderValue($minOrderValue);
     $originalCoupon->setMaxOrderValue($maxOrderValue);
     $originalCoupon->setFlagFreeShipping(true);
     $originalCoupon->setCanCombineWithOtherCoupons(true);
     $this->persistEntityAndFlushClear($originalCoupon);
     $this->setCountLogger();
     $coupon = $this->couponRepository->findOneById($originalCoupon->getId());
     $this->assertEquals($originalCoupon->getId(), $coupon->getId());
     $this->assertSame($code, $coupon->getCode());
     $this->assertSame($name, $coupon->getName());
     $this->assertSame($value, $coupon->getValue());
     $this->assertSame($minOrderValue, $coupon->getMinOrderValue());
     $this->assertSame($maxOrderValue, $coupon->getMaxOrderValue());
     $this->assertTrue($coupon->getType()->isFixed());
     $this->assertTrue($coupon->getFlagFreeShipping());
     $this->assertTrue($coupon->getCanCombineWithOtherCoupons());
     $this->assertSame(1, $this->getTotalQueries());
 }
예제 #2
0
 public function testCreate()
 {
     $code = '20PCT100';
     $coupon = new Coupon($code);
     $this->assertSame(null, $coupon->getName());
     $this->assertSame($code, $coupon->getCode());
     $this->assertSame(null, $coupon->getValue());
     $this->assertSame(null, $coupon->getMinOrderValue());
     $this->assertSame(null, $coupon->getMaxOrderValue());
     $this->assertTrue($coupon->getType()->isFixed());
     $this->assertFalse($coupon->getFlagFreeShipping());
     $this->assertFalse($coupon->getCanCombineWithOtherCoupons());
 }
예제 #3
0
 public static function setFromDTO(Coupon &$coupon, CouponDTO $couponDTO)
 {
     $coupon->setCode($couponDTO->code);
     $coupon->setFlagFreeShipping($couponDTO->flagFreeShipping);
     $coupon->setMinOrderValue($couponDTO->minOrderValue);
     $coupon->setMaxOrderValue($couponDTO->maxOrderValue);
     $coupon->setCanCombineWithOtherCoupons($couponDTO->canCombineWithOtherCoupons);
 }
예제 #4
0
 public function handle(CreateCouponCommand $command)
 {
     $coupon = new Coupon($command->getCode(), $command->getCouponId());
     $coupon->setFlagFreeShipping($command->getFlagFreeShipping());
     $coupon->setMinOrderValue($command->getMinOrderValue());
     $coupon->setMaxOrderValue($command->getMaxOrderValue());
     $coupon->setCanCombineWithOtherCoupons($command->canCombineWithOtherCoupons());
     $coupon->setName($command->getName());
     $coupon->setType(PromotionType::createById($command->getPromotionTypeId()));
     $coupon->setValue($command->getValue());
     $coupon->setReducesTaxSubtotal($command->getReducesTaxSubtotal());
     $coupon->setMaxRedemptions($command->getMaxRedemptions());
     $coupon->setStart($command->getStartDate());
     $coupon->setEnd($command->getEndDate());
     $this->couponService->create($coupon);
 }
예제 #5
0
 /**
  * @param Coupon $coupon
  * @return bool
  */
 private function couponCanCombineWithOtherCoupons(Coupon $coupon)
 {
     return !($this->coupons->count() > 0 && !$coupon->getCanCombineWithOtherCoupons());
 }
예제 #6
0
 public function getCoupon($code = null)
 {
     if ($code === null) {
         $code = uniqid();
     }
     $coupon = new Coupon($code);
     $coupon->setName('20% OFF Test Coupon');
     $coupon->setType(PromotionType::percent());
     $coupon->setValue(20);
     $coupon->setStart(new DateTime('-1 Day'));
     $coupon->setEnd(new DateTime('+1 Day'));
     return $coupon;
 }