Пример #1
0
 /**
  * @param array $basket
  * @return int
  */
 private function getMaxDeliveryTime($basket)
 {
     // get the SwagTrustedShop config
     $config = $this->tsConfig->getSettings($this->shop->getId());
     $deliveryTime = $config['trustedShopsInStockDeliveryTime'];
     $notInStockDeliveryTime = $config['trustedShopsNotInStockDeliveryTime'];
     // if trustedShopsNotInStockDeliveryTime is defined check if any
     // article is not in stock
     if ($notInStockDeliveryTime > 0) {
         if ($this->isArticleNotInStock($basket)) {
             return $notInStockDeliveryTime;
         }
     }
     // if trustedShopsInStockDeliveryTime is defined return it
     if ($deliveryTime > 0) {
         return $deliveryTime;
     }
     $defaultReturn = 2;
     if (!$basket) {
         return $defaultReturn;
     }
     $shippingTimes = array_column($basket, 'shippingtime');
     if (!$shippingTimes) {
         return $defaultReturn;
     }
     $maxDeliveryTime = (int) max($shippingTimes);
     if (!$maxDeliveryTime) {
         return $defaultReturn;
     }
     return $maxDeliveryTime;
 }
 /**
  * @param Shop $shop
  * @param Configuration $configuration
  * @return string
  * @throws \Exception
  */
 private function dumpConfiguration(Shop $shop, Configuration $configuration)
 {
     $pathResolver = $this->container->get('theme_path_resolver');
     $file = $pathResolver->getCacheDirectory() . '/config_' . $shop->getId() . '.json';
     file_put_contents($file, json_encode($configuration, JSON_PRETTY_PRINT));
     return $file;
 }
Пример #3
0
 /**
  * Converts a shop doctrine model to a shop struct
  * @param \Shopware\Models\Shop\Shop $shop
  * @return Struct\Shop
  */
 public function convertShop(Models\Shop\Shop $shop)
 {
     $struct = new Struct\Shop();
     $struct->setId($shop->getId());
     $struct->setName($shop->getName());
     $struct->setHost($shop->getHost());
     $struct->setPath($shop->getBasePath());
     $struct->setUrl($shop->getBaseUrl());
     $struct->setSecure($shop->getSecure());
     $struct->setSecureHost($shop->getSecureHost());
     $struct->setSecurePath($struct->getSecurePath());
     if ($shop->getCategory()) {
         $struct->setCategory($this->convertCategory($shop->getCategory()));
     }
     return $struct;
 }
Пример #4
0
 /**
  * This function reads out the nested configuration layout
  * and translate the element and container snippets.
  * If a shop instance passed, the function selects additionally the
  * element values of the passed shop.
  *
  * @param Shop\Template $template
  * @param Shop\Shop $shop
  * @param null $parentId
  * @return array
  */
 protected function buildConfigLayout(Shop\Template $template, Shop\Shop $shop = null, $parentId = null)
 {
     $builder = $this->entityManager->createQueryBuilder();
     $builder->select(array('layout', 'elements'))->from('Shopware\\Models\\Shop\\TemplateConfig\\Layout', 'layout')->leftJoin('layout.elements', 'elements')->where('layout.templateId = :templateId')->orderBy('elements.id')->setParameter('templateId', $template->getId());
     if ($shop instanceof Shop\Shop) {
         $builder->addSelect('values')->leftJoin('elements.values', 'values', 'WITH', 'values.shopId = :shopId')->setParameter('shopId', $shop->getId());
     }
     if ($parentId == null) {
         $builder->andWhere('layout.parentId IS NULL');
     } else {
         $builder->andWhere('layout.parentId = :parentId')->setParameter('parentId', $parentId);
     }
     $layout = $builder->getQuery()->getArrayResult();
     foreach ($layout as &$container) {
         $container['children'] = $this->buildConfigLayout($template, $shop, $container['id']);
     }
     return $layout;
 }
