/** * @param ShoppingList $shoppingList */ protected function saveToStorage(ShoppingList $shoppingList) { /** @var ProductDataStorage $storage */ $storage = $this->get('orob2b_product.service.product_data_storage'); $data = [ProductDataStorage::ENTITY_DATA_KEY => ['accountUser' => $shoppingList->getAccountUser()->getId(), 'account' => $shoppingList->getAccount()->getId()]]; foreach ($shoppingList->getLineItems() as $lineItem) { $data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY][] = [ProductDataStorage::PRODUCT_SKU_KEY => $lineItem->getProduct()->getSku(), ProductDataStorage::PRODUCT_QUANTITY_KEY => $lineItem->getQuantity(), 'comment' => $lineItem->getNotes(), 'productUnit' => $lineItem->getUnit()->getCode(), 'productUnitCode' => $lineItem->getUnit()->getCode()]; } $storage->set($data); }
/** * @param ObjectManager $manager * @param ShoppingList $shoppingList * @param ProductUnit $unit * @param Product $product * @param string $referenceName */ protected function createLineItem(ObjectManager $manager, ShoppingList $shoppingList, ProductUnit $unit, Product $product, $referenceName) { $item = new LineItem(); $item->setNotes('Test Notes'); $item->setAccountUser($shoppingList->getAccountUser()); $item->setOrganization($shoppingList->getOrganization()); $item->setShoppingList($shoppingList); $item->setUnit($unit); $item->setProduct($product); $item->setQuantity(23.15); $manager->persist($item); $this->addReference($referenceName, $item); }