/** * Test decrease from 10 by 20. */ public function testDecreaseUnderZero() { $item = new InventoryItem(); $item->setQuantity(10); $form = $this->createForm($item); $form->submit(['modifyOperator' => InventoryItem::MODIFY_OPERATOR_DECREASE, 'modifyAmount' => 20]); $this->assertFalse($form->isValid()); }
/** * Fills item collection so it contains all warehouses. * * @param Collection $items * * @return Collection */ protected function fillItemCollection(Collection $items) { $indexed = []; /** @var InventoryItem $item */ foreach ($items as $item) { $indexed[$item->getWarehouse()->getId()] = $item; } $warehouses = $this->doctrine->getRepository('MarelloInventoryBundle:Warehouse')->findAll(); foreach ($warehouses as $warehouse) { if (!array_key_exists($warehouse->getId(), $indexed)) { $newItem = new InventoryItem(); $newItem->setWarehouse($warehouse); /* * Add item to collection, collection is not ordered, so any new warehouses will be added to end. * TODO: Solve this by ordering warehouses when retrieving relation on Product entity. */ $items->add($newItem); } } return $items; }
/** * create new products and inventory items * @param array $data * @return Product $product */ private function createProduct(array $data) { $product = new Product(); $product->setSku($data['sku']); $product->setPrice($data['price']); $product->setName($data['name']); $inventoryItem = new InventoryItem(); $inventoryItem->setProduct($product); $inventoryItem->setWarehouse($this->defaultWarehouse); $inventoryItem->setQuantity($data['stock_level']); $product->getInventoryItems()->add($inventoryItem); $status = $this->getReference('product_status_' . $data['status']); $product->setStatus($status); $channels = explode(';', $data['channel']); foreach ($channels as $channelId) { $channel = $this->getReference('marello_sales_channel_' . (int) $channelId); $product->addChannel($channel); } $this->manager->persist($product); return $product; }
/** * @param InventoryItem $item * * @return $this */ public function addInventoryItem(InventoryItem $item) { $item->setProduct($this); $this->inventoryItems->add($item); return $this; }