Пример #5
0
 /**
  * Helper function which returns the theme configuration as
  * key - value array.
  *
  * The element name is used as array key, the shop config
  * as value. If no shop config saved, the value will fallback to
  * the default value.
  *
  * @param \Shopware\Models\Shop\Template $template
  * @param \Shopware\Models\Shop\Shop $shop
  * @param bool $lessCompatible
  * @return array
  */
 private function getShopConfig(Shop\Template $template, Shop\Shop $shop, $lessCompatible = true)
 {
     $builder = $this->getShopConfigQuery($template, $lessCompatible);
     $builder->setParameter('templateId', $template->getId())->setParameter('shopId', $shop->getMain() ? $shop->getMain()->getId() : $shop->getId());
     $data = $builder->getQuery()->getArrayResult();
     foreach ($data as &$row) {
         if (!isset($row['value'])) {
             $row['value'] = $row['defaultValue'];
         }
         if ($lessCompatible && $row['type'] === 'theme-media-selection') {
             $row['value'] = '"' . $row['value'] . '"';
         }
         if ($row['type'] === 'theme-media-selection' && $row['value'] !== $row['defaultValue'] && strpos($row['value'], "media/") !== false) {
             $row['value'] = $this->mediaService->getUrl($row['value']);
         }
     }
     if (!is_array($data) || empty($data)) {
         return array();
     }
     //creates a key value array for the configuration.
     return array_combine(array_column($data, 'name'), array_column($data, 'value'));
 }
Пример #6
0
 /**
  * @param ShopwareShop $shop
  * @param ShopwareConfig $config
  * @return Context
  */
 public static function createFromShop(ShopwareShop $shop, ShopwareConfig $config)
 {
     $self = new self($shop->getHost(), $shop->getBaseUrl(), $shop->getAlwaysSecure() || $shop->getSecure(), []);
     $self->setShopId($shop->getId());
     $self->setUrlToLower($config->get('routerToLower'));
     $self->setBaseFile($config->get('baseFile'));
     $self->setAlwaysSecure($shop->getAlwaysSecure());
     $self->setRemoveCategory((bool) $config->get('routerRemoveCategory'));
     return $self;
 }
Пример #7
0
 /**
  * @param ShopEntity $shop
  * @return Shop
  */
 public static function createFromShopEntity(ShopEntity $shop)
 {
     $struct = new self();
     $struct->setId($shop->getId());
     $struct->setParentId($shop->getMain() ? $shop->getMain()->getId() : $shop->getId());
     $struct->setIsDefault($shop->getDefault());
     $struct->setName($shop->getName());
     $struct->setHost($shop->getHost());
     $struct->setPath($shop->getBasePath());
     $struct->setUrl($shop->getBaseUrl());
     $struct->setSecure($shop->getSecure());
     $struct->setSecureHost($shop->getSecureHost());
     $struct->setSecurePath($shop->getSecureBasePath());
     if ($shop->getCategory()) {
         $struct->setCategory(Category::createFromCategoryEntity($shop->getCategory()));
     }
     if ($shop->getFallback()) {
         $struct->setFallbackId($shop->getFallback()->getId());
     }
     return $struct;
 }
