/**
  * {@inheritdoc}
  */
 public function isGranted($permissionCode)
 {
     if (null === $this->settings) {
         $this->settings = $this->settingsManager->load('sylius_security');
     }
     if (false === $this->settings->get('enabled')) {
         return true;
     }
     return $this->authorizationChecker->isGranted($permissionCode);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function save(SettingsInterface $settings)
 {
     /** @var SchemaInterface $schema */
     $schema = $this->schemaRegistry->get($settings->getSchemaAlias());
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     $parameters = $settingsBuilder->resolve($settings->getParameters());
     $settings->setParameters($parameters);
     $this->eventDispatcher->dispatch(SettingsEvent::PRE_SAVE, new SettingsEvent($settings));
     $this->manager->persist($settings);
     $this->manager->flush();
     $this->eventDispatcher->dispatch(SettingsEvent::POST_SAVE, new SettingsEvent($settings));
 }
 /**
  * @param SettingsInterface $settings
  *
  * @return ParameterTransformerInterface[]
  */
 protected function getTransformers(SettingsInterface $settings)
 {
     $registry = $this->container->get('sylius.registry.settings_schema');
     /** @var SchemaInterface $schema */
     $schema = $registry->get($settings->getSchemaAlias());
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     return $settingsBuilder->getTransformers();
 }
 function it_cannot_be_supported_when_the_default_tax_calculation_strategy_setting_does_not_match_the_strategy_type(SettingsInterface $settings, OrderInterface $order, ZoneInterface $zone)
 {
     $settings->get('default_tax_calculation_strategy')->willReturn('order_item_units_based');
     $this->supports($order, $zone)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function save(SettingsInterface $settings)
 {
     $schema = $this->schemaRegistry->get($settings->getSchemaAlias());
     //$schema = $this->schemaRegistry->getSchema($namespace);
     $settingsBuilder = new SettingsBuilder();
     $schema->buildSettings($settingsBuilder);
     $parameters = $settingsBuilder->resolve($settings->getParameters());
     foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) {
         if (array_key_exists($parameter, $parameters)) {
             $parameters[$parameter] = $transformer->transform($parameters[$parameter]);
         }
     }
     if (isset($this->resolvedSettings[$namespace])) {
         $this->resolvedSettings[$namespace]->setParameters($parameters);
     }
     $persistedParameters = $this->parameterRepository->findBy(array('category' => $namespace));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     $event = $this->eventDispatcher->dispatch(SettingsEvent::PRE_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     $url = $event->getArgument('url');
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             if ($value instanceof Course) {
                 $value = $value->getId();
             }
             $persistedParametersMap[$name]->setValue($value);
         } else {
             /** @var SettingsCurrent $parameter */
             $parameter = $this->parameterFactory->createNew();
             $parameter->setNamespace($namespace)->setName($name)->setValue($value)->setUrl($url)->setAccessUrl(1)->setAccessUrlLocked(0)->setAccessUrlChangeable(1);
             /* @var $errors ConstraintViolationListInterface */
             $errors = $this->validator->validate($parameter);
             if (0 < $errors->count()) {
                 throw new ValidatorException($errors->get(0)->getMessage());
             }
             $this->parameterManager->persist($parameter);
         }
     }
     $this->parameterManager->flush();
     $this->eventDispatcher->dispatch(SettingsEvent::POST_SAVE, new SettingsEvent($namespace, $settings, $parameters));
     $this->cache->save($namespace, $parameters);
 }
 /**
  * {@inheritdoc}
  */
 public function supports(OrderInterface $order, ZoneInterface $zone)
 {
     return $this->settings->get('default_tax_calculation_strategy') === $this->type;
 }
 /**
  * {@inheritdoc}
  */
 public function getZone()
 {
     return $this->settings->get('default_tax_zone');
 }