Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions everblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class Everblock extends Module
private $bypassedControllers = [
'hookDisplayInvoiceLegalFreeText',
];
/** @var Module|null */
private $qcdBuilderModule;
/** @var bool */
private $qcdBuilderModuleResolved = false;

public function __construct()
{
Expand Down Expand Up @@ -1099,10 +1103,35 @@ public function hookFilterQcdPageBuilderDeclarativeBlocks(array $params)

public function hookFilterQcdPageBuilderThirdPartyBlockFrontRender(array $params)
{
$renderer = new QcdThirdPartyBlockRenderer($this, $this->context);
$renderer = new QcdThirdPartyBlockRenderer(
$this,
$this->context,
$this->getQcdBuilderModule()
);
$renderer->renderFromHookFilterQcdPageBuilderThirdPartyBlockFrontRender($params);
}

private function getQcdBuilderModule(): ?Module
{
if ($this->qcdBuilderModuleResolved) {
return $this->qcdBuilderModule;
}

static $cachedQcdBuilderModule;
static $cachedQcdBuilderModuleResolved = false;

if (!$cachedQcdBuilderModuleResolved) {
$module = Module::getInstanceByName('qcdpagebuilder');
$cachedQcdBuilderModule = ($module instanceof Module) ? $module : null;
$cachedQcdBuilderModuleResolved = true;
}

$this->qcdBuilderModule = $cachedQcdBuilderModule;
$this->qcdBuilderModuleResolved = true;

return $this->qcdBuilderModule;
}

public function getContent()
{
if ($this->isProductModalAjaxRequest()) {
Expand Down Expand Up @@ -5129,7 +5158,7 @@ public function everHook($method, $args)
]);
}
/** @var Qcdpagebuilder|null $builder */
$builder = \Module::getInstanceByName('qcdpagebuilder');
$builder = $this->getQcdBuilderModule();

$block['content'] = $builder
? (string) $builder->renderTargetField(
Expand Down
35 changes: 27 additions & 8 deletions src/Service/QcdThirdPartyBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class QcdThirdPartyBlockRenderer
/** @var Context */
private $context;

public function __construct(Everblock $module, Context $context)
/** @var Module|null */
private $qcdBuilderModule;

public function __construct(Everblock $module, Context $context, ?Module $qcdBuilderModule = null)
{
$this->module = $module;
$this->context = $context;
$this->qcdBuilderModule = $qcdBuilderModule;
}

public function renderFromHookFilterQcdPageBuilderThirdPartyBlockFrontRender(array &$params): void
Expand Down Expand Up @@ -109,7 +113,7 @@ public function renderEverblockSelectContext(array &$context, string $blockType)
}

/** @var Qcdpagebuilder|null $builder */
$builder = Module::getInstanceByName('qcdpagebuilder');
$builder = $this->qcdBuilderModule;
$everblock->content = $builder
? (string) $builder->renderTargetField(
'everblock',
Expand Down Expand Up @@ -153,14 +157,29 @@ public function renderLatestPagesContext(array &$context, string $blockType): bo
$context['normalized']['attributes']['limit'] = $limit;

$customerGroups = EverblockPage::getCustomerGroups($this->context);
$pages = EverblockPage::getPages(
$customerGroups = array_map('intval', (array) $customerGroups);
sort($customerGroups);

static $latestPagesCache = [];
$cacheKey = implode(':', [
(int) $this->context->language->id,
(int) $this->context->shop->id,
true,
$customerGroups,
1,
$limit
);
$limit,
implode(',', $customerGroups),
]);

if (!isset($latestPagesCache[$cacheKey])) {
$latestPagesCache[$cacheKey] = EverblockPage::getPages(
(int) $this->context->language->id,
(int) $this->context->shop->id,
true,
$customerGroups,
1,
$limit
);
}

$pages = $latestPagesCache[$cacheKey];

$pageLinks = [];
foreach ($pages as $page) {
Expand Down
Loading