Skip to content

Commit 2cee2dc

Browse files
committed
MC-18995: Page Builder & PWA Studio Compatibility
- Fix Product Widget list rendering through GraphQL
1 parent ad44545 commit 2cee2dc

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CmsGraphQl\Plugin;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\Message\MessageInterface;
12+
13+
/**
14+
* Load necessary design files for GraphQL
15+
*/
16+
class DesignLoader
17+
{
18+
/**
19+
* @var \Magento\Framework\View\DesignLoader
20+
*/
21+
protected $designLoader;
22+
23+
/**
24+
* @var \Magento\Framework\Message\ManagerInterface
25+
*/
26+
protected $messageManager;
27+
28+
/**
29+
* @param \Magento\Framework\View\DesignLoader $designLoader
30+
* @param \Magento\Framework\Message\ManagerInterface $messageManager
31+
*/
32+
public function __construct(
33+
\Magento\Framework\View\DesignLoader $designLoader,
34+
\Magento\Framework\Message\ManagerInterface $messageManager
35+
) {
36+
$this->designLoader = $designLoader;
37+
$this->messageManager = $messageManager;
38+
}
39+
40+
/**
41+
* Before create load the design files
42+
*
43+
* @param \Magento\Catalog\Block\Product\ImageFactory $subject
44+
* @param Product $product
45+
* @param string $imageId
46+
* @param array|null $attributes
47+
*
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function beforeCreate(
51+
\Magento\Catalog\Block\Product\ImageFactory $subject,
52+
Product $product,
53+
string $imageId,
54+
array $attributes = null
55+
) {
56+
try {
57+
$this->designLoader->load();
58+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
59+
if ($e->getPrevious() instanceof \Magento\Framework\Config\Dom\ValidationException) {
60+
/** @var MessageInterface $message */
61+
$message = $this->messageManager
62+
->createMessage(MessageInterface::TYPE_ERROR)
63+
->setText($e->getMessage());
64+
$this->messageManager->addUniqueMessages([$message]);
65+
}
66+
}
67+
}
68+
}

app/code/Magento/CmsGraphQl/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
</argument>
1919
</arguments>
2020
</type>
21+
<type name="Magento\Catalog\Block\Product\ImageFactory">
22+
<plugin name="designLoader" type="Magento\CmsGraphQl\Plugin\DesignLoader" />
23+
</type>
2124
</config>

0 commit comments

Comments
 (0)