示例#1
0
文件: CartTest.php 项目: extcode/cart
 /**
  * @test
  */
 public function addSecondCombinableCouponAddsCoupon()
 {
     $firstCoupon = $this->getMock(\Extcode\Cart\Domain\Model\Cart\CartCoupon::class, array(), array(), '', false, true, true, array('getCode', 'getIsCombinable'));
     $firstCoupon->expects($this->any())->method('getCode')->will($this->returnValue('firstCouponCode'));
     $firstCoupon->expects($this->any())->method('getTitle')->will($this->returnValue('firstCouponTitle'));
     $firstCoupon->expects($this->any())->method('getDiscount')->will($this->returnValue(10.0));
     $firstCoupon->expects($this->any())->method('getTaxClass')->will($this->returnValue($this->normalTaxClass));
     $firstCoupon->expects($this->any())->method('getIsCombinable')->will($this->returnValue(true));
     $secondCoupon = $this->getMock(\Extcode\Cart\Domain\Model\Cart\CartCoupon::class, array(), array(), '', false, true, true, array('getCode', 'getIsCombinable'));
     $secondCoupon->expects($this->any())->method('getCode')->will($this->returnValue('secondCouponCode'));
     $secondCoupon->expects($this->any())->method('getTitle')->will($this->returnValue('secondCouponTitle'));
     $secondCoupon->expects($this->any())->method('getDiscount')->will($this->returnValue(10.0));
     $secondCoupon->expects($this->any())->method('getTaxClass')->will($this->returnValue($this->normalTaxClass));
     $secondCoupon->expects($this->any())->method('getIsCombinable')->will($this->returnValue(true));
     $this->grossCart->addCoupon($firstCoupon);
     $this->grossCart->addCoupon($secondCoupon);
     $this->assertCount(2, $this->grossCart->getCoupons());
     $this->netCart->addCoupon($firstCoupon);
     $this->netCart->addCoupon($secondCoupon);
     $this->assertCount(2, $this->netCart->getCoupons());
 }
示例#2
0
 /**
  * Add Coupons to Order Item
  */
 protected function addCoupons()
 {
     /**
      * @var $cartCoupon \Extcode\Cart\Domain\Model\Cart\CartCoupon
      */
     foreach ($this->cart->getCoupons() as $cartCoupon) {
         if ($cartCoupon->getIsUseable()) {
             $orderDiscount = new \Extcode\Cart\Domain\Model\Order\Discount($cartCoupon->getTitle(), $cartCoupon->getCode(), $cartCoupon->getGross(), $cartCoupon->getNet(), $cartCoupon->getTaxClass(), $cartCoupon->getTax());
             $orderDiscount->setPid($this->storagePid);
             $this->orderDiscountRepository->add($orderDiscount);
             $this->orderItem->addDiscount($orderDiscount);
             $coupon = $this->productCouponRepository->findOneByCode($cartCoupon->getCode());
             $coupon->incNumberUsed();
             $this->productCouponRepository->update($coupon);
         }
     }
 }