/**
  * @param IMarketPlaceType $marketplace_type
  * @return int|bool
  */
 public function store(IMarketPlaceType $marketplace_type)
 {
     $repository = $this->repository;
     $group_repository = $this->group_repository;
     $res = false;
     $this->tx_manager->transaction(function () use(&$res, &$marketplace_type, $repository, $group_repository) {
         $query = new QueryObject();
         $query->addAndCondition(QueryCriteria::equal('Name', $marketplace_type->getName()));
         $query->addAndCondition(QueryCriteria::equal('Slug', $marketplace_type->getSlug()));
         $query->addAndCondition(QueryCriteria::notEqual('ID', $marketplace_type->getIdentifier()));
         $old = $repository->getBy($query);
         if ($old) {
             throw new EntityAlreadyExistsException('MarketPlaceType', sprintf('Name  %s', $marketplace_type->getName()));
         }
         $repository->add($marketplace_type);
     });
     //reload from db...
     $id = $marketplace_type->getIdentifier();
     $marketplace_type = $this->repository->getById($id);
     $g = $marketplace_type->getAdminGroup();
     $permission_code = sprintf('MANAGE_MARKETPLACE_%s', str_replace(' ', '_', strtoupper($marketplace_type->getName())));
     $groups = Permission::get_groups_by_permission($permission_code);
     if (count($groups) == 0) {
         Permission::grant($g->getIdentifier(), $permission_code);
     }
     return $res;
 }
 /**
  * @param IMarketPlaceType $type
  * @return int
  */
 public function getAllowedMarketplaceTypeInstances(IMarketPlaceType $type)
 {
     $mkt = $this->owner->MarketPlaceTypeAllowedInstances('MarketPlaceTypeID = ' . $type->getIdentifier())->first();
     return is_null($mkt) ? 1 : $mkt->getMaxInstances();
 }