private function getDummyTemplates()
 {
     $master = new \Shopware\Models\Shop\Template();
     $master->setName('TestBare');
     $master->setTemplate('TestBare');
     $master->setVersion(3);
     $slave = new \Shopware\Models\Shop\Template();
     $slave->setName('TestResponsive');
     $slave->setTemplate('TestResponsive');
     $slave->setParent($master);
     $slave->setVersion(3);
     return $slave;
 }
Example #2
0
    /**
     * Updates the template list
     *
     * @param $templateDir
     */
    protected function refreshTemplateList($templateDir)
    {
        $repository = $this->getRepository('template');
        $templates = $repository->findAll();

        $templateList = array();
        foreach ($templates as $template) {
            $templateList[$template->getTemplate()] = $template;
        }

        $dirs = new DirectoryIterator($templateDir);
        foreach ($dirs as $dirInfo) {
            if ($dirInfo->isDot() || !$dirInfo->isDir()) {
                continue;
            }
            $dirName = $dirInfo->getFilename();
            if (in_array($dirName, array('.svn'))
                || is_numeric($dirName)
                || strpos($dirName, '_') === 0
            ) {
                continue;
            }

            $templateData = array();
            $templateFile = $dirInfo->getPathname() . '/info.json';
            if (file_exists($templateFile)) {
                $templateData = (array)Zend_Json::decode(file_get_contents($templateFile));
            }
            if(!isset($templateData['version'])) {
                $templateData['version'] = strpos($dirName, 'emotion_') !== 0 ? 1 : 2;
            }
            if (isset($templateList[$dirName])) {
                $template = $templateList[$dirName];
            } else {
                $template = new Shopware\Models\Shop\Template();
                $templateData['template'] = $dirName;
                if (empty($templateData['name'])) {
                    $templateData['name'] = ucwords(str_replace('_', ' ', $dirName));
                }
            }
            $template->fromArray($templateData);

            Shopware()->Models()->persist($template);
        }
        Shopware()->Models()->flush();
    }
Example #3
0
 /**
  * Create a new template
  *
  * @param   array|string $options
  * @return  \Shopware\Models\Shop\Template
  */
 public function createTemplate($options)
 {
     if(is_string($options)) {
         $options = array('template' => $options);
     }
     $template = $this->Payments()->findOneBy(array(
         'template' => $options['template']
     ));
     if($template === null) {
         $template = new \Shopware\Models\Shop\Template();
         if(!isset($options['name'])) {
             $options['name'] = ucfirst($options['template']);
         }
     }
     $template->fromArray($options);
     $plugin = $this->Plugin();
     $plugin->getTemplates()->add($template);
     $template->setPlugin($plugin);
     return $template;
 }
Example #4
0
 public function testSynchronizeSetsAdd()
 {
     $template = new \Shopware\Models\Shop\Template();
     $theme = $this->getResponsiveTheme();
     $entityManager = $this->getEntityManager();
     $entityManager->expects($this->once())->method('flush');
     $configurator = $this->getMockBuilder('Shopware\\Components\\Theme\\Configurator')->setConstructorArgs(array($entityManager, $this->getUtilClass(), $this->getFormPersister(), $this->getEventManager()))->getMock();
     $this->invokeMethod($configurator, 'synchronizeSets', array($theme, $template));
     $this->assertCount(2, $template->getConfigSets());
     $set = $template->getConfigSets()->get(0);
     $this->assertEquals('set1', $set->getName());
     $set = $template->getConfigSets()->get(1);
     $this->assertEquals('set2', $set->getName());
 }