Skip to content

Commit b259f81

Browse files
committed
ACP2E-2615: Bundle products added via the Page Builder > Products widget break the cart
- grid list widget template now incorporates product options
1 parent 881ca23 commit b259f81

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1616
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1717
use Magento\Catalog\Pricing\Price\FinalPrice;
18+
use Magento\Catalog\ViewModel\Product\OptionsData;
1819
use Magento\CatalogWidget\Model\Rule;
1920
use Magento\Framework\App\ActionInterface;
2021
use Magento\Framework\App\Http\Context as HttpContext;
@@ -130,6 +131,11 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
130131
*/
131132
private $categoryRepository;
132133

134+
/**
135+
* @var OptionsData
136+
*/
137+
private OptionsData $optionsData;
138+
133139
/**
134140
* @param Context $context
135141
* @param CollectionFactory $productCollectionFactory
@@ -143,6 +149,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
143149
* @param LayoutFactory|null $layoutFactory
144150
* @param EncoderInterface|null $urlEncoder
145151
* @param CategoryRepositoryInterface|null $categoryRepository
152+
* @param OptionsData|null $optionsData
146153
*
147154
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
148155
*/
@@ -158,7 +165,8 @@ public function __construct(
158165
Json $json = null,
159166
LayoutFactory $layoutFactory = null,
160167
EncoderInterface $urlEncoder = null,
161-
CategoryRepositoryInterface $categoryRepository = null
168+
CategoryRepositoryInterface $categoryRepository = null,
169+
OptionsData $optionsData = null
162170
) {
163171
$this->productCollectionFactory = $productCollectionFactory;
164172
$this->catalogProductVisibility = $catalogProductVisibility;
@@ -171,6 +179,7 @@ public function __construct(
171179
$this->urlEncoder = $urlEncoder ?: ObjectManager::getInstance()->get(EncoderInterface::class);
172180
$this->categoryRepository = $categoryRepository ?? ObjectManager::getInstance()
173181
->get(CategoryRepositoryInterface::class);
182+
$this->optionsData = $optionsData ?: ObjectManager::getInstance()->get(OptionsData::class);
174183
parent::__construct(
175184
$context,
176185
$data
@@ -306,6 +315,17 @@ public function getAddToCartPostParams(Product $product)
306315
];
307316
}
308317

318+
/**
319+
* Return product options
320+
*
321+
* @param Product $product
322+
* @return array
323+
*/
324+
public function getOptionsData(Product $product): array
325+
{
326+
return $this->optionsData->getOptionsData($product);
327+
}
328+
309329
/**
310330
* @inheritdoc
311331
*/

app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ use Magento\Wishlist\Helper\Data;
7474
<?php if ($_item->isSaleable()): ?>
7575
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
7676
<form data-role="tocart-form" data-product-sku="<?= $escaper->escapeHtml($_item->getSku()) ?>" action="<?= $escaper->escapeUrl($postParams['action']) ?>" method="post">
77+
<?php $options = $block->getOptionsData($_item); ?>
78+
<?php foreach ($options as $optionItem): ?>
79+
<input type="hidden"
80+
name="<?= $escaper->escapeHtml($optionItem['name']) ?>"
81+
value="<?= $escaper->escapeHtml($optionItem['value']) ?>">
82+
<?php endforeach; ?>
7783
<input type="hidden" name="product" value="<?= $escaper->escapeHtmlAttr($postParams['data']['product']) ?>">
7884
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
7985
<?= $block->getBlockHtml('formkey') ?>

0 commit comments

Comments
 (0)