Example #1
0
 /**
  * Parses current .ini snippet files and generates the matching MySQL queries
  *
  * @param string  $snippetsDir
  * @param bool $update if false, UPDATE IGNORE statements are generated. Default true, generates UPDATE .. ON DUPLICATE KEY statements
  * @return array The array containing the generated queries.
  */
 public function loadToQuery($snippetsDir = null, $update = true)
 {
     $snippetsDir = $snippetsDir ?: $this->snippetsDir;
     if (!file_exists($snippetsDir)) {
         return array();
     }
     $locales = array();
     $finder = new Finder();
     $inputAdapter = new \Enlight_Config_Adapter_File(array('configDir' => $snippetsDir));
     $queryWriter = new QueryWriter();
     $finder->files()->in($snippetsDir);
     foreach ($finder as $file) {
         $filePath = $file->getRelativePathname();
         if (strpos($filePath, '.ini') == strlen($filePath) - 4) {
             $namespace = substr($filePath, 0, -4);
         } else {
             continue;
         }
         $namespaceData = new \Enlight_Components_Snippet_Namespace(array('adapter' => $inputAdapter, 'name' => $namespace));
         foreach ($namespaceData->read()->toArray() as $index => $values) {
             if (!array_key_exists($index, $locales)) {
                 $locales[$index] = 'SET @locale_' . $index . ' = (SELECT id FROM s_core_locales WHERE locale = \'' . $index . '\');';
             }
             $queryWriter->setUpdate($update);
             $queryWriter->write($values, $namespace, '@locale_' . $index, 1);
         }
     }
     $result = $queryWriter->getQueries();
     foreach ($locales as $locale) {
         array_unshift($result, $locale);
     }
     return $result;
 }
 public function filter($value)
 {
     $ret = $this->namespace->get($value);
     if (!$ret) {
         return $value;
     }
     return $ret;
 }
 /**
  * @param array $requirement
  * @return array
  */
 public function check($requirement)
 {
     $templates = $this->getActiveEmotionTemplates();
     if (empty($templates)) {
         return ['type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => $this->namespace->get('controller/check_emotiontemplate_success')];
     }
     $names = array_column($templates, 'templateName');
     return ['type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($this->namespace->get('check_emotiontemplate_failure'), implode(',', $names))];
 }
 /**
  * {@inheritdoc}
  */
 public function check($requirement)
 {
     $requiredExtension = $requirement['value'];
     $successMessage = $this->namespace->get('controller/check_phpextension_success');
     $failMessage = $this->namespace->get('controller/check_phpextension_failure');
     if (extension_loaded($requiredExtension)) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => sprintf($successMessage, $requiredExtension));
     } else {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($failMessage, $requiredExtension));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function filter($value)
 {
     if (!$value instanceof AbstractSortDefinition) {
         throw new \InvalidArgumentException('Unable to generate translation $value of wrong type');
     }
     $ret = $this->snippetNamespace->get($this->getSanitizedValue($value->getUniqueIdentifier()));
     if (!$ret) {
         return $value;
     }
     return $ret;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function check($requirement)
 {
     $minPHPVersion = $requirement['value'];
     $validVersion = version_compare(PHP_VERSION, $minPHPVersion) >= 0;
     $successMessage = $this->namespace->get('controller/check_phpversion_success', "Min PHP Version: %s, your version %s");
     $failMessage = $this->namespace->get('controller/check_phpversion_failure', "Min PHP Version: %s, your version %s");
     if ($validVersion) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => sprintf($successMessage, $minPHPVersion, PHP_VERSION));
     } else {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($failMessage, $minPHPVersion, PHP_VERSION));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function check($requirement)
 {
     $conn = Shopware()->Container()->get('dbal_connection');
     $version = $conn->fetchColumn("SELECT VERSION()");
     $minMySQLVersion = $requirement['value'];
     $validVersion = version_compare($version, $minMySQLVersion) >= 0;
     $successMessage = $this->namespace->get('controller/check_mysqlversion_success', "Min MySQL Version: %s, your version %s");
     $failMessage = $this->namespace->get('controller/check_mysqlversion_failure', "Min MySQL Version %s, your version %s");
     if ($validVersion) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => sprintf($successMessage, $minMySQLVersion, $version));
     } else {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($failMessage, $minMySQLVersion, $version));
     }
 }
 /**
  * @param FacetInterface|Facet\PriceFacet $facet
  * @param Criteria $criteria
  * @param ShopContextInterface $context
  * @return RangeFacetResult
  */
 public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context)
 {
     $queryCriteria = clone $criteria;
     $queryCriteria->resetConditions();
     $queryCriteria->resetSorting();
     $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context);
     $query->resetQueryPart('orderBy');
     $query->resetQueryPart('groupBy');
     $selection = $this->priceHelper->getSelection($context);
     $this->priceHelper->joinPrices($query, $context);
     $query->select('MIN(' . $selection . ') as cheapest_price');
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $min = $statement->fetch(\PDO::FETCH_COLUMN);
     $query->groupBy('product.id')->orderBy('cheapest_price', 'DESC')->setFirstResult(0)->setMaxResults(1);
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $max = $statement->fetch(\PDO::FETCH_COLUMN);
     $activeMin = $min;
     $activeMax = $max;
     /**@var $condition PriceCondition */
     if ($condition = $criteria->getCondition($facet->getName())) {
         $activeMin = $condition->getMinPrice();
         $activeMax = $condition->getMaxPrice();
     }
     return new RangeFacetResult($facet->getName(), $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Price'), (double) $min, (double) $max, (double) $activeMin, (double) $activeMax, $this->minFieldName, $this->maxFieldName, [], 'frontend/listing/filter/facet-currency-range.tpl');
 }
