diff --git a/app/code/Magento/Catalog/ViewModel/Product/Listing/PreparePostData.php b/app/code/Magento/Catalog/ViewModel/Product/Listing/PreparePostData.php new file mode 100644 index 0000000000000..c7ea49cc4dc1b --- /dev/null +++ b/app/code/Magento/Catalog/ViewModel/Product/Listing/PreparePostData.php @@ -0,0 +1,46 @@ +urlHelper = $urlHelper; + } + + /** + * Wrapper for the PostHelper::getPostData() + * + * @param string $url + * @param array $data + * @return array + */ + public function getPostData(string $url, array $data = []):array + { + if (!isset($data[ActionInterface::PARAM_NAME_URL_ENCODED])) { + $data[ActionInterface::PARAM_NAME_URL_ENCODED] = $this->urlHelper->getEncodedUrl(); + } + return ['action' => $url, 'data' => $data]; + } +} diff --git a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml index 13e2d998f6cdd..6e24f84f00482 100644 --- a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml +++ b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml @@ -175,6 +175,7 @@ related + Magento\Catalog\ViewModel\Product\Listing\PreparePostData upsell + Magento\Catalog\ViewModel\Product\Listing\PreparePostData getType()) { default: $exist = null; } +$_item = null; ?> @@ -170,13 +174,15 @@ switch ($type = $block->getType()) {
- escapeHtml($title) ?> + escapeHtml($title) ?>
escapeHtml(__('Check items to add to the cart or')) ?> - +
@@ -195,11 +201,15 @@ switch ($type = $block->getType()) {
' ?> - + getImage($_item, $image)->toHtml() ?>
- + escapeHtml($_item->getName()) ?> @@ -209,52 +219,88 @@ switch ($type = $block->getType()) { getReviewsSummaryHtml($_item, $templateType) ?> - isComposite() && $_item->isSaleable() && $type == 'related'):?> + isComposite() && $_item->isSaleable() + && $type == 'related'):?> getRequiredOptions()):?> - @@ -264,4 +310,15 @@ switch ($type = $block->getType()) {
+ isRedirectToCartEnabled() && $_item):?> + + diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml index 69d2523d88dfb..4b5d1033408e4 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml @@ -189,6 +189,7 @@ crosssell + Magento\Catalog\ViewModel\Product\Listing\PreparePostData getConfigurableAttributes($product) as $attribute) { - $eavAttribute = $attribute->getProductAttribute(); - - $isAllCustomOptionsDisplayed = ($isAllCustomOptionsDisplayed && $eavAttribute->getUsedInProductListing()); - } - - return $isAllCustomOptionsDisplayed; + //such cases already handled by add to cart action + return true; } /** diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/CrosssellTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/CrosssellTest.php index bf546ccd979b7..e3d8e3b229ffa 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/CrosssellTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Block/Product/ProductList/CrosssellTest.php @@ -29,6 +29,7 @@ public function testAll() $block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class) ->createBlock(\Magento\Catalog\Block\Product\ProductList\Crosssell::class); $block->setLayout($objectManager->get(\Magento\Framework\View\LayoutInterface::class)); + $block->setViewModel($objectManager->get(\Magento\Catalog\ViewModel\Product\Listing\PreparePostData::class)); $block->setTemplate('Magento_Catalog::product/list/items.phtml'); $block->setType('crosssell'); $block->setItemCount(1); @@ -36,7 +37,7 @@ public function testAll() $this->assertNotEmpty($html); $this->assertContains('Simple Cross Sell', $html); /* name */ - $this->assertContains('product\/' . $firstProduct->getId() . '\/', $html); + $this->assertContains('product/' . $firstProduct->getId() . '/', $html); /* part of url */ $this->assertInstanceOf( \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection::class,