Пример #1
0
 /**
  * Disable features that are not used in the current installation
  */
 protected function checkFeatures()
 {
     $blnDownloads = false;
     $blnVariants = false;
     $blnAdvancedPrices = false;
     $blnShowSku = false;
     $blnShowPrice = false;
     $arrAttributes = array();
     /** @var \Isotope\Model\ProductType[] $objProductTypes */
     if (($objProductTypes = ProductType::findAllUsed()) !== null) {
         foreach ($objProductTypes as $objType) {
             if ($objType->hasDownloads()) {
                 $blnDownloads = true;
             }
             if ($objType->hasVariants()) {
                 $blnVariants = true;
             }
             if ($objType->hasAdvancedPrices()) {
                 $blnAdvancedPrices = true;
             }
             if (in_array('sku', $objType->getAttributes())) {
                 $blnShowSku = true;
             }
             if (in_array('price', $objType->getAttributes())) {
                 $blnShowPrice = true;
             }
             $arrAttributes = array_merge($arrAttributes, $objType->getAttributes());
         }
     }
     // If no downloads are enabled in any product type, we do not need the option
     if (!$blnDownloads) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['operations']['downloads']);
     }
     // Disable all variant related operations
     if (!$blnVariants) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['global_operations']['toggleVariants']);
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['operations']['generate']);
     }
     // Disable prices button if not enabled in any product type
     if (!$blnAdvancedPrices) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['operations']['prices']);
     }
     // Hide SKU column if not enabled in any product type
     if (!$blnShowSku) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['label']['fields'][2]);
     }
     // Hide price column if not enabled in any product type
     if (!$blnShowPrice) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['label']['fields'][3]);
     }
     // Disable sort-into-group if no groups are defined
     if (Group::countAll() == 0) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['operations']['group']);
     }
     // Disable related categories if none are defined
     if (RelatedCategory::countAll() == 0) {
         unset($GLOBALS['TL_DCA'][Product::getTable()]['list']['operations']['related']);
     }
     foreach (array_diff(array_keys($GLOBALS['TL_DCA'][Product::getTable()]['fields']), array_unique($arrAttributes)) as $field) {
         $GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]['filter'] = false;
         $GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]['sorting'] = false;
         $GLOBALS['TL_DCA'][Product::getTable()]['fields'][$field]['search'] = false;
     }
 }