public function testPostRemove() { $listener = new ShoppingListListener(); $lifecycleEventArgs = $this->getEventArgs(); $listener->postRemove($lifecycleEventArgs); $this->assertTrue($this->shoppingListTwo->isCurrent()); }
/** * Create shopping list form * * @Route("/create", name="orob2b_shopping_list_frontend_create") * @Template("OroB2BShoppingListBundle:ShoppingList/Frontend:update.html.twig") * @Acl( * id="orob2b_shopping_list_frontend_create", * type="entity", * class="OroB2BShoppingListBundle:ShoppingList", * permission="CREATE", * group_name="commerce" * ) * * @return array|RedirectResponse */ public function createAction() { $shoppingList = new ShoppingList(); /** @var AccountUser $accountUser */ $accountUser = $this->getUser(); $shoppingList->setOwner($accountUser)->setOrganization($accountUser->getOrganization())->setAccount($accountUser->getCustomer())->setAccountUser($accountUser); return $this->update($shoppingList); }
/** * @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 AccountUser $accountUser * @param ShoppingList $shoppingList */ public function setCurrent(AccountUser $accountUser, ShoppingList $shoppingList) { $em = $this->managerRegistry->getManagerForClass('OroB2BShoppingListBundle:ShoppingList'); /** @var ShoppingListRepository $shoppingListRepository */ $shoppingListRepository = $em->getRepository('OroB2BShoppingListBundle:ShoppingList'); $currentList = $shoppingListRepository->findCurrentForAccountUser($accountUser); if ($currentList instanceof ShoppingList && $currentList->getId() !== $shoppingList->getId()) { $currentList->setCurrent(false); } $shoppingList->setCurrent(true); $em->persist($shoppingList); $em->flush(); }
/** * @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); }
public function testProcessExistingShoppingList() { $this->shoppingList->expects($this->once())->method('getId')->willReturn(1); $this->request->expects($this->once())->method('getMethod')->will($this->returnValue('PUT')); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); /** @var \PHPUnit_Framework_MockObject_MockObject|ObjectManager $manager */ $manager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $manager->expects($this->once())->method('persist'); $manager->expects($this->once())->method('flush'); $this->registry->expects($this->once())->method('getManagerForClass')->with(self::SHOPPING_LIST_SHORTCUT)->will($this->returnValue($manager)); $handler = new ShoppingListHandler($this->form, $this->request, $this->manager, $this->registry); $this->assertTrue($handler->process($this->shoppingList)); }
/** * @param ObjectManager $manager * @param AccountUser $accountUser * @param string $label * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $label) { $shoppingList = new ShoppingList(); $shoppingList->setOwner($accountUser); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getCustomer()); $shoppingList->setNotes('Some notes for ' . $label); $shoppingList->setLabel($label); $manager->persist($shoppingList); }
/** * @param ObjectManager $manager * @param string $name * @param AccountUser $accountUser * @param bool $isCurrent * * @return ShoppingList */ protected function createShoppingList(ObjectManager $manager, AccountUser $accountUser, $name, $isCurrent = false) { $shoppingList = new ShoppingList(); $shoppingList->setOrganization($accountUser->getOrganization()); $shoppingList->setAccountUser($accountUser); $shoppingList->setAccount($accountUser->getAccount()); $shoppingList->setLabel($name . '_label'); $shoppingList->setNotes($name . '_notes'); $shoppingList->setCurrent($isCurrent); $manager->persist($shoppingList); $this->addReference($name, $shoppingList); return $shoppingList; }
/** * "Success" form handler * * @param ShoppingList $entity * @return bool */ protected function onSuccess(ShoppingList $entity) { $rfpRequest = new RFPRequest(); $rfpRequest->setFirstName($this->user->getFirstName())->setLastName($this->user->getLastName())->setEmail($this->user->getEmail())->setPhone('')->setRole('')->setBody('')->setCompany($this->user->getOrganization() ? $this->user->getOrganization()->getName() : '')->setAccountUser($this->user)->setAccount($this->user->getAccount())->setStatus($this->requestStatus); foreach ($entity->getLineItems() as $shoppingListLineItem) { $requestProduct = new RequestProduct(); $requestProduct->setProduct($shoppingListLineItem->getProduct()); $requestProductItem = new RequestProductItem(); $requestProductItem->setQuantity($shoppingListLineItem->getQuantity())->setProductUnit($shoppingListLineItem->getUnit()); $requestProduct->addRequestProductItem($requestProductItem); $rfpRequest->addRequestProduct($requestProduct); } try { $this->manager->persist($rfpRequest); $this->manager->flush(); $this->rfpRequest = $rfpRequest; } catch (DBALException $e) { $this->exception = $e; return false; } return true; }
public function testPreUpdate() { $shoppingList = new ShoppingList(); $shoppingList->preUpdate(); $this->assertInstanceOf('\\DateTime', $shoppingList->getUpdatedAt()); }
public function testCreateCurrent() { $this->manager->setCurrent((new AccountUser())->setFirstName('setCurrent'), $this->shoppingListTwo); $this->assertTrue($this->shoppingListTwo->isCurrent()); $this->assertFalse($this->shoppingListOne->isCurrent()); }