/** * Load product. return item otherwise create item. * * @param int $productId * * @return bool */ public function loadProduct($productId) { $collection = $this->catalogCollection->create()->addFieldToFilter('product_id', $productId)->setPageSize(1); if ($collection->getSize()) { //@codingStandardsIgnoreStart return $collection->getFirstItem(); //@codingStandardsIgnoreEnd } else { $this->catalogFactory->create()->setProductId($productId)->save(); } return false; }
/** * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $searchIds = $this->getRequest()->getParam('selected'); if (!is_array($searchIds)) { $this->messageManager->addErrorMessage(__('Please select catalog.')); } else { try { //@codingStandardsIgnoreStart foreach ($searchIds as $searchId) { $model = $this->catalog->create()->setId($searchId); $model->delete(); } //@codingStandardsIgnoreEnd $this->messageManager->addSuccessMessage(__('Total of %1 record(s) were deleted.', count($searchIds))); } catch (\Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath('*/*/'); return $resultRedirect; }