Save new customer group to database

@param array $moduleConfiguration Customer group module configuration
174761
protected function applyConfig(array $moduleConfiguration)
    {
        foreach ($moduleConfiguration['customer_group'] as $customerGroupData) {
            if (CustomerGroupQuery::create()->findOneByCode($customerGroupData['code']) === null) {
                $customerGroup = (new CustomerGroup)
                    ->setCode($customerGroupData['code']);

                foreach ($customerGroupData['descriptive'] as $descriptiveData) {
                    $customerGroup
                        ->setLocale($descriptiveData['locale'])
                        ->setTitle($descriptiveData['title'])
                        ->setDescription($descriptiveData['description']);
                }

                $customerGroup->save();
            }
        }

        if ($moduleConfiguration['default']) {
            $customerGroup = CustomerGroupQuery::create()->findOneByCode($moduleConfiguration['default']);
            if ($customerGroup !== null) {
                $this->resetDefault();

                $customerGroup
                    ->setIsDefault(true)
                    ->save();
            }
        }
    }
738219
public function initialize(array $config)
    {
        $this->verifyConfig();

        $this->_table->hasMany($this->getConfig('associationAlias'), [
            'className' => 'Muffin/Tokenize.Tokens',
            'foreignKey' => 'foreign_key',
            'conditions' => [
                'foreign_alias' => $this->_table->getAlias(),
                'foreign_table' => $this->_table->getTable(),
            ],
            'dependent' => true,
        ]);
    }
818124
public function saveServiceGroup($group, $overwrite = false)
    {
        $filename = $this->getConfigFilename($group);
        $hasConfigFile = $this->hasConfigFile($group);

        // This sucks, but it is the only way to get the builder config.
        // @todo Create a Guzzle issue to add a getBuilderConfig() method.
        $builder = $this[$group];
        $builderConfig = Json::decode($builder->serialize());

        // @todo Add validation.
        if (!$overwrite && $hasConfigFile) {
            $groupJson = file_get_contents($filename);
            $groupData = Json::decode($groupJson);
            $builderConfig = array_merge($groupData['services'], $builderConfig);
        }

        // Unset the services that are flagged to be removed then clear the
        // remove flag since action was taken.
        foreach ($this->removed[$group] as $name) {
            unset($builderConfig[$name]);
        }
        $this->removed[$group] = array();

        $json = Json::encode(array(
            'class' => get_class($builder),
            'services' => $builderConfig,
        ));

        $filesystem = $this->getFilesystem();

        if (!$hasConfigFile) {
            $filesystem->mkdir(dirname($filename), 0755);
        }

        $filesystem->dumpFile($filename, $json, 0600);
    }
1202419
public function createGroup(array $options)
    {
        if ($this->prepared) {
            throw new \RuntimeException('MenuPool has been prepared and can\'t receive new groups.');
        }

        $group = new MenuGroup($this->groupOptionsResolver->resolve($options));

        $this->addGroup($group);
    }
273307
public function newCustomerAutomation($customer)
    {
        $email = $customer->getEmail();
        $websiteId = $customer->getWebsiteId();
        $customerId = $customer->getId();
        $store = $this->storeManager->getStore($customer->getStoreId());
        $storeName = $store->getName();
        try {
            //Api is enabled
            $apiEnabled = $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_API_ENABLED,
                $websiteId
            );

            //Automation enrolment
            $programId = $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_AUTOMATION_STUDIO_CUSTOMER,
                $websiteId
            );

            //new contact program mapped
            if ($programId && $apiEnabled) {
                //save automation type
                $this->setEmail($email)
                    ->setAutomationType(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_CUSTOMER)
                    ->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)
                    ->setTypeId($customerId)
                    ->setWebsiteId($websiteId)
                    ->setStoreName($storeName)
                    ->setProgramId($programId);

                $this->automationResource->save($this);
            }
        } catch (\Exception $e) {
            $this->helper->debug((string)$e, []);
        }
    }
