public function process($item) { $sku = $item['sku']; $attribute = $this->productManager->getIdentifierAttribute(); $product = $this->productManager->findByIdentifier($sku); if (!$product) { $product = $this->productManager->createProduct(); $value = $this->productManager->createProductValue(); $value->setAttribute($attribute); $value->setData($sku); $product->addValue($value); $this->stepExecution->incrementSummaryInfo('create'); return $product; } else { $data = current(((array) $item)); $this->stepExecution->incrementSummaryInfo('skip'); throw new InvalidItemException(sprintf('Skip the existing %s product', $sku), $data); } }
/** * Create product * * @param Request $request * @param string $dataLocale * * @Template * @AclAncestor("pim_enrich_product_create") * @return array */ public function createAction(Request $request, $dataLocale) { if (!$request->isXmlHttpRequest()) { return $this->redirectToRoute('pim_enrich_product_index'); } $product = $this->productManager->createProduct(); $form = $this->createForm('pim_product_create', $product, $this->getCreateFormOptions($product)); if ($request->isMethod('POST')) { $form->submit($request); if ($form->isValid()) { $this->productSaver->save($product); $this->addFlash('success', 'flash.product.created'); if ($dataLocale === null) { $dataLocale = $this->getDataLocaleCode(); } $url = $this->generateUrl('pim_enrich_product_edit', ['id' => $product->getId(), 'dataLocale' => $dataLocale]); $response = ['status' => 1, 'url' => $url]; return new Response(json_encode($response)); } } return ['form' => $form->createView(), 'dataLocale' => $this->getDataLocaleCode()]; }
/** * {@inheritdoc} */ protected function createEntity($class, array $data) { return $this->productManager->createProduct(); }