public function __construct(Product $product, DTOBuilderFactoryInterface $dtoBuilderFactory) { $this->entity = $product; $this->dtoBuilderFactory = $dtoBuilderFactory; $this->initializeProductDTO(); $this->setId(); $this->setTime(); $this->entityDTO->slug = Slug::get($this->entity->getName()); $this->entityDTO->sku = $this->entity->getSku(); $this->entityDTO->name = $this->entity->getName(); $this->entityDTO->unitPrice = $this->entity->getUnitPrice(); $this->entityDTO->quantity = $this->entity->getQuantity(); $this->entityDTO->isInventoryRequired = $this->entity->isInventoryRequired(); $this->entityDTO->isPriceVisible = $this->entity->isPriceVisible(); $this->entityDTO->isVisible = $this->entity->isVisible(); $this->entityDTO->isActive = $this->entity->isActive(); $this->entityDTO->isTaxable = $this->entity->isTaxable(); $this->entityDTO->isShippable = $this->entity->isShippable(); $this->entityDTO->shippingWeight = $this->entity->getShippingWeight(); $this->entityDTO->description = $this->entity->getDescription(); $this->entityDTO->rating = $this->entity->getRating(); $this->entityDTO->defaultImage = $this->entity->getDefaultImage(); $this->entityDTO->isInStock = $this->entity->inStock(); $this->entityDTO->areAttachmentsEnabled = $this->entity->areAttachmentsEnabled(); }
public function testCreateDefaults() { $product = new Product(); $this->assertTrue($product->getId() instanceof UuidInterface); $this->assertTrue($product->getCreated() instanceof DateTime); $this->assertSame(null, $product->getSku()); $this->assertSame(null, $product->getName()); $this->assertSame(null, $product->getDescription()); $this->assertSame(null, $product->getDefaultImage()); $this->assertSame(0, $product->getUnitPrice()); $this->assertSame(0, $product->getQuantity()); $this->assertSame(0, $product->getShippingWeight()); $this->assertSame(null, $product->getRating()); $this->assertFalse($product->isInventoryRequired()); $this->assertFalse($product->isPriceVisible()); $this->assertFalse($product->isActive()); $this->assertFalse($product->isVisible()); $this->assertFalse($product->isTaxable()); $this->assertFalse($product->isShippable()); $this->assertSame(0, count($product->getTags())); $this->assertSame(0, count($product->getImages())); $this->assertSame(0, count($product->getProductQuantityDiscounts())); $this->assertSame(0, count($product->getOptionProducts())); $this->assertSame(0, count($product->getProductAttributes())); }
/** * @param Product $product * @param int $quantity * @throws InventoryException * @throws InsufficientInventoryException * @throws EntityValidatorException */ public function reserveProduct(Product $product, $quantity) { if (!$product->isInventoryRequired()) { // TODO: Investigate throwing exception in this case return; } try { $inventoryHoldLocation = $this->inventoryLocationRepository->findOneById($this->inventoryHoldLocationId); } catch (EntityNotFoundException $e) { throw InventoryException::missingInventoryHoldLocation(); } try { $inventoryLocationId = $this->inventoryTransactionRepository->findInventoryIdForProductAndQuantity($product, $quantity); $inventoryLocation = $this->inventoryLocationRepository->findOneById($inventoryLocationId); } catch (EntityNotFoundException $e) { throw new InsufficientInventoryException(); } $this->transferProduct($product, $quantity, 'Hold ' . ngettext('item', 'items', $quantity) . ' for order', $inventoryLocation, $inventoryHoldLocation, InventoryTransactionType::hold()); }