/** * Proprocess article * * @param string $command Command * @param int $articleUid Article uid * * @return void */ protected function preProcessArticle(&$command, &$articleUid) { if ($command == 'localize') { $command = ''; $this->error('LLL:EXT:commerce/Resources/Private/Language/locallang_be.xml:article.localization'); } elseif ($command == 'delete') { /** * Article * * @var Tx_Commerce_Domain_Model_Article $article */ $article = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Article', $articleUid); $article->loadData(); /** * Product * * @var Tx_Commerce_Domain_Model_Product $product */ $product = $article->getParentProduct(); // check if product or if translated the translation parent category if (!current($product->getParentCategories())) { $product = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $product->getL18nParent()); } if (!Tx_Commerce_Utility_BackendUtility::checkPermissionsOnCategoryContent($product->getParentCategories(), array('editcontent'))) { // Log the error $this->pObj->log('tx_commerce_articles', $articleUid, 3, 0, 1, 'Attempt to ' . $command . ' record without ' . $command . '-permissions'); // Set id to 0 (reference!) to prevent delete of the record $articleUid = 0; } } }
/** * After database product handling * * @param string $status Status * @param string $table Table * @param string|int $id Id * @param array $fieldArray Field array * @param DataHandler $pObj Parent object * * @return void */ protected function afterDatabaseProduct($status, $table, $id, array $fieldArray, DataHandler $pObj) { // if fieldArray has been unset, do not save anything, but load dynaflex config if (count($fieldArray)) { /** * Product * * @var Tx_Commerce_Domain_Model_Product $product */ $product = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $id); $product->loadData(); if (isset($fieldArray['categories'])) { $catList = $this->belib->getUidListFromList(explode(',', $fieldArray['categories'])); $catList = $this->belib->extractFieldArray($catList, 'uid_foreign', TRUE); // get id of the live placeholder instead if such exists $relId = $status != 'new' && $product->getPid() == '-1' ? $product->getT3verOid() : $id; $this->belib->saveRelations($relId, $catList, 'tx_commerce_products_categories_mm', TRUE, FALSE); } // if the live shadow is saved, the product relations have to be saved // to the versioned version if ($status == 'new' && $fieldArray['pid'] == '-1') { $id++; } $this->saveProductRelations($id, $fieldArray); } // sometimes the array is unset because only the checkbox "create new article" // has been checked if that is the case and we have the rights, create the // articles so we check if the product is already created and if we have edit // rights on it if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($id)) { // check permissions /** * Product * * @var Tx_Commerce_Domain_Model_Product $product */ $product = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Product', $id); $parentCategories = $product->getParentCategories(); // check existing categories if (!Tx_Commerce_Utility_BackendUtility::checkPermissionsOnCategoryContent($parentCategories, array('editcontent'))) { $pObj->newlog('You dont have the permissions to create a new article.', 1); } else { // init the article creator /** * Article creator * * @var Tx_Commerce_Utility_ArticleCreatorUtility $articleCreator */ $articleCreator = GeneralUtility::makeInstance('Tx_Commerce_Utility_ArticleCreatorUtility'); $articleCreator->init($id, $this->belib->getProductFolderUid()); // create new articles $articleCreator->createArticles($pObj->datamap[$table][$this->unsubstitutedId ? $this->unsubstitutedId : $id]); // update articles if new attributes were added $articleCreator->updateArticles(); } } }
/** * Calculate article rights * * @param int $uid Uid * @param array $rights Rights * * @return array */ protected function calculateArticleRights($uid, array $rights) { // get all parent categories for the parent product /** * Article * * @var Tx_Commerce_Domain_Model_Article $article */ $article = GeneralUtility::makeInstance('Tx_Commerce_Domain_Model_Article', $uid); // get the parent categories of the product $parentCategories = $article->getParentProduct()->getParentCategories(); // store the rights in the flags $rights['edit'] = $rights['delete'] = Tx_Commerce_Utility_BackendUtility::checkPermissionsOnCategoryContent($parentCategories, array('editcontent')); return $rights; }