/** * {@inheritdoc} */ public function handle(MassActionHandlerArgs $args) { $argsParser = new ArgsParser($args); $shoppingList = $this->shoppingListLineItemHandler->getShoppingList($argsParser->getShoppingListId()); if (!$shoppingList) { return $this->generateResponse($args); } try { $addedCnt = $this->shoppingListLineItemHandler->createForShoppingList($shoppingList, $argsParser->getProductIds()); return $this->generateResponse($args, $addedCnt, $shoppingList->getId()); } catch (AccessDeniedException $e) { return $this->generateResponse($args); } }
/** {@inheritdoc} */ public function process(array $data, Request $request) { if (empty($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY]) || !is_array($data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY])) { return; } $data = $data[ProductDataStorage::ENTITY_ITEMS_DATA_KEY]; $shoppingListId = (int) $request->get(sprintf('%s[%s]', QuickAddType::NAME, QuickAddType::ADDITIONAL_FIELD_NAME), null, true); $shoppingList = $this->shoppingListLineItemHandler->getShoppingList($shoppingListId); $productSkus = ArrayUtils::arrayColumn($data, 'productSku'); $productIds = $this->getProductRepository()->getProductsIdsBySku($productSkus); $productSkuQuantities = array_combine($productSkus, ArrayUtils::arrayColumn($data, 'productQuantity')); $productIdsQuantities = array_combine($productIds, $productSkuQuantities); /** @var Session $session */ $session = $request->getSession(); $flashBag = $session->getFlashBag(); try { $entitiesCount = $this->shoppingListLineItemHandler->createForShoppingList($shoppingList, array_values($productIds), $productIdsQuantities); $flashBag->add('success', $this->messageGenerator->getSuccessMessage($shoppingListId, $entitiesCount)); } catch (AccessDeniedException $e) { $flashBag->add('error', $this->messageGenerator->getFailedMessage()); } }
/** * @dataProvider idDataProvider * @param mixed $id */ public function testGetShoppingList($id) { $shoppingList = new ShoppingList(); $this->manager->expects($this->once())->method('getForCurrentUser')->willReturn($shoppingList); $this->assertSame($shoppingList, $this->handler->getShoppingList($id)); }