Ejemplo n.º 1
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());
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
 public function testInStockReturnsFalseWhenLackingQuantity()
 {
     $product = new Product();
     $product->setIsInventoryRequired(true);
     $product->setQuantity(0);
     $this->assertFalse($product->inStock());
 }