1031657
public function saveConfigurationArray($config, $apply = true)
    {
        if ($this->ignoreIfDefault && $this->attributes) {
            foreach ($this->attributes as $key=>$default) {
                if (isset($config[$key]) && $config[$key]==$default) {
                    unset($config[$key]);
                }
            }
        }
        if ($this->_keyStorage->set($this->getKey(), $config))
        {
            if ($apply) {
                $this->_configuration = null;
                $this->configure();
            }
            return true;
        } else {
            return false;
        }
    }
382999
public function save()
    {
        // saving config params
        $this->saveConfVars();

        $oShop = oxNew(\OxidEsales\Eshop\Application\Model\Shop::class);
        if ($oShop->loadInLang($this->_iEditLang, $this->getEditObjectId())) {
            //assigning values
            $oShop->setLanguage(0);
            $oShop->assign(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('editval'));
            $oShop->setLanguage($this->_iEditLang);
            $oShop->save();

            // saving static url changes
            if (is_array($aStaticUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aStaticUrl'))) {
                $this->_sActSeoObject = \OxidEsales\Eshop\Core\Registry::getSeoEncoder()->encodeStaticUrls($this->_processUrls($aStaticUrl), $oShop->getId(), $this->_iEditLang);
            }
        }
    }
667928
public function saveConfigTypeCMDL($configTypeName, $cmdl)
    {
        $this->repositoryInfo = [];

        $url = 'config/' . $configTypeName . '/cmdl';

        $this->getClient()->setDefaultOption('query',
            [
                'userinfo' => [
                    'username'  => $this->userInfo->getUsername(),
                    'firstname' => $this->userInfo->getFirstname(),
                    'lastname'  => $this->userInfo->getLastname()
                ]
            ]);

        $this->getClient()->post($url, ['body' => ['cmdl' => $cmdl]]);

        $configTypeNames = $this->getConfiguration()->getConfigTypeNames();

        $configTypeNames[] = $configTypeName;

        $this->getConfiguration()->addConfigTypes($configTypeNames);

        $this->getCMDLCache()->flushAll();

        return true;
    }
559624
public function saveAction(ConfigGroup $group)
    {
        $form = $this->createConfigGroupForm($group);
        $form->bind($this->getRequest());
        $configValueManager = $this->container->get('admin.configuration.configvalue_manager');
        foreach ($form as $sub) {
            $configValue = $sub->getData();
            $configValueManager->update($configValue);
        }
        $message = $this->container->get('translator')->trans(
            'The configuration has been successfully saved.',
            array(),
            'VinceTAdminConfigurationBundle'
        );
        $this->get('session')->getFlashBag()->add('sonata_flash_success', $message);

        return $this->redirect(
            $this->generateUrl(
                'vince_t_admin_configuration_group',
                array(
                    'sname' => $group->getConfigSection()->getName(),
                    'gname' => $group->getName()
                )
            )
        );
    }
571567
public function save()
    {
        $aModule = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("aModules");

        $aModules = [];
        if ($tmp = json_decode($aModule, true)) {
            foreach ($tmp as $key => $value) {
                $sanitizedKey = str_replace(self::BACKSLASH_REPLACEMENT, "\\", $key);
                $aModules[$sanitizedKey] = $value;
            }
            $oModuleInstaller = oxNew(\OxidEsales\Eshop\Core\Module\ModuleInstaller::class);
            $aModules = $oModuleInstaller->buildModuleChains($aModules);
        }

        \OxidEsales\Eshop\Core\Registry::getConfig()->saveShopConfVar("aarr", "aModules", $aModules);
    }
204933
public function initialize(array $config)
    {
        $this->table('users');
        $this->displayField('email');
        $this->primaryKey('id');
        $this->addBehavior('Timestamp');

        $this->belongsTo('Roles', [
            'className' => 'CakeManager.Roles',
            'foreignKey' => 'role_id',
            'propertyName' => 'role',
        ]);
    }
841137
protected function addModuleSettings($moduleSettings, $moduleId)
    {
        $this->removeNotUsedSettings($moduleSettings, $moduleId);
        $config = \OxidEsales\Eshop\Core\Registry::getConfig();
        $shopId = $config->getShopId();
        $moduleConfigs = $this->getModuleConfigs($moduleId);
        $db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        if (is_array($moduleSettings)) {
            foreach ($moduleSettings as $setting) {
                $oxid = \OxidEsales\Eshop\Core\Registry::getUtilsObject()->generateUId();

                $module = $this->getModuleConfigId($moduleId);
                $name = $setting["name"];
                $type = $setting["type"];

                if ($this->isTheme($moduleId)) {
                    $value = array_key_exists($name, $moduleConfigs) ? $moduleConfigs[$name] : $setting["value"];
                } else {
                    $value = is_null($config->getConfigParam($name)) ? $setting["value"] : $config->getConfigParam($name);
                }

                $group = $setting["group"];

                $constraints = "";
                if (isset($setting["constraints"]) && $setting["constraints"]) {
                    $constraints = $setting["constraints"];
                } elseif (isset($setting["constrains"]) && $setting["constrains"]) {
                    $constraints = $setting["constrains"];
                }

                $position = 1;
                if (isset($setting["position"])) {
                    $position = $setting["position"];
                }

                $config->saveShopConfVar($type, $name, $value, $shopId, $module);

                $deleteSql = "DELETE FROM `oxconfigdisplay` WHERE OXCFGMODULE=" . $db->quote($module) . " AND OXCFGVARNAME=" . $db->quote($name);
                $insertSql = "INSERT INTO `oxconfigdisplay` (`OXID`, `OXCFGMODULE`, `OXCFGVARNAME`, `OXGROUPING`, `OXVARCONSTRAINT`, `OXPOS`) " .
                "VALUES ('{$oxid}', " . $db->quote($module) . ", " . $db->quote($name) . ", " . $db->quote($group) . ", " . $db->quote($constraints) . ", " . $db->quote($position) . ")";

                $db->execute($deleteSql);
                $db->execute($insertSql);
            }
        }
    }
127689
public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('posts');
        $this->setDisplayField('title');
        $this->setPrimaryKey('id');

        $this->belongsTo('Categories', ['className' => 'MeCms.PostsCategories'])
            ->setForeignKey('category_id')
            ->setJoinType('INNER')
            ->setTarget($this->getTableLocator()->get('MeCms.PostsCategories'))
            ->setAlias('Categories');

        $this->belongsTo('Users', ['className' => 'MeCms.Users'])
            ->setForeignKey('user_id')
            ->setJoinType('INNER');

        $this->belongsToMany('Tags', ['className' => 'MeCms.Tags', 'joinTable' => 'posts_tags'])
            ->setForeignKey('post_id')
            ->setTargetForeignKey('tag_id')
            ->setThrough('MeCms.PostsTags');

        $this->addBehavior('Timestamp');
        $this->addBehavior('CounterCache', [
            'Categories' => ['post_count'],
            'Users' => ['post_count'],
        ]);

        $this->_validatorClass = PostValidator::class;
    }
