public function setLanguageSubShop(\Shopware\Models\Shop\Shop $languageSubShop) { $this->languageSubShop = $languageSubShop; $subShop = $languageSubShop->getMain() ? $languageSubShop->getMain() : $languageSubShop; $this->setShop($subShop); }
/** * 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')); }
/** * @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; }
/** * Helper function to build a unique file name. * @param string $timestamp * @param Shop\Shop $shop * @param string $suffix * @return string */ public function buildTimestampName($timestamp, Shop\Shop $shop, $suffix) { if ($shop->getMain()) { $shop = $shop->getMain(); } $filname = $timestamp . '_' . md5($timestamp . $shop->getTemplate()->getId() . $shop->getId() . \Shopware::REVISION); return $filname . '.' . $suffix; }
/** * Clear existing theme cache * Removes all assets and timestamp files * * @param \Shopware\Models\Shop\Shop $shop * @param $timestamp */ public function clearThemeCache(Shop\Shop $shop, $timestamp) { if ($shop->getMain()) { $shop = $shop->getMain(); } $files = [$this->pathResolver->buildTimestampName($timestamp, $shop, 'css'), $this->pathResolver->buildTimestampName($timestamp, $shop, 'js')]; $this->clearDirectory($files); }