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 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));
 }