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));
 }
Пример #2
0
 public static function setFromDTO(Product &$product, ProductDTO $productDTO)
 {
     $product->setName($productDTO->name);
     $product->setSku($productDTO->sku);
     $product->setUnitPrice($productDTO->unitPrice);
     $product->setQuantity($productDTO->quantity);
     $product->setIsInventoryRequired($productDTO->isInventoryRequired);
     $product->setIsPriceVisible($productDTO->isPriceVisible);
     $product->setIsActive($productDTO->isActive);
     $product->setIsVisible($productDTO->isVisible);
     $product->setIsTaxable($productDTO->isTaxable);
     $product->setIsShippable($productDTO->isShippable);
     $product->setAreAttachmentsEnabled($productDTO->areAttachmentsEnabled);
     $product->setShippingWeight($productDTO->shippingWeight);
     $product->setDescription($productDTO->description);
     $product->setRating($productDTO->rating);
     $product->setDefaultImage($productDTO->defaultImage);
 }
 public function testFindOneById()
 {
     $tag = $this->dummyData->getTag();
     $image = $this->dummyData->getImage();
     $sku = 'TST101';
     $name = 'Test Product';
     $description = 'Test description';
     $defaultImage = 'http://lorempixel.com/400/200/';
     $unitPrice = 500;
     $quantity = 10;
     $shippingWeight = 16;
     $rating = 500;
     $originalProduct = new Product();
     $originalProduct->setSku($sku);
     $originalProduct->setName($name);
     $originalProduct->setDescription($description);
     $originalProduct->setDefaultImage($defaultImage);
     $originalProduct->setUnitPrice($unitPrice);
     $originalProduct->setQuantity($quantity);
     $originalProduct->setShippingWeight($shippingWeight);
     $originalProduct->setRating($rating);
     $originalProduct->setIsInventoryRequired(true);
     $originalProduct->setIsPriceVisible(true);
     $originalProduct->setIsActive(true);
     $originalProduct->setIsVisible(true);
     $originalProduct->setIsTaxable(true);
     $originalProduct->setIsShippable(true);
     $originalProduct->enableAttachments();
     $originalProduct->addTag($tag);
     $originalProduct->addImage($image);
     $attribute = $this->dummyData->getAttribute();
     $attributeValue = $this->dummyData->getAttributeValue($attribute);
     $productAttribute = $this->dummyData->getProductAttribute($originalProduct, $attribute, $attributeValue);
     $option = $this->dummyData->getOption();
     $optionProduct = $this->dummyData->getOptionProduct($option, $originalProduct);
     $productQuantityDiscount = $this->dummyData->getProductQuantityDiscount($originalProduct);
     $this->persistEntityAndFlushClear([$tag, $image, $option, $optionProduct, $attribute, $attributeValue, $originalProduct]);
     $this->setCountLogger();
     $product = $this->productRepository->findOneById($originalProduct->getId());
     $this->assertEquals($originalProduct->getId(), $product->getId());
     $this->assertSame($sku, $product->getSku());
     $this->assertSame($name, $product->getName());
     $this->assertSame($description, $product->getDescription());
     $this->assertSame($defaultImage, $product->getDefaultImage());
     $this->assertSame($unitPrice, $product->getUnitPrice());
     $this->assertSame($quantity, $product->getQuantity());
     $this->assertSame($shippingWeight, $product->getShippingWeight());
     $this->assertSame(5, $product->getRating());
     $this->assertTrue($product->isInventoryRequired());
     $this->assertTrue($product->isPriceVisible());
     $this->assertTrue($product->isActive());
     $this->assertTrue($product->isvisible());
     $this->assertTrue($product->isTaxable());
     $this->assertTrue($product->isShippable());
     $this->assertTrue($product->areAttachmentsEnabled());
     $this->assertEquals($tag->getId(), $product->getTags()[0]->getId());
     $this->assertEquals($image->getId(), $product->getImages()[0]->getId());
     $this->assertEquals($productQuantityDiscount->getId(), $product->getProductQuantityDiscounts()[0]->getId());
     $this->assertEquals($optionProduct->getId(), $product->getOptionProducts()[0]->getId());
     $this->assertEquals($productAttribute->getId(), $product->getProductAttributes()[0]->getId());
     $this->assertSame(6, $this->getTotalQueries());
 }
Пример #4
0
 public function getProduct($sku = null)
 {
     if ($sku === null) {
         $sku = uniqid();
     }
     $product = new Product();
     $product->setSku($sku);
     $product->setName('Test Product');
     $product->setIsInventoryRequired(true);
     $product->setIsPriceVisible(true);
     $product->setIsActive(true);
     $product->setIsVisible(true);
     $product->setIsTaxable(true);
     $product->setIsShippable(true);
     $product->setShippingWeight(16);
     $product->setQuantity(10);
     $product->setUnitPrice(1200);
     return $product;
 }
Пример #5
0
 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));
 }