Example #9
0
 /**
  * Internal helper function for the automatic mapping
  *
  * @param $sourceArray
  * @param $targetArray
  * @return mixed
  */
 private function mapArrays($sourceArray, $targetArray)
 {
     foreach ($sourceArray as &$source) {
         $source = ["value" => $source, "mapping" => '', "mapping_value" => ''];
         foreach ($targetArray as $key => $target) {
             if (is_array($target)) {
                 foreach ($target as $alias) {
                     if (strtolower($source["value"]) == strtolower($alias) || strtolower(substr($source["value"], 0, 6)) == strtolower(substr($alias, 0, 6))) {
                         $source["mapping"] = $target[0];
                         $source["mapping_value"] = $key;
                         break;
                     }
                 }
             } else {
                 if (strtolower($source["value"]) == strtolower($target) || strtolower(substr($source["value"], 0, 6)) == strtolower(substr($target, 0, 6))) {
                     $source["mapping"] = $target;
                     $source["mapping_value"] = $key;
                     break;
                 }
             }
         }
         if ($source['mapping'] === '' && $source['mapping_value'] === '') {
             $source["mapping"] = $this->namespace->get('pleaseSelect', 'Please select');
             $source["mapping_value"] = $this->namespace->get('pleaseSelect', 'Please select');
         }
     }
     return $sourceArray;
 }
 /**
  * Generates the facet data for the passed query, criteria and context object.
  *
  * @param FacetInterface|VoteAverageFacet $facet
  * @param Criteria $criteria
  * @param Struct\ShopContextInterface $context
  * @return \Shopware\Bundle\SearchBundle\FacetResult\RadioFacetResult|null
  */
 public function generateFacet(FacetInterface $facet, Criteria $criteria, Struct\ShopContextInterface $context)
 {
     $queryCriteria = clone $criteria;
     $queryCriteria->resetConditions();
     $queryCriteria->resetSorting();
     $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context);
     $query->resetQueryPart('orderBy');
     $query->resetQueryPart('groupBy');
     if (!$query->hasState(VoteAverageCondition::STATE_INCLUDES_VOTE_TABLE)) {
         $query->innerJoin('product', 's_articles_vote', 'vote', 'vote.articleID = product.id');
     }
     $query->select('COUNT(vote.id) as hasVotes');
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetch(\PDO::FETCH_COLUMN);
     if (!$data) {
         return null;
     }
     $activeAverage = null;
     if ($criteria->hasCondition($facet->getName())) {
         /**@var $condition VoteAverageCondition*/
         $condition = $criteria->getCondition($facet->getName());
         $activeAverage = $condition->getAverage();
     }
     $values = [new ValueListItem(1, '', $activeAverage == 1), new ValueListItem(2, '', $activeAverage == 2), new ValueListItem(3, '', $activeAverage == 3), new ValueListItem(4, '', $activeAverage == 4), new ValueListItem(5, '', $activeAverage == 5)];
     return new RadioFacetResult($facet->getName(), $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Ranking'), $values, $this->fieldName, [], 'frontend/listing/filter/facet-rating.tpl');
 }
