I am trying to use Magento's Advanced search in an effort to return multiple SKUs.
I have tried methods via the frontend/url like searching using quotes, +, & and more..
"SKU1""SKU2"
SKU1&SKU2
SKU1+SKU2
etc.
but they always tend to return either no result or the first SKU and nothing more. Is there a way to change the advanced search formula (and only the advanced search version as we have an extension working perfectly for regular use, we are just attempting to use the advanced search as another means to get this side necessity accomplished)
Be it from the backend editing within /vendor/magento/module-catalog-search/ or anywhere else? Surely there should be a possible/relatively easy solution.
UPDATE EDITS:
Trying to use the URL directly by replacing SKU1 and SKU2 with proper sku's doesn't work and throws the below error. Trying to use the advanced search form and searching with either a space between the SKUs or a comma just throws the error of not finding any matches.
The error at this time that I am receiving is;
Exception #0 (Exception): Notice: Array to string conversion in /app/design/frontend/CleverSoft/core/Magento_CatalogSearch/templates/advanced/result.phtml on line 39
#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(8, 'Array to string...', '/home/location...', 39, Array)
#1 /app/design/frontend/CleverSoft/core/Magento_CatalogSearch/templates/advanced/result.phtml(39): implode(',', Array)
#2 /vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/home/location...')
#3 /vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\CatalogSearch\Block\Advanced\Result), '/home/location...', Array)
#4 /vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/home/location...')
#5 /vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Framework\View\Element\Template->_toHtml()
#6 /vendor/magento/framework/View/Layout.php(558): Magento\Framework\View\Element\AbstractBlock->toHtml()
#7 /vendor/magento/framework/View/Layout.php(534): Magento\Framework\View\Layout->_renderBlock('catalogsearch_a...')
#8 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('catalogsearch_a...')
#9 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('catalogsearch_a...')
#10 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('content')
#11 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('content')
#12 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('content')
#13 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main.content.wr...')
#14 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main.content.wr...')
#15 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main.content.wr...')
#16 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main')
#17 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main')
#18 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main')
#19 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('columns_schedul...')
#20 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('columns_schedul...')
#21 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('columns_schedul...')
#22 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('columns_schedul...')
#23 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('columns_schedul...')
#24 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('columns_schedul...')
#25 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('columns')
#26 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#27 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('columns')
#28 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main.content_sc...')
#29 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main.content_sc...')
#30 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main.content_sc...')
#31 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('main.content')
#32 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#33 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main.content')
#34 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('page.wrapper')
#35 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#36 /vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('page.wrapper')
#37 /vendor/magento/framework/View/Layout.php(536): Magento\Framework\View\Layout->_renderContainer('root')
#38 /vendor/magento/framework/View/Layout.php(489): Magento\Framework\View\Layout->renderNonCachedElement('root')
#39 /vendor/magento/framework/View/Layout.php(954): Magento\Framework\View\Layout->renderElement('root')
#40 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Layout->getOutput()
#41 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Layout\Interceptor->___callParent('getOutput', Array)
#42 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}()
#43 /generated/code/Magento/Framework/View/Layout/Interceptor.php(39): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#44 /vendor/magento/framework/View/Result/Page.php(257): Magento\Framework\View\Layout\Interceptor->getOutput()
#45 /vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#46 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#47 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#48 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#49 /generated/code/Magento/Framework/View/Result/Page/Interceptor.php(26): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#50 /vendor/magento/framework/App/View.php(221): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#51 /vendor/magento/module-catalog-search/Controller/Advanced/Result.php(55): Magento\Framework\App\View->renderLayout()
#52 /vendor/magento/framework/App/Action/Action.php(107): Magento\CatalogSearch\Controller\Advanced\Result->execute()
#53 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#54 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\CatalogSearch\Controller\Advanced\Result\Interceptor->___callParent('dispatch', Array)
#55 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\CatalogSearch\Controller\Advanced\Result\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#56 /generated/code/Magento/CatalogSearch/Controller/Advanced/Result/Interceptor.php(26): Magento\CatalogSearch\Controller\Advanced\Result\Interceptor->___callPlugins('dispatch', Array, Array)
#57 /vendor/magento/framework/App/FrontController.php(55): Magento\CatalogSearch\Controller\Advanced\Result\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#58 /vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#59 /vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#60 /vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(94): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#61 /vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#62 /vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#63 /vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#64 /vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#65 /generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, NULL)
#66 /vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#67 /vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http->launch()
#68 /index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#69 {main}
While having the code as is; /app/design/frontend/CleverSoft/core/Magento_CatalogSearch/templates/advanced/result.phtml
<div class="search summary">
<?php foreach (['left', 'right'] as $side): ?>
<?php if (@$searchCriterias[$side]): ?>
<ul class="items">
<?php foreach ($searchCriterias[$side] as $criteria): ?>
<?php $criteria['value'] = is_array($criteria['value']) ? implode(",",$criteria['value']) : $criteria['value']; ?>
<li class="item"><strong><?= $block->escapeHtml(__($criteria['name'])) ?>:</strong> <?= $block->escapeHtml($criteria['value']) ?></li>
<script>console.log('testing if works');</script>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endforeach; ?>
Using the Advanced Search page (/catalogsearch/advanced/) and searching shows the message in the console so it's loading it, but shows incorrectly in that it isn't seeing the separate SKUs. However when trying to use the exact URL and replacing SKU1 with SKU2 is when the error seems to come.
I am using Magento CE 2.2.4 for clarity.
EDIT 2:
Success! Kind of. :) So the below string will work and supply the three requested SKUs;
https://example.com/catalogsearch/advanced/result/?sku[in][]=SKU1&sku[in][]=SKU2&sku[in][]=SKU3
What I did (and had to remove to get there);
What works now;
<div class="search summary">
<?php foreach (['left', 'right'] as $side): ?>
<?php if (@$searchCriterias[$side]): ?>
<ul class="items">
<?php foreach ($searchCriterias[$side] as $criteria): ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endforeach; ?>
</div>
What was removed;
<li class="item"><strong><?= $block->escapeHtml(__($criteria['name'])) ?>:</strong> <?= $block->escapeHtml($criteria['value']) ?></li>
Which was inside the foreach loop. Not sure if this was ideal, but I gave it a shot and removing so got everything working correct. I knew the criteria was correct because doing a print_r($criteria['value']);
would give:
Array
(
[in] => Array
(
[0] => SKU1
[1] => SKU2
[2] => SKU3
)
)
"4567","1234"
. But not Skus in the Catalog. – Craig Mar 20 '19 at 20:17