Exemplo n.º 1
0
 public function testCreate()
 {
     $productQuantityDiscount = $this->dummyData->getProductQuantityDiscount();
     $catalogPromotion = $this->dummyData->getCatalogPromotion();
     $this->pricing->setProductQuantityDiscounts([$productQuantityDiscount]);
     $this->pricing->setCatalogPromotions([$catalogPromotion]);
     $this->assertTrue($this->pricing->getPrice(new Product(), 1) instanceof Price);
     $this->assertTrue($this->pricing->getDate() instanceof DateTime);
     $this->assertTrue($this->pricing->getProductQuantityDiscounts()[0] instanceof ProductQuantityDiscount);
     $this->assertTrue($this->pricing->getCatalogPromotions()[0] instanceof CatalogPromotion);
 }
Exemplo n.º 2
0
 private function calculateCatalogPromotions()
 {
     foreach ($this->pricing->getCatalogPromotions() as $catalogPromotion) {
         if ($catalogPromotion->isValid($this->pricing->getDate(), $this->product)) {
             $this->price->unitPrice = $catalogPromotion->getUnitPrice($this->price->unitPrice);
             $this->price->addCatalogPromotion($catalogPromotion);
         }
     }
     // No prices below zero!
     $this->price->unitPrice = max(0, $this->price->unitPrice);
 }
Exemplo n.º 3
0
 private function calculateCouponDiscounts()
 {
     foreach ($this->cart->getCoupons() as $key => $coupon) {
         if ($coupon->isValid($this->pricing->getDate(), $this->cartTotal->subtotal)) {
             $newSubtotal = $coupon->getUnitPrice($this->cartTotal->subtotal);
             $discountValue = $this->cartTotal->subtotal - $newSubtotal;
             $this->cartTotal->discount += $discountValue;
             $this->cartTotal->coupons[$key] = $coupon;
             if ($coupon->getReducesTaxSubtotal()) {
                 $this->cartTotal->taxSubtotal -= $discountValue;
             }
             if ($coupon->getFlagFreeShipping()) {
                 $this->cartTotal->shippingDiscount = $this->cartTotal->shipping;
                 $this->cartTotal->discount += $this->cartTotal->shipping;
             }
         }
     }
     // No taxes below zero!
     $this->cartTotal->taxSubtotal = max(0, $this->cartTotal->taxSubtotal);
 }