Skip to content

Commit 7db3f1a

Browse files
committed
ACP2E-3092: [CLOUD] No buttons of checkout or edit cart on the cart section
1 parent 1bafc57 commit 7db3f1a

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

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

Lines changed: 11 additions & 2 deletions
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 as BundleOptionsData;
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 BundleOptionsData|mixed|null
136+
*/
137+
private ?BundleOptionsData $bundleOptionsData;
138+
133139
/**
134140
* @param Context $context
135141
* @param CollectionFactory $productCollectionFactory
@@ -143,7 +149,7 @@ class ProductsList extends AbstractProduct implements BlockInterface, IdentityIn
143149
* @param LayoutFactory|null $layoutFactory
144150
* @param EncoderInterface|null $urlEncoder
145151
* @param CategoryRepositoryInterface|null $categoryRepository
146-
*
152+
* @param BundleOptionsData|null $bundleOptionsData
147153
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
148154
*/
149155
public function __construct(
@@ -158,7 +164,8 @@ public function __construct(
158164
Json $json = null,
159165
LayoutFactory $layoutFactory = null,
160166
EncoderInterface $urlEncoder = null,
161-
CategoryRepositoryInterface $categoryRepository = null
167+
CategoryRepositoryInterface $categoryRepository = null,
168+
BundleOptionsData $bundleOptionsData = null
162169
) {
163170
$this->productCollectionFactory = $productCollectionFactory;
164171
$this->catalogProductVisibility = $catalogProductVisibility;
@@ -171,6 +178,7 @@ public function __construct(
171178
$this->urlEncoder = $urlEncoder ?: ObjectManager::getInstance()->get(EncoderInterface::class);
172179
$this->categoryRepository = $categoryRepository ?? ObjectManager::getInstance()
173180
->get(CategoryRepositoryInterface::class);
181+
$this->bundleOptionsData = $bundleOptionsData ?: ObjectManager::getInstance()->get(BundleOptionsData::class);
174182
parent::__construct(
175183
$context,
176184
$data
@@ -301,6 +309,7 @@ public function getAddToCartPostParams(Product $product)
301309
'action' => $url,
302310
'data' => [
303311
'product' => $product->getEntityId(),
312+
'options' => $this->bundleOptionsData->getOptionsData($product),
304313
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($url),
305314
]
306315
];

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ 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 foreach ($postParams['data']['options'] as $optionItem): ?>
78+
<input type="hidden"
79+
name="<?= $escaper->escapeHtml($optionItem['name']) ?>"
80+
value="<?= $escaper->escapeHtml($optionItem['value']) ?>">
81+
<?php endforeach; ?>
7782
<input type="hidden" name="product" value="<?= $escaper->escapeHtmlAttr($postParams['data']['product']) ?>">
7883
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
7984
<?= $block->getBlockHtml('formkey') ?>
@@ -107,13 +112,13 @@ use Magento\Wishlist\Helper\Data;
107112
<div class="actions-secondary" data-role="add-to-links">
108113
<?php if ($this->helper(Data::class)->isAllow() && $showWishlist): ?>
109114
<a href="#"
110-
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
115+
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $escaper->escapeHtmlAttr(__('Add to Wish List')) ?>">
111116
<span><?= $escaper->escapeHtml(__('Add to Wish List')) ?></span>
112117
</a>
113118
<?php endif; ?>
114119
<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
115120
<?php $compareHelper = $this->helper(Compare::class);?>
116-
<a href="#" class="action tocompare" data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>">
121+
<a href="#" class="action tocompare" data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>' title="<?= $escaper->escapeHtmlAttr(__('Add to Compare')) ?>">
117122
<span><?= $escaper->escapeHtml(__('Add to Compare')) ?></span>
118123
</a>
119124
<?php endif; ?>

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66

77
namespace Magento\CatalogWidget\Block\Product;
88

9+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
10+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
11+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
912
use Magento\Catalog\Model\Indexer\Product\Eav\Processor;
1013
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1114
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1215
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\TestFramework\Fixture\DataFixture;
17+
use Magento\TestFramework\Fixture\DataFixtureStorage;
18+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
19+
use Magento\TestFramework\Fixture\DbIsolation;
1320
use Magento\TestFramework\Helper\Bootstrap;
1421
use PHPUnit\Framework\TestCase;
1522

@@ -34,11 +41,17 @@ class ProductListTest extends TestCase
3441
*/
3542
protected $objectManager;
3643

44+
/**
45+
* @var DataFixtureStorage
46+
*/
47+
private $fixtures;
48+
3749
protected function setUp(): void
3850
{
3951
$this->objectManager = Bootstrap::getObjectManager();
4052
$this->block = $this->objectManager->create(ProductsList::class);
4153
$this->categoryCollection = $this->objectManager->create(CategoryCollection::class);
54+
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
4255
}
4356

4457
/**
@@ -257,6 +270,29 @@ public function testCreateAnchorCollection()
257270
);
258271
}
259272

273+
#[
274+
DbIsolation(false),
275+
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
276+
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
277+
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$']], 'opt1'),
278+
DataFixture(BundleProductFixture::class, ['_options' => ['$opt1$']], 'bundle1'),
279+
]
280+
public function testBundleProductList()
281+
{
282+
$postParams = $this->block->getAddToCartPostParams($this->fixtures->get('bundle1'));
283+
284+
$this->assertArrayHasKey(
285+
'product',
286+
$postParams['data'],
287+
'Bundle product options is missing from POST params.'
288+
);
289+
$this->assertArrayHasKey(
290+
'options',
291+
$postParams['data'],
292+
'Bundle product options is missing from POST params.'
293+
);
294+
}
295+
260296
/**
261297
* Test that price rule condition works correctly
262298
*

0 commit comments

Comments
 (0)