public function testGetNamePercent() { $this->productQuantityDiscount->setType(PromotionType::percent()); $this->productQuantityDiscount->setQuantity(10); $this->productQuantityDiscount->setValue(50); $this->assertSame('Buy 10 or more for 50% off', $this->productQuantityDiscount->getName()); }
public function testGetPriceWithProductQuantityDiscountPercent() { $product = new Product(); $product->setUnitPrice(500); $productQuantityDiscount6 = new ProductQuantityDiscount($product); $productQuantityDiscount6->setType(PromotionType::percent()); $productQuantityDiscount6->setQuantity(6); $productQuantityDiscount6->setValue(5); $productQuantityDiscount12 = new ProductQuantityDiscount($product); $productQuantityDiscount12->setType(PromotionType::percent()); $productQuantityDiscount12->setQuantity(12); $productQuantityDiscount12->setValue(30); $productQuantityDiscount24 = new ProductQuantityDiscount($product); $productQuantityDiscount24->setType(PromotionType::percent()); $productQuantityDiscount24->setQuantity(24); $productQuantityDiscount24->setValue(35); $productQuantityDiscounts = $product->getProductQuantityDiscounts(); $this->pricing->setProductQuantityDiscounts($productQuantityDiscounts); $expectedPrice = new Price(); $expectedPrice->unitPrice = 500; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 500; $expectedPrice->origQuantityPrice = 500; $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 1)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 475; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 2850; $expectedPrice->origQuantityPrice = 3000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount6); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 6)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 350; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 4200; $expectedPrice->origQuantityPrice = 6000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount12); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 12)); $expectedPrice = new Price(); $expectedPrice->unitPrice = 325; $expectedPrice->origUnitPrice = 500; $expectedPrice->quantityPrice = 7800; $expectedPrice->origQuantityPrice = 12000; $expectedPrice->addProductQuantityDiscount($productQuantityDiscount24); $this->assertEquals($expectedPrice, $this->pricingCalculator->getPrice($product, 24)); }
public function getProductQuantityDiscount(Product $product = null) { if ($product === null) { $product = $this->getProduct(); } $productQuantityDiscount = new ProductQuantityDiscount($product); $productQuantityDiscount->setType(PromotionType::percent()); $productQuantityDiscount->setQuantity(6); $productQuantityDiscount->setValue(5); $productQuantityDiscount->setCustomerGroup(null); $productQuantityDiscount->setQuantity(1); $productQuantityDiscount->setFlagApplyCatalogPromotions(true); return $productQuantityDiscount; }
public function testGetUnitPriceWithPercent() { $this->promotion->setType(PromotionType::percent()); $this->promotion->setValue(20); $this->assertSame(800, $this->promotion->getUnitPrice(1000)); }
public function testGetters() { $this->assertSame('Fixed', PromotionType::fixed()->getName()); $this->assertSame('Percent', PromotionType::percent()->getName()); $this->assertSame('Exact', PromotionType::exact()->getName()); }
public function testGetTotalWithZip5TaxAndCouponNoReduceSubtotal() { $product = new Product(); $product->setUnitPrice(2000); $product->setIsTaxable(true); $taxRate = new TaxRate(); $taxRate->setZip5(92606); $taxRate->setRate(8.0); $taxRate->setApplyToShipping(false); $coupon = $this->dummyData->getCoupon(); $coupon->setName('20% Off orders under $100'); $coupon->setType(PromotionType::percent()); $coupon->setValue(20); $coupon->setMinOrderValue(1000); $coupon->setMaxOrderValue(10000); $coupon->setReducesTaxSubtotal(false); $cartItem = new CartItem(); $cartItem->setProduct($product); $cartItem->setQuantity(1); $cart = new Cart(); $cart->addCoupon($coupon); $cart->addCartItem($cartItem); $cart->setTaxRate($taxRate); $expectedCartTotal = new CartTotal(); $expectedCartTotal->origSubtotal = 2000; $expectedCartTotal->subtotal = 2000; $expectedCartTotal->taxSubtotal = 2000; $expectedCartTotal->shipping = 0; $expectedCartTotal->discount = 400; $expectedCartTotal->tax = 160; $expectedCartTotal->total = 1760; $expectedCartTotal->savings = 400; $expectedCartTotal->coupons = [$coupon]; $expectedCartTotal->taxRate = $taxRate; $cartCalculator = new CartCalculator(new Pricing()); $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart)); }
private function getPercentCoupon($value) { $coupon = $this->dummyData->getCoupon(); $coupon->setName($value . '% Off'); $coupon->setType(PromotionType::percent()); $coupon->setValue($value); return $coupon; }