/**
  * {@inheritdoc}
  */
 public function getZone()
 {
     if ($this->settings->has('default_tax_zone')) {
         return $this->settings->get('default_tax_zone');
     }
     return null;
 }
 /**
  * {@inheritdoc}
  */
 public function isGranted($permissionCode)
 {
     if (null === $this->settings) {
         $this->settings = $this->settingsManager->loadSettings('sylius_security');
     }
     if (false === $this->settings->get('enabled')) {
         return true;
     }
     return $this->authorizationChecker->isGranted($permissionCode);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function applyTaxes(OrderInterface $order)
 {
     // Remove all tax adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
     if ($order->getItems()->isEmpty()) {
         return;
     }
     $zone = null;
     if (null !== $order->getShippingAddress()) {
         // Match the tax zone.
         $zone = $this->zoneMatcher->match($order->getShippingAddress());
     }
     if ($this->settings->has('default_tax_zone')) {
         // If address does not match any zone, use the default one.
         $zone = $zone ?: $this->settings->get('default_tax_zone');
     }
     if (null === $zone) {
         return;
     }
     $taxes = $this->processTaxes($order, $zone);
     $this->addAdjustments($taxes, $order);
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function saveSettings($namespace, Settings $settings)
 {
     $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, 'cId' => $this->getCourse()->getId()));
     $persistedParametersMap = array();
     foreach ($persistedParameters as $parameter) {
         $persistedParametersMap[$parameter->getName()] = $parameter;
     }
     foreach ($parameters as $name => $value) {
         if (isset($persistedParametersMap[$name])) {
             $persistedParametersMap[$name]->setValue($value);
         } else {
             /** @var CCourseSetting $parameter */
             //$parameter = $this->parameterFactory->createNew();
             $parameter = new CCourseSetting();
             $parameter->setNamespace($namespace)->setName($name)->setValue($value)->setCId($this->getCourse()->getId());
             /* @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->cache->save($namespace, $parameters);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  * @throws ValidatorException
  */
 public function saveSettings($namespace, Settings $settings)
 {
     $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])) {
             $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);
 }