Skip to content

Commit

Permalink
Merge pull request #4015 in SW/shopware from SW-15829/5.2/fix-shop-pa…
Browse files Browse the repository at this point in the history
…ge-seo-generation to 5.2

* commit '94e7b0df5ab33887acabc3e2d0cfbe52d0a31fa9':
  SW-15829 - Implement shop page service for seo generation
  • Loading branch information
MarcelSchmaeing committed Aug 26, 2016
2 parents e856e35 + 94e7b0d commit 3ab435f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
71 changes: 59 additions & 12 deletions engine/Shopware/Core/sRewriteTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Shopware\Bundle\AttributeBundle\Repository\SearchCriteria;
use Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Service\ShopPageServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Struct\ShopContextInterface;
use Shopware\Components\MemoryLimit;
use Shopware\Components\Model\ModelManager;
Expand Down Expand Up @@ -110,6 +111,11 @@ class sRewriteTable
* @var ContextServiceInterface
*/
private $contextService;

/**
* @var ShopPageServiceInterface
*/
private $shopPageService;

/**
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $db
Expand All @@ -120,6 +126,7 @@ class sRewriteTable
* @param Shopware_Components_Modules $moduleManager
* @param SlugInterface $slug
* @param ContextServiceInterface $contextService
* @param ShopPageServiceInterface $shopPageService
*/
public function __construct(
Enlight_Components_Db_Adapter_Pdo_Mysql $db = null,
Expand All @@ -129,7 +136,8 @@ public function __construct(
Enlight_Template_Manager $template = null,
Shopware_Components_Modules $moduleManager = null,
SlugInterface $slug = null,
ContextServiceInterface $contextService = null
ContextServiceInterface $contextService = null,
ShopPageServiceInterface $shopPageService = null
) {
$this->db = $db ?: Shopware()->Db();
$this->config = $config ?: Shopware()->Config();
Expand All @@ -139,6 +147,7 @@ public function __construct(
$this->moduleManager = $moduleManager ?: Shopware()->Modules();
$this->slug = $slug ?: Shopware()->Container()->get('shopware.slug');
$this->contextService = $contextService ?: Shopware()->Container()->get('shopware_storefront.context_service');
$this->shopPageService = $shopPageService ?: Shopware()->Container()->get('shopware_storefront.shop_page_service');
}

/**
Expand Down Expand Up @@ -255,7 +264,7 @@ public function sCreateRewriteTable($lastUpdate)
$this->sCreateRewriteTableBlog();
$this->sCreateRewriteTableCampaigns();
$lastUpdate = $this->sCreateRewriteTableArticles($lastUpdate);
$this->sCreateRewriteTableContent();
$this->sCreateRewriteTableContent(null, null, $context);
$this->sCreateRewriteTableSuppliers(null, null, $context);

return $lastUpdate;
Expand Down Expand Up @@ -554,14 +563,25 @@ public function sCreateRewriteTableBlog($offset = null, $limit = null)
}

/**
* Create emotion rewrite rules
* Used in multiple locations
*
* @deprecated since 5.2 will be removed in 5.3, use \sRewriteTable::createManufacturerUrls
* @param null $offset
* @param null $limit
* @param ShopContextInterface $context
*/
public function sCreateRewriteTableSuppliers($offset = null, $limit = null, ShopContextInterface $context = null)
{
$context = $this->createFallbackContext($context);
$this->createManufacturerUrls($context, $offset, $limit);
}

/**
* @param ShopContextInterface $context
* @param null $offset
* @param null $limit
* @throws Exception
* @throws SmartyException
*/
public function createManufacturerUrls(ShopContextInterface $context, $offset = null, $limit = null)
{
$seoSupplier = $this->config->get('sSEOSUPPLIER');
if (empty($seoSupplier)) {
Expand Down Expand Up @@ -657,14 +677,15 @@ public function sCreateRewriteTableForSingleCampaign(
*
* @param int $offset
* @param int $limit
* @param ShopContextInterface $context
*/
public function sCreateRewriteTableContent($offset = null, $limit = null)
public function sCreateRewriteTableContent($offset = null, $limit = null, ShopContextInterface $context = null)
{
//form urls
$this->insertFormUrls($offset, $limit);

//static pages urls
$this->insertStaticPageUrls($offset, $limit);
$this->insertStaticPageUrls($offset, $limit, $context);
}

/**
Expand Down Expand Up @@ -815,16 +836,23 @@ private function insertFormUrls($offset, $limit)
*
* @param $offset
* @param $limit
* @param ShopContextInterface $context
* @throws Exception
* @throws SmartyException
*/
private function insertStaticPageUrls($offset, $limit)
private function insertStaticPageUrls($offset, $limit, ShopContextInterface $context = null)
{
$shopId = Shopware()->Shop()->getId();
$context = $this->createFallbackContext($context);

$sitesData = $this->modelManager->getRepository('Shopware\Models\Site\Site')
->getSitesWithoutLinkQuery($shopId, $offset, $limit)
->getSitesWithoutLinkQuery($context->getShop()->getId(), $offset, $limit)
->getArrayResult();

foreach ($sitesData as $site) {
$pages = $this->shopPageService->getList(array_column($sitesData, 'id'), $context);

foreach ($pages as $site) {
$site = json_decode(json_encode($site), true);

$org_path = 'sViewport=custom&sCustom=' . $site['id'];
$this->data->assign('site', $site);
$path = $this->template->fetch('string:' . $this->config->get('seoCustomSiteRouteTemplate'), $this->data);
Expand Down Expand Up @@ -867,7 +895,7 @@ public function mapArticleTranslationObjectData($articles)
'name' => 'txtArtikel',
'description_long' => 'txtlangbeschreibung',
'description' => 'txtshortdescription',
'keywords' => 'keywords',
'keywords' => 'txtkeywords',
'metaTitle' => 'metaTitle',
]);

Expand Down Expand Up @@ -951,4 +979,23 @@ private function getManufacturerIds($offset = null, $limit = null)
$ids = array_column($suppliers, 'id');
return $ids;
}

/**
* @param ShopContextInterface $context
* @return ShopContextInterface
*/
private function createFallbackContext(ShopContextInterface $context = null)
{
if ($context) {
return $context;
}

/** @var \Shopware\Models\Shop\Shop $shop */
if (Shopware()->Container()->has('shop')) {
$shop = Shopware()->Container()->get('shop');
return $this->contextService->createShopContext($shop->getId());
}

return $this->contextService->createShopContext(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function countContent($shopId)
Shopware()->Db()->fetchOne('SELECT COUNT(id) FROM `s_cms_static` WHERE link=\'\''),
];

return max($counts);
return array_sum($counts);
}

/**
Expand Down

0 comments on commit 3ab435f

Please sign in to comment.