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());
 }
Example #3
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;
 }
 public function testGetTotalWithCartPriceRulesAndReducesTaxSubtotal()
 {
     $productShirt = new Product();
     $productShirt->setSku('TS-NAVY-LG');
     $productShirt->setName('Navy T-shirt (large)');
     $productShirt->setUnitPrice(1200);
     $productShirt->setIsTaxable(true);
     $productPoster = new Product();
     $productPoster->setSku('PST-CKN');
     $productPoster->setName('Citizen Kane (1941) Poster');
     $productPoster->setUnitPrice(500);
     $productPoster->setIsTaxable(true);
     $cartPriceRule = new CartPriceRule();
     $cartPriceRule->setName('Buy a Shirt get a FREE poster');
     $cartPriceRule->addItem(new CartPriceRuleProductItem($productShirt, 1));
     $cartPriceRule->addItem(new CartPriceRuleProductItem($productPoster, 1));
     $cartPriceRule->addDiscount(new CartPriceRuleDiscount($productPoster, 1));
     $cartPriceRule->setReducesTaxSubtotal(true);
     $pricing = new Pricing();
     $pricing->setCartPriceRules([$cartPriceRule]);
     $cartItem1 = new CartItem();
     $cartItem1->setProduct($productShirt);
     $cartItem1->setQuantity(1);
     $cartItem2 = new CartItem();
     $cartItem2->setProduct($productPoster);
     $cartItem2->setQuantity(1);
     $taxRate = new TaxRate();
     $taxRate->setZip5(92606);
     $taxRate->setRate(8.0);
     $taxRate->setApplyToShipping(false);
     $cart = new Cart();
     $cart->addCartItem($cartItem1);
     $cart->addCartItem($cartItem2);
     $cart->setTaxRate($taxRate);
     $expectedCartTotal = new CartTotal();
     $expectedCartTotal->origSubtotal = 1700;
     $expectedCartTotal->subtotal = 1700;
     $expectedCartTotal->taxSubtotal = 1200;
     $expectedCartTotal->shipping = 0;
     $expectedCartTotal->discount = 500;
     $expectedCartTotal->tax = 96;
     $expectedCartTotal->total = 1296;
     $expectedCartTotal->savings = 500;
     $expectedCartTotal->addCartPriceRule($cartPriceRule);
     $expectedCartTotal->taxRate = $taxRate;
     $cartCalculator = new CartCalculator($pricing);
     $this->assertEquals($expectedCartTotal, $cartCalculator->getTotal($cart));
 }