Example #11
0
 /**
  * Helper to assure that everything is alright.
  *
  * @return bool
  */
 private function defaultCheck()
 {
     if (!$this->Request()->isPost()) {
         $this->View()->assign(array('success' => false, 'errorMsg' => $this->namespace->get('wrong_transmit_method', 'Wrong transmit method.')));
         return false;
     }
     return true;
 }
 /**
  * @param array $requirement
  * @return array
  */
 public function check($requirement)
 {
     $requiredVersion = $requirement['value'];
     if (!extension_loaded('ionCube Loader')) {
         return null;
     }
     if (!function_exists('ioncube_loader_version')) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($this->namespace->get('controller/check_ioncubeloaderversion_unknown'), $requiredVersion));
     }
     $installedVersion = ioncube_loader_version();
     $isValid = version_compare(strtolower($installedVersion), $requiredVersion, '>');
     if ($isValid) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => sprintf($this->namespace->get('controller/check_ioncubeloaderversion_success'), $requiredVersion, $installedVersion));
     } else {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($this->namespace->get('check_ioncubeloaderversion_failure'), $requiredVersion, $installedVersion));
     }
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function check($requirement)
 {
     $directories = array();
     $checkedDirectories = array();
     $successMessage = $this->namespace->get('controller/check_writable_success', "The following directories are writeable <br/>%s");
     $failMessage = $this->namespace->get('controller/check_writable_failure', "The following directories are not writable: <br> %s");
     foreach ($requirement['value'] as $path) {
         $fullPath = rtrim(Shopware()->DocPath($path), '/');
         $checkedDirectories[] = $fullPath;
         $fixPermissions = true;
         $directories = array_merge($directories, $this->fileSystem->checkDirectoryPermissions($fullPath, $fixPermissions));
     }
     if (empty($directories)) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => sprintf($successMessage, implode('<br>', $checkedDirectories)));
     } else {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => sprintf($failMessage, implode('<br>', $directories)));
     }
 }
 /**
  * @param Category[] $categories
  * @param Facet\CategoryFacet $facet
  * @param int[] $active
  * @return TreeFacetResult
  */
 private function createTreeFacet($categories, $facet, $active)
 {
     $items = $this->getCategoriesOfParent($categories, null);
     if (!$items) {
         return null;
     }
     $values = [];
     foreach ($items as $item) {
         $values[] = $this->createTreeItem($categories, $item, $active);
     }
     return new TreeFacetResult($facet->getName(), $this->fieldName, empty($active), $this->snippetNamespace->get($facet->getName(), 'Categories'), $values, [], null);
 }
 /**
  * @param Manufacturer[] $manufacturers
  * @param int[] $activeIds
  * @return ValueListFacetResult
  */
 private function createFacetResult($manufacturers, $activeIds)
 {
     $listItems = [];
     foreach ($manufacturers as $manufacturer) {
         $listItem = new ValueListItem($manufacturer->getId(), $manufacturer->getName(), in_array($manufacturer->getId(), $activeIds));
         $listItems[] = $listItem;
     }
     usort($listItems, function (ValueListItem $a, ValueListItem $b) {
         return strcasecmp($a->getLabel(), $b->getLabel());
     });
     return new ValueListFacetResult('manufacturer', !empty($activeIds), $this->snippetNamespace->get('manufacturer', 'Manufacturer'), $listItems, $this->fieldName);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function check($requirement)
 {
     $licenseKeys = $requirement['value']['licenseKeys'];
     if (empty($licenseKeys)) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_WARNING, 'message' => 'License check requested but no license key provided');
     }
     $licenseData = $this->getLicenseData($licenseKeys);
     if (empty($licenseData)) {
         return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => $this->namespace->get('controller/check_license_nolicense'));
     }
     $url = $this->endpoint . '/licenseupgrades/permission';
     $client = new \Zend_Http_Client($url, array('timeout' => 15));
     foreach ($licenseData as $licenseDatum) {
         $client->setParameterPost('domain', $licenseDatum['host']);
         $client->setParameterPost('licenseKey', $licenseDatum['license']);
         $client->setParameterPost('version', $this->shopwareVersion);
         try {
             $response = $client->request(\Zend_Http_Client::POST);
         } catch (\Zend_Http_Client_Exception $e) {
             // Do not show exception to user if request times out
             return null;
         }
         try {
             $body = $response->getBody();
             if ($body != '') {
                 $json = \Zend_Json::decode($body, true);
             } else {
                 $json = null;
             }
         } catch (\Exception $e) {
             // Do not show exception to user if SBP returns an error
             return null;
         }
         if ($json === true) {
             return array('type' => self::CHECK_TYPE, 'errorLevel' => Validation::REQUIREMENT_VALID, 'message' => $this->namespace->get('controller/check_license_success'));
         }
     }
     return array('type' => self::CHECK_TYPE, 'errorLevel' => $requirement['level'], 'message' => $this->namespace->get('controller/check_license_failure'));
 }
 /**
  * Generates the facet data for the passed query, criteria and context object.
  *
  * @param FacetInterface|Facet\ShippingFreeFacet $facet
  * @param Criteria $criteria
  * @param ShopContextInterface $context
  * @return BooleanFacetResult
  */
 public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context)
 {
     $queryCriteria = clone $criteria;
     $queryCriteria->resetConditions();
     $queryCriteria->resetSorting();
     $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context);
     $query->resetQueryPart('orderBy');
     $query->resetQueryPart('groupBy');
     $query->select('product.id')->andWhere('variant.shippingfree = 1')->setMaxResults(1);
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $total = $statement->fetch(\PDO::FETCH_COLUMN);
     if ($total <= 0) {
         return null;
     }
     return new BooleanFacetResult($facet->getName(), $this->fieldName, $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Shipping free'));
 }
 /**
  * Generates the facet data for the passed query, criteria and context object.
  *
  * @param FacetInterface|Facet\ShippingFreeFacet $facet
  * @param Criteria $criteria
  * @param ShopContextInterface $context
  * @return BooleanFacetResult
  */
 public function generateFacet(FacetInterface $facet, Criteria $criteria, ShopContextInterface $context)
 {
     $queryCriteria = clone $criteria;
     $queryCriteria->resetConditions();
     $queryCriteria->resetSorting();
     $query = $this->queryBuilderFactory->createQuery($queryCriteria, $context);
     $query->resetQueryPart('orderBy');
     $query->resetQueryPart('groupBy');
     if (!$query->hasState(ImmediateDeliveryConditionHandler::STATE_INCLUDES_ALL_VARIANTS)) {
         $query->innerJoin('product', 's_articles_details', 'allVariants', 'allVariants.articleID = product.id
              AND allVariants.active = 1
              AND allVariants.instock >= allVariants.minpurchase');
         $query->addState(ImmediateDeliveryConditionHandler::STATE_INCLUDES_ALL_VARIANTS);
     }
     $query->select('product.id')->setMaxResults(1);
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $total = $statement->fetch(\PDO::FETCH_COLUMN);
     if ($total <= 0) {
         return null;
     }
     return new BooleanFacetResult($facet->getName(), $this->fieldName, $criteria->hasCondition($facet->getName()), $this->snippetNamespace->get($facet->getName(), 'Immediate delivery'));
 }
Example #19
0
 /**
  * Helper function to check, convert and load the translation for
  * the passed value.
  *
  * @param $snippet
  * @param \Enlight_Components_Snippet_Namespace $namespace
  * @return mixed
  */
 private function convertSnippet($snippet, \Enlight_Components_Snippet_Namespace $namespace)
 {
     if (!$this->isSnippet($snippet)) {
         return $snippet;
     }
     return $namespace->get($this->getSnippetName($snippet), $snippet);
 }
Example #20
0
 /**
  * Test case
  */
 public function testAllowModifications()
 {
     $namespace = new Enlight_Components_Snippet_Namespace(array('name' => 'test'));
     $this->assertFalse($namespace->readOnly());
 }
 /**
  * Loads all snippets from all files in $snippetsDir
  * (including subfolders) and removes them from the database.
  *
  * @param null $snippetsDir
  * @param boolean $removeDirty
  */
 public function removeFromDatabase($snippetsDir = null, $removeDirty = false)
 {
     $snippetsDir = $snippetsDir ?: $this->kernelRoot . '/snippets/';
     if (!file_exists($snippetsDir)) {
         return;
     }
     $localeRepository = $this->em->getRepository('Shopware\\Models\\Shop\\Locale');
     $inputAdapter = new \Enlight_Config_Adapter_File(array('configDir' => $snippetsDir));
     $outputAdapter = new \Enlight_Config_Adapter_DbTable(array('db' => $this->db, 'table' => 's_core_snippets', 'namespaceColumn' => 'namespace', 'sectionColumn' => array('shopID', 'localeID')));
     $finder = new Finder();
     $finder->files()->in($snippetsDir);
     $defaultLocale = $localeRepository->findOneBy(array('locale' => 'en_GB'));
     foreach ($finder as $file) {
         $filePath = $file->getRelativePathname();
         if (strpos($filePath, '.ini') == strlen($filePath) - 4) {
             $namespace = substr($filePath, 0, -4);
         } else {
             continue;
         }
         if ($this->output) {
             $this->output->writeln('<info>Processing ' . $namespace . ' namespace</info>');
         }
         $namespaceData = new \Enlight_Components_Snippet_Namespace(array('adapter' => $inputAdapter, 'name' => $namespace));
         foreach ($namespaceData->read()->toArray() as $index => $values) {
             if ($index == 'default') {
                 $locale = $defaultLocale;
             } else {
                 $locale = $localeRepository->findOneBy(array('locale' => $index));
             }
             $namespaceData->setSection(array(1, $locale->getId()))->read();
             $namespaceData->setData($values);
             $outputAdapter->delete($namespaceData, array_keys($values), $removeDirty);
             if ($this->output) {
                 $this->output->writeln('<info>Deleted ' . count($values) . ' snippets from ' . $locale->getLocale() . '</info>');
             }
         }
         if ($this->output) {
             $this->output->writeln('<info></info>');
         }
     }
 }