public function getTheme(\Shopware\Models\Shop\Template $template) { if ($template->getParent() === null) { return $this->getBareTheme(); } else { return $this->getResponsiveTheme(); } }
/** * sets the theme settings for a specific theme * @param Template $theme * @param Shop $shop * @param array $settings key value array containing the settings */ public function setThemeSettingsArray(Template $theme, Shop $shop, array $settings) { $elements = $theme->getElements(); $elements = $this->buildKeyValueSettings($elements); foreach ($settings as $key => $value) { if (!isset($elements[$key])) { continue; } $element = $elements[$key]; $valueEntity = $this->getValueForShop($element, $shop); $valueEntity->setValue($value); } $this->em->flush(); }
/** * Saves the passed shop configuration values to the passed * template. * The configuration elements are identified over the * element name. * The values array can contains multiple sub shop values, * which identified over the shopId parameter inside the values array. * * @param Shop\Template $template * @param array $values */ public function saveConfig(Shop\Template $template, array $values) { foreach ($values as $data) { //get the element over the name $element = $this->getElementByName($template->getElements(), $data['elementName']); if (!$element instanceof Shop\TemplateConfig\Element) { continue; } $value = $this->getElementShopValue($element->getValues(), $data['shopId']); /**@var $shop Shop\Shop */ $shop = $this->entityManager->getReference('Shopware\\Models\\Shop\\Shop', $data['shopId']); if ($element->getType() === 'theme-media-selection') { $data['value'] = $this->mediaService->normalize($data['value']); } $value->setShop($shop); $value->setElement($element); $value->setValue($data['value']); } $this->entityManager->flush(); }
/** * Helper function which creates an array with all shop templates * inside which should be included in the frontend inheritance. * * @param Shop\Template $template * @return array */ private function buildInheritanceRecursive(Shop\Template $template) { $hierarchy = array($template); if ($template->getParent() instanceof Shop\Template) { $hierarchy = array_merge($hierarchy, $this->buildInheritanceRecursive($template->getParent())); } return $hierarchy; }
/** * Returns the template directory of the passed shop template. * To get this use the getDirectory function. * * @param Shop\Template $template * @return string */ private function getTemplateDirectory(Shop\Template $template) { return $this->templateManager->resolveTemplateDir($template->getTemplate()); }
/** * @param Form\Interfaces\Field $field * @param Template $template * @param TemplateConfig\Layout $parent */ private function saveField(Form\Interfaces\Field $field, Template $template, TemplateConfig\Layout $parent) { /**@var $field Form\Field */ $lessCompatible = true; if (array_key_exists('lessCompatible', $field->getAttributes())) { $attributes = $field->getAttributes(); $lessCompatible = (bool) $attributes['lessCompatible']; } $data = array('attributes' => $field->getAttributes(), 'fieldLabel' => $field->getLabel(), 'name' => $field->getName(), 'defaultValue' => $field->getDefaultValue(), 'supportText' => $field->getHelp(), 'allowBlank' => !$field->isRequired(), 'lessCompatible' => $lessCompatible); $class = get_class($field); switch ($class) { case "Shopware\\Components\\Form\\Field\\Text": /**@var $field Form\Field\Text */ $data += array('type' => 'theme-text-field'); break; case "Shopware\\Components\\Form\\Field\\Boolean": /**@var $field Form\Field\Boolean */ $data += array('type' => 'theme-checkbox-field'); break; case "Shopware\\Components\\Form\\Field\\Date": /**@var $field Form\Field\Date */ $data += array('type' => 'theme-date-field'); break; case "Shopware\\Components\\Form\\Field\\Color": /**@var $field Form\Field\Color */ $data += array('type' => 'theme-color-picker'); break; case "Shopware\\Components\\Form\\Field\\Media": /**@var $field Form\Field\Media */ $data += array('type' => 'theme-media-selection'); break; case "Shopware\\Components\\Form\\Field\\Number": /**@var $field Form\Field\Number */ $data += array('type' => 'numberfield'); break; case "Shopware\\Components\\Form\\Field\\Em": /**@var $field Form\Field\Number */ $data += array('type' => 'theme-em-field'); break; case "Shopware\\Components\\Form\\Field\\Percent": /**@var $field Form\Field\Number */ $data += array('type' => 'theme-percent-field'); break; case "Shopware\\Components\\Form\\Field\\Pixel": /**@var $field Form\Field\Number */ $data += array('type' => 'theme-pixel-field'); break; case "Shopware\\Components\\Form\\Field\\TextArea": /**@var $field Form\Field\Number */ $data += array('type' => 'theme-text-area-field'); break; case "Shopware\\Components\\Form\\Field\\Selection": /**@var $field Form\Field\Selection */ $data += array('type' => 'theme-select-field', 'selection' => $field->getStore()); break; } $entity = $this->checkExistingElement($template->getElements(), $field->getName()); $entity->fromArray($data); $entity->setTemplate($template); $entity->setContainer($parent); $this->entityManager->persist($entity); }
/** * {@inheritDoc} */ public function setManyToOne($data, $model, $property) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManyToOne', array($data, $model, $property)); return parent::setManyToOne($data, $model, $property); }
/** * Returns all config elements of the passed template. * * @param \Shopware\Models\Shop\Template $template * @return ArrayCollection */ private function getElements(Shop\Template $template) { $builder = $this->entityManager->createQueryBuilder(); $builder->select('elements')->from('Shopware\\Models\\Shop\\TemplateConfig\\Element', 'elements')->where('elements.templateId = :templateId')->setParameter('templateId', $template->getId()); $elements = $builder->getQuery()->getResult(); $elements = $this->eventManager->filter('Theme_Configurator_Elements_Loaded', $elements, array('template' => $template)); return new ArrayCollection($elements); }
/** * Generates the Theme.php file for the theme. * * @param array $data * @param Template $parent */ private function generateThemePhp(array $data, Template $parent = null) { $source = str_replace('$TEMPLATE$', $data['template'], $this->phpSource); if ($parent instanceof Template) { $source = str_replace('$PARENT$', $parent->getTemplate(), $source); } else { $source = str_replace('$PARENT$', 'null', $source); } $source = $this->replacePlaceholder('name', $data['name'], $source); $source = $this->replacePlaceholder('author', $data['author'], $source); $source = $this->replacePlaceholder('license', $data['license'], $source); $source = $this->replacePlaceholder('description', $data['description'], $source); $output = new \SplFileObject($this->getThemeDirectory($data['template']) . DIRECTORY_SEPARATOR . 'Theme.php', "w+"); $source = $this->eventManager->filter('Theme_Generator_Theme_Source_Generated', $source, array('data' => $data, 'parent' => $parent)); $output->fwrite($source); }
/** * Helper function which iterates the engine\Shopware\Themes directory * and registers all stored themes within the directory as \Shopware\Models\Shop\Template. * * @param \DirectoryIterator $directories * @param \Shopware\Models\Plugin\Plugin $plugin * @return Theme[] */ private function synchronizeThemeDirectories(\DirectoryIterator $directories, Plugin $plugin = null) { $themes = array(); $settings = $this->service->getSystemConfiguration(AbstractQuery::HYDRATE_OBJECT); /**@var $directory \DirectoryIterator */ foreach ($directories as $directory) { //check valid directory if ($directory->isDot() || !$directory->isDir() || $directory->getFilename() == '_cache') { continue; } try { $theme = $this->util->getThemeByDirectory($directory); } catch (\Exception $e) { continue; } $data = $this->getThemeDefinition($theme); $template = $this->repository->findOneBy(array('template' => $theme->getTemplate())); if (!$template instanceof Shop\Template) { $template = new Shop\Template(); if ($plugin) { $template->setPlugin($plugin); } $this->entityManager->persist($template); } $template->fromArray($data); if (!$template->getId() || $settings->getReloadSnippets()) { $this->synchronizeSnippets($template); } $this->entityManager->flush($template); $themes[] = $theme; } return $themes; }
/** * Returns the snippet namespace for the passed theme. * * @param Shop\Template $template * @return string */ public function getSnippetNamespace(Shop\Template $template) { return 'themes/' . strtolower($template->getTemplate()) . '/'; }