Search

Mar 29, 2023

Magento 2.4.3: The Preview does not show sale prices created through catalog price rules

THE ISSUE:

When we search for product in preview or click link on cms page using Product Carousel, the site does not show the correct offer price created through the price rule in the catalog.

But When we view preview of Catalog Price Rule and click category in frontend it shows the right price.

As well as if we click Preview in Calendar it shows the correct offer price.


SOLUTION:

Follow the patch

diff --git a/vendor/magento/module-search/ViewModel/AdditionalSearchFormData.php b/vendor/magento/module-search/ViewModel/AdditionalSearchFormData.php
new file mode 100644
index 00000000000..84745a1eb04
--- /dev/null
+++ b/vendor/magento/module-search/ViewModel/AdditionalSearchFormData.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+declare(strict_types=1);
+
+namespace Magento\Search\ViewModel;
+
+use Magento\Framework\View\Element\Block\ArgumentInterface;
+
+/**
+ * View model for search additional form params
+ */
+class AdditionalSearchFormData implements ArgumentInterface
+{
+    /**
+     * Return search query params
+     *
+     * @return array
+     */
+    public function getFormData(): array
+    {
+        return [];
+    }
+}
diff --git a/vendor/magento/module-search/view/frontend/layout/default.xml b/vendor/magento/module-search/view/frontend/layout/default.xml
index 69c99f979d5..390de1883c8 100644
--- a/vendor/magento/module-search/view/frontend/layout/default.xml
+++ b/vendor/magento/module-search/view/frontend/layout/default.xml
@@ -11,6 +11,7 @@
             <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml">
                 <arguments>
                     <argument name="configProvider" xsi:type="object">Magento\Search\ViewModel\ConfigProvider</argument>
+                    <argument name="additionalSearchFormData" xsi:type="object">Magento\Search\ViewModel\AdditionalSearchFormData</argument>
                 </arguments>
             </block>
         </referenceContainer>
diff --git a/vendor/magento/module-search/view/frontend/templates/form.mini.phtml b/vendor/magento/module-search/view/frontend/templates/form.mini.phtml
index c6b2a6a7295..67aa709103d 100644
--- a/vendor/magento/module-search/view/frontend/templates/form.mini.phtml
+++ b/vendor/magento/module-search/view/frontend/templates/form.mini.phtml
@@ -10,6 +10,8 @@
 /** @var $escaper \Magento\Framework\Escaper */
 /** @var $configProvider \Magento\Search\ViewModel\ConfigProvider */
 $configProvider = $block->getData('configProvider');
+/** @var $versionManager \Magento\Search\ViewModel\AdditionalSearchFormData */
+$additionalSearchFormData = $block->getData('additionalSearchFormData');
 /** @var $helper \Magento\Search\Helper\Data */
 $helper = $configProvider->getSearchHelperData();
 $allowedSuggestion = $configProvider->isSuggestionsAllowed();
@@ -20,6 +22,12 @@ $quickSearchUrl = $allowedSuggestion ? $escaper->escapeUrl($helper->getSuggestUr
     <div class="block block-content">
         <form class="form minisearch" id="search_mini_form"
               action="<?= $escaper->escapeUrl($helper->getResultUrl()) ?>" method="get">
+            <?php  if (!empty($queryParams = $additionalSearchFormData->getFormData())): ?>
+                <?php foreach ($queryParams as $param): ?>
+                    <input type="hidden" name="<?= $escaper->escapeHtmlAttr($param['name']) ?>"
+                           value="<?= $escaper->escapeHtmlAttr($param['value']) ?>"/>
+                <?php endforeach; ?>
+            <?php endif; ?>
             <div class="field search">
                 <label class="label" for="search" data-role="minisearch-label">
                     <span><?= $escaper->escapeHtml(__('Search')) ?></span>
diff --git a/vendor/magento/module-search-staging/ViewModel/AdditionalSearchFormData.php b/vendor/magento/module-search-staging/ViewModel/AdditionalSearchFormData.php
new file mode 100644
index 00000000000..a37ae7259da
--- /dev/null
+++ b/vendor/magento/module-search-staging/ViewModel/AdditionalSearchFormData.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+declare(strict_types=1);
+
+namespace Magento\SearchStaging\ViewModel;
+
+use Magento\Framework\App\RequestInterface;
+use Magento\Framework\View\Element\Block\ArgumentInterface;
+use Magento\Staging\Model\VersionManager;
+
+/**
+ * View model for additional params for search
+ */
+class AdditionalSearchFormData implements ArgumentInterface
+{
+
+    /**
+     * @var \Magento\Staging\Model\VersionManager
+     */
+    private $versionManager;
+
+    /**
+     * @var RequestInterface
+     */
+    private $request;
+
+    /**
+     * @param RequestInterface $request
+     * @param VersionManager $versionManager
+     */
+    public function __construct(
+        RequestInterface $request,
+        VersionManager $versionManager
+    ) {
+        $this->request = $request;
+        $this->versionManager = $versionManager;
+    }
+
+    /**
+     * Return additional params for search staging
+     *
+     * @return array
+     */
+    public function getFormData(): array
+    {
+        $queryParams = [];
+        if ($this->versionManager->isPreviewVersion()) {
+            $queryPreviewParams = $this->request->getParams();
+            $queryParams = [
+                ['name' => '___version', 'value'=> $queryPreviewParams['___version']],
+                ['name'=> '__signature', 'value'=> $queryPreviewParams['__signature']],
+                ['name'=> '__timestamp', 'value'=> $queryPreviewParams['__timestamp']],
+            ];
+        }
+        return $queryParams;
+    }
+}
diff --git a/vendor/magento/module-search-staging/view/frontend/layout/default.xml b/vendor/magento/module-search-staging/view/frontend/layout/default.xml
index 3aec0b6c383..e28fcc9cb65 100644
--- a/vendor/magento/module-search-staging/view/frontend/layout/default.xml
+++ b/vendor/magento/module-search-staging/view/frontend/layout/default.xml
@@ -7,6 +7,11 @@
 -->
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <body>
+        <referenceBlock name="top.search">
+            <arguments>
+                <argument name="additionalSearchFormData" xsi:type="object">Magento\SearchStaging\ViewModel\AdditionalSearchFormData</argument>
+            </arguments>
+        </referenceBlock>
         <referenceContainer name="header-wrapper">
             <block class="Magento\Staging\Block\Preview\RequireInjector" name="top.search.staging" template="Magento_Staging::js/require-injector.phtml">
                 <arguments>

No comments:

Post a Comment