Yeah that would work, but way too many products I’d have to do that to. Like 500 or so.
I was hoping I could put something like"
$pageQuoteTitle = true;
or
$pageQuoteTitle = 1;
on the theme pages and whatever uses that theme page would work.
It didn’t.
I checked and getGlobalBlocks() doesn’t accept any parameters, it always returns all the blocks in all the global areas.
Only getBlocks() can be filtered by area. From the code I don’t see any reason why it wouldn’t work for global areas, maybe you should try again with just getBlocks()
I tried it again.
$pageObject = Page::getCurrentPage();
$pageBlocks = $pageObject->getBlocks('Request Quote');
$pageQuoteTitle = true;
if (!is_array($pageBlocks) || count($pageBlocks) === 0) {
$pageQuoteTitle = false;
}
if ($pageQuoteTitle) {
// there are blocks in the "Request Quote" Global Area
echo '<hr><h3>Please use the "Request a Quote" form</h3>(Success)<hr>';
} else {
// there are no blocks in the "Request Quote" Global Area
echo '<hr><h3>Please use the "Request More Info" form</h3>(Not Working)<hr>';
}
var_dump_safe($pageBlocks, true, 2);
The var_dump_safe returns:
array(0) { }
I’ll just look in to trying to put something on the page template to show what data to show.
@mdius why not just use JavaScript?
actually @mdius this works for me
$pageObject = Page::getCurrentPage();
$area = $pageObject ->getArea('Request Quote');
$totalBlocksInGlobalArea = $area->getTotalBlocksInArea($pageObject );
I tested it from the page template and counted blocks in a global area and it worked.
Well thank you!
Looking at your code made me try something different, and it worked.
As well you used getArea and I was using getBlock, that was the difference.
So after a few tried I got:
$area = $pageObject->getArea('Request Quote');
if ($area !== null) {
// there are blocks in the "Request Quote" Global Area
echo '<hr><h3>Please use the "Request a Quote" form</h3><hr>';
} else {
// there are no blocks in the "Request Quote" Global Area
echo '<hr><h3>Please use the "Request More Info" form</h3><hr>';
}
It now works perfectly.
About using JavaScript, I simply don’t understand JavaScript the same. I wouldn’t know where to begin.