1

I tried find a solution to this magento 2 theme problem. How should be edit the theme file?

PHP Fatal error:  Uncaught Error: Call to undefined method Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\Interceptor::getCollectionClone() in app/code/custom_theme/LayeredAjax/view/frontend/templates/layer/filter.phtml:15
Stack trace:
#0 vendor/magento/framework/View/TemplateEngine/Php.php(59): include()
#1 vendor/magento/framework/View/Element/Template.php(271): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\LayeredNavigation\Block\Navigation\FilterRenderer\Interceptor), '/home/npartsco/...', Array)
#2 vendor/magento/framework/View/Element/Template.php(301): Magento\Framework\View\Element\Template->fetchView('/home/npartsco/...')
#3 vendor/magento/module-layered-navigation/Block/Navigation/FilterRenderer.php(29): Magento\Framework\View\Element\Template->_toHtml()
#4 vendor/magento/framework/Interception/Interceptor.php(58): Mage in app/code/custom_theme/LayeredAjax/view/frontend/templates/layer/filter.phtml on line 15

line 12-23

<?php
    $productCollection = $filter->getLayer()->getProductCollection();
    $productCollectionClone = $productCollection->getCollectionClone();
    $collection = $productCollectionClone
        ->removeAttributeSearch(['price.from', 'price.to']);

    $min = $collection->getMinPrice();
    $max = $collection->getMaxPrice();

    list($from, $to) = $requestValue ? explode('-', $requestValue) : [$min, $max];
?>
  • +1 for answer acceptance :) – Shoaib Munir Oct 28 '19 at 8:59
3

I don't understand why do you want clone of your collection. But still you can try php object cloning

Instead of which is I guess not available in Magento:

$productCollection = $filter->getLayer()->getProductCollection();
$productCollectionClone = $productCollection->getCollectionClone();

Try this one:

$productCollection = $filter->getLayer()->getProductCollection();
$productCollectionClone = clone $productCollection;
| improve this answer | |
  • Thanks it works! I don't know how it doesn't works with magento 2.3.3 and php 7.3 now because earlier was magento 2.2.6 and php 7.2 then all works. – Peter Oct 27 '19 at 22:12
  • @ShoaibMunir after add this solution still, I can't get my custom filter in layered navigation. Do you know solution for that? – Rohan Hapani Jan 20 at 11:09
  • can you share your code? – Shoaib Munir Jan 20 at 11:17
  • codeshare.io/2ELZjO it's di.xml file code. – Rohan Hapani Jan 20 at 11:35
  • codeshare.io/aJ4rVr It's fulltext collection file of custom module. There are functions code available also. But, I didn't add here. – Rohan Hapani Jan 20 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.