453641
protected function registerAdminConfiguration()
    {
        $configurationGroup = AdminConfigurationFacade::add('general')
            ->label('avored-framework::system.configuration.general_title');

        $configurationGroup->addConfiguration('general_site_title')
            ->label('avored-framework::system.configuration.default_site_title')
            ->type('text')
            ->name('general_site_title');

        $configurationGroup->addConfiguration('general_site_description')
            ->label('avored-framework::system.configuration.default_site_description')
            ->type('text')
            ->name('general_site_description');

        $siteCurrencyRepository = new SiteCurrencyRepository;
        $configurationGroup->addConfiguration('general_site_currency')
            ->label('avored-framework::system.configuration.default_site_currency')
            ->type('select')
            ->name('general_site_currency')
            ->options($siteCurrencyRepository);

        $configurationGroup->addConfiguration('general_administrator_email')
            ->label('avored-framework::system.configuration.administrator_email')
            ->type('text')
            ->name('general_administrator_email');

        $configurationGroup->addConfiguration('general_term_condition_page')
            ->label('avored-framework::system.configuration.term_condition_page')
            ->type('select')
            ->name('general_term_condition_page')
            ->options(
                function () {
                    $options = Page::all()->pluck('name', 'id');
                    return $options;
                }
            );

        $configurationGroup->addConfiguration('general_home_page')
            ->label('avored-framework::system.configuration.home_page')
            ->type('select')
            ->name('general_home_page')
            ->options(
                function () {
                    return Page::all()->pluck('name', 'id');
                }
            );

        $userGroup = AdminConfigurationFacade::add('users')
            ->label('avored-framework::system.configuration.user_title');

        $userGroup->addConfiguration('user_default_country')
            ->label('avored-framework::system.configuration.user_default_country')
            ->type('select')
            ->name('user_default_country')
            ->options(
                function () {
                    return Country::all()->pluck('name', 'id');
                }
            );

        $userGroup->addConfiguration('user_activation_required')
            ->label('avored-framework::system.configuration.user_activation_required')
            ->type('select')
            ->name('user_activation_required')
            ->options(
                function () {
                    return [0 => 'No', 1 => 'Yes'];
                }
            );

        $userGroup->addConfiguration('user_delete_request_days')
            ->label('avored-framework::system.configuration.user_delete_request_days')
            ->type('text')
            ->name('user_delete_request_days');

        $shippingGroup = AdminConfigurationFacade::add('shipping')
            ->label('avored-framework::system.configuration.shipping_title');

        $shippingGroup->addConfiguration('shipping_free_shipping_enabled')
            ->label('avored-framework::system.configuration.is_free_shipping_enabled')
            ->type('select')
            ->name('shipping_free_shipping_enabled')
            ->options(
                function () {
                    return [1 => 'Yes', 0 => 'No'];
                }
            );

        $paymentGroup = AdminConfigurationFacade::add('payment')
            ->label('avored-framework::system.configuration.payment_title');

        $paymentGroup->addConfiguration('payment_stripe_enabled')
            ->label('avored-framework::system.configuration.payment_stripe_enabled')
            ->type('select')
            ->name('payment_stripe_enabled')
            ->options(
                function () {
                    return [0 => 'No', 1 => 'Yes'];
                }
            );

        $paymentGroup->addConfiguration('payment_stripe_publishable_key')
            ->label('avored-framework::system.configuration.payment_stripe_publishable_key')
            ->type('text')
            ->name('payment_stripe_publishable_key');

        $paymentGroup->addConfiguration('avored_stripe_secret_key')
            ->label('avored-framework::system.configuration.payment_stripe_secret_key')
            ->type('text')
            ->name('avored_stripe_secret_key');

        $taxGroup = AdminConfigurationFacade::add('tax')
            ->label('avored-framework::system.configuration.tax_title');

        $taxGroup->addConfiguration('tax_enabled')
            ->label('avored-framework::system.configuration.is_tax_enabled')
            ->type('select')
            ->name('tax_enabled')
            ->options(
                function () {
                    return [1 => 'Yes', 0 => 'No'];
                }
            );

        $taxGroup->addConfiguration('tax_percentage')
            ->label('avored-framework::system.configuration.tax_percentage')
            ->type('text')
            ->name('tax_percentage');

        $taxGroup->addConfiguration('tax_default_country')
            ->label('avored-framework::system.configuration.tax_default_country')
            ->type('select')
            ->name('tax_default_country')
            ->options(
                function () {
                    return $options = Country::all()->pluck('name', 'id');
                }
            );
    }
414063
public function save(UserConfiguration $config)
    {
        file_put_contents($this->storagePath, Yaml::dump($config->toArray(), 3, 2));

        return $this;
    }
738756
private function SaveGroups()
    {
        $assignedIDs = $this->AssignedGroupIDs();
        $selectedIDs = Request::PostArray('Group');
        $this->ClearMembergroups($selectedIDs);
        foreach ($selectedIDs as $selectedID)
        {
            if (!in_array($selectedID, $assignedIDs))
            {
                $confirmGroup = new RegisterConfirmMembergroup();
                $confirmGroup->SetConfirm($this->confirm);
                $confirmGroup->SetMemberGroup(Membergroup::Schema()->ByID($selectedID));
                $confirmGroup->Save();
            }
        }
    }
781748
public function setConfiguration( models\Connection\Config $connectionConfig){
        $rest = $this->getService( self::API_CONNECTION_CONFIG);
        $rest->PUT( $connectionConfig);

        return $rest->getResult( models\Connection\Config::class);
    }