Skip to content

Commit

Permalink
Fixed issues with merchandising
Browse files Browse the repository at this point in the history
  • Loading branch information
jansentjeu committed Jan 3, 2025
1 parent 8927d59 commit cc0a2e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 26 additions & 8 deletions src/Observer/ManageLayoutBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\Framework\Event\Observer;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Text;
use Magento\Framework\View\Layout;
use Tweakwise\TweakwiseJs\Model\Config;
use Tweakwise\TweakwiseJs\ViewModel\Merchandising;
Expand Down Expand Up @@ -54,6 +53,10 @@ public function execute(Observer $observer)

$this->layout = $observer->getLayout();

if (!$this->needToAddBlocks()) {
return;
}

$this->addDefaultBlock();
$this->addSearchBlock();

Expand All @@ -64,6 +67,15 @@ public function execute(Observer $observer)
$this->manageCategoryViewLayoutElements();
}

/**
* If container "after.body.start" doesn't exist, it is not a page request
* @return bool
*/
private function needToAddBlocks(): bool
{
return $this->layout->hasElement('after.body.start');
}

/**
* @return void
*/
Expand Down Expand Up @@ -125,7 +137,7 @@ private function addTweakwiseJsAddToCartBlock(): void
'view_model' => $this->merchandisingViewModel
]
]
)->setTemplate('Tweakwise_TweakwiseJs::js/category/add-to-cart-js.phtml');
)->setTemplate('Tweakwise_TweakwiseJs::js/category/add-to-cart.phtml');
$this->layout->setChild('page.wrapper', $blockName, $blockName);
}

Expand All @@ -134,21 +146,27 @@ private function addTweakwiseJsAddToCartBlock(): void
*/
private function removeMagentoCategoryViewLayoutElements(): void
{
$this->addEmptyBlock();
$this->moveCustomerBlocks();
$this->layout->unsetElement('main');
$this->layout->unsetElement('div.sidebar.main');
$this->layout->unsetElement('div.sidebar.additional');
}

/**
* Function to add an empty block to the "columns" container, because Magento doesn't render empty containers
* Move customer blocks out of the "main", so we can delete the "main" element
* @return void
*/
private function addEmptyBlock(): void
private function moveCustomerBlocks(): void
{
$blockName = 'empty-block';
$this->layout->createBlock(Text::class, $blockName, ['data' => ['text' => ' ']]);
$this->layout->setChild('columns', $blockName, $blockName);
$customerDataBlockName = 'customer.customer.data';
$customerDataBlock = $this->layout->getBlock($customerDataBlockName);
$this->layout->unsetElement($customerDataBlockName);
$this->layout->addBlock($customerDataBlock, $customerDataBlockName, 'columns');

$sectionConfigBlockName = 'customer.section.config';
$sectionConfigBlock = $this->layout->getBlock($sectionConfigBlockName);
$this->layout->unsetElement($sectionConfigBlockName);
$this->layout->addBlock($sectionConfigBlock, $sectionConfigBlockName, 'columns');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
*/
public function afterGetSuggestUrl(Subject $subject, string $result): string
{
if ($this->config->getSearchType() === SearchType::MAGENTO_DEFAULT->value) {
if (!$this->config->isEnabled() || $this->config->getSearchType() === SearchType::MAGENTO_DEFAULT->value) {
return $result;
}

Expand Down

0 comments on commit cc0a2e3

Please sign in to comment.