Пример #8
0
 /**
  * Returns the plugin configuration by the plugin name. If the
  * plugin has no config, the config is automatically set to an empty array.
  *
  * @param   string $name
  * @param   Shop   $shop
  * @return  Enlight_Config|array
  */
 public function getConfig($name, Shop $shop = null)
 {
     if ($shop) {
         $cacheKey = $name . $shop->getId();
     } else {
         $cacheKey = $name;
         $shop = $this->shop;
     }
     if (!isset($this->configStorage[$cacheKey])) {
         $sql = "\n                SELECT\n                  ce.name,\n                  COALESCE(currentShop.value, parentShop.value, fallbackShop.value, ce.value) as value\n\n                FROM s_core_plugins p\n\n                INNER JOIN s_core_config_forms cf\n                  ON cf.plugin_id = p.id\n\n                INNER JOIN s_core_config_elements ce\n                  ON ce.form_id = cf.id\n\n                LEFT JOIN s_core_config_values currentShop\n                  ON currentShop.element_id = ce.id\n                  AND currentShop.shop_id = :currentShopId\n\n                LEFT JOIN s_core_config_values parentShop\n                  ON parentShop.element_id = ce.id\n                  AND parentShop.shop_id = :parentShopId\n\n                LEFT JOIN s_core_config_values fallbackShop\n                  ON fallbackShop.element_id = ce.id\n                  AND fallbackShop.shop_id = :fallbackShopId\n\n                WHERE p.name=:pluginName\n            ";
         $config = $this->Application()->Db()->fetchPairs($sql, array('fallbackShopId' => 1, 'parentShopId' => $shop !== null && $shop->getMain() !== null ? $shop->getMain()->getId() : 1, 'currentShopId' => $shop !== null ? $shop->getId() : null, 'pluginName' => $name));
         foreach ($config as $key => $value) {
             $config[$key] = unserialize($value);
         }
         $this->configStorage[$cacheKey] = new Enlight_Config($config, true);
     }
     return $this->configStorage[$cacheKey];
 }
Пример #9
0
 /**
  * @param Request $request
  * @param Shop $shop
  * @return bool
  */
 protected function shouldRedirect(Request $request, Shop $shop)
 {
     return $request->isGet() && $request->getQuery('__shop') !== null && $request->getQuery('__shop') != $shop->getId() || $request->isPost() && $request->getPost('__shop') !== null && $request->getPost('__redirect') !== null;
 }
Пример #10
0
 /**
  * @param Shop\Shop $shop
  * @param $timestamp
  */
 public function createThemeTimestamp(Shop\Shop $shop, $timestamp)
 {
     $file = $this->pathResolver->getCacheDirectory() . DIRECTORY_SEPARATOR . 'timestamp' . $shop->getId() . '.txt';
     file_put_contents($file, $timestamp);
 }
Пример #11
0
 /**
  * Helper function which translates associated array data.
  *
  * @param array $association
  * @param Shop $shop
  * @param $type
  * @return array
  */
 protected function translateAssociation(array $association, Shop $shop, $type)
 {
     foreach ($association as &$item) {
         $translation = $this->getSingleTranslation($type, $shop->getId(), $item['id']);
         if (empty($translation)) {
             continue;
         }
         $item = $this->mergeTranslation($item, $translation['data']);
     }
     return $association;
 }
Пример #12
0
 /**
  * Returns the plugin configuration by the plugin name. If the
  * plugin has no config, the config is automatically set to an empty array.
  *
  * @param   string $name
  * @param   Shop   $shop
  * @return  Enlight_Config|array
  */
 public function getConfig($name, Shop $shop = null)
 {
     if ($shop) {
         $cacheKey = $name . $shop->getId();
     } else {
         $cacheKey = $name;
         $shop = $this->shop;
     }
     if (!isset($this->configStorage[$cacheKey])) {
         $sql = "\n                SELECT\n                  ce.name,\n                  IFNULL(IFNULL(cv.value, cm.value), ce.value) as value\n                FROM s_core_plugins p\n                JOIN s_core_config_forms cf\n                ON cf.plugin_id = p.id\n                JOIN s_core_config_elements ce\n                ON ce.form_id = cf.id\n                LEFT JOIN s_core_config_values cv\n                ON cv.element_id = ce.id\n                AND cv.shop_id = ?\n                LEFT JOIN s_core_config_values cm\n                ON cm.element_id = ce.id\n                AND cm.shop_id = ?\n                WHERE p.name=?\n            ";
         $config = $this->Application()->Db()->fetchPairs($sql, array($shop !== null ? $shop->getId() : null, $shop !== null && $shop->getMain() !== null ? $shop->getMain()->getId() : 1, $name));
         foreach ($config as $key => $value) {
             $config[$key] = unserialize($value);
         }
         $this->configStorage[$cacheKey] = new Enlight_Config($config, true);
     }
     return $this->configStorage[$cacheKey];
 }