1

In magento 2.2.5 Enterprise edition

I am trying to get layered navigation using custom API.

I got solution form here:
https://magento.stackexchange.com/a/262086/31910
and http://www.sivaschenko.com/magento2-category-layered-navigation-filterable-attributes/

my code is this: Please ignore ObjectManager it is only for testing purpose

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $filterableAttributes = $objectManager->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::class);

    //$appState = $objectManager->get(\Magento\Framework\App\State::class);
    $layerResolver = $objectManager->get(\Magento\Catalog\Model\Layer\Resolver::class);
    $filterList = $objectManager->create(
        \Magento\Catalog\Model\Layer\FilterList::class,
        [
            'filterableAttributes' => $filterableAttributes
        ]
    );

    //$appState->setAreaCode('frontend');
    $layer = $layerResolver->get();
    $layer->setCurrentCategory($category);
    $filters = $filterList->getFilters($layer);

    $data = array();
    foreach ($filters as $filter) {
        if ($filter->getItemsCount()) {
            $data[] = $filter;
        }
    }

    return $data;

The problem is, I am getting this error after applying this code:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.created_in' in 'where clause', query was: SELECT FLOOR((ROUND((e.min_price) * 1, 2)) / 10000) + 1 AS range, COUNT(*) AS count FROM catalog_product_index_price AS e\n INNER JOIN catalog_category_product_index_store1 AS cat_index ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='46'\n INNER JOIN cataloginventory_stock_status AS stock_status_index ON e.entity_id = stock_status_index.product_id AND stock_status_index.website_id = 0 AND stock_status_index.stock_id = 1\n INNER JOIN search_tmp_5e05a53f383179_70162465 AS search_result ON e.entity_id = search_result.entity_id WHERE ((stock_status_index.stock_status = 1)) AND (e.created_in <= '1573154701') AND (e.updated_in > '1573154701') AND ( e.website_id = '1' ) AND ( e.customer_group_id = 0) AND (e.min_price IS NOT NULL) GROUP BY FLOOR((ROUND((e.min_price) * 1, 2)) / 10000) + 1 ORDER BY (FLOOR((ROUND((e.min_price) * 1, 2)) / 10000) + 1) ASC

I don't know why it is adding (e.created_in <= '1573154701') in where clause

Can anyone help me resolve this issue?

  • Hi. Did you get solution? – Rohan Hapani Mar 12 at 12:19
0

In your Rest Api model file use this below code.

ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1);

class Filters implements Customer {

public function orders($id)
{
    $category = $id;

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $filterableAttributes = $objectManager->getInstance()
        ->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::class);

    $appState = $objectManager->getInstance()
        ->get(\Magento\Framework\App\State::class);
    $layerResolver = $objectManager->getInstance()
        ->get(\Magento\Catalog\Model\Layer\Resolver::class);
    $filterList = $objectManager->getInstance()
        ->create(\Magento\Catalog\Model\Layer\FilterList::class , ['filterableAttributes' => $filterableAttributes]);

    $layer = $layerResolver->get();
    $layer->setCurrentCategory($category);
    $filters = $filterList->getFilters($layer);
    $maxPrice = $layer->getProductCollection()
        ->getMaxPrice();
    $minPrice = $layer->getProductCollection()
        ->getMinPrice();

    $i = 0;
    foreach ($filters as $filter)
    {
        //$availablefilter = $filter->getRequestVar(); //Gives the request param name such as 'cat' for Category, 'price' for Price
        $availablefilter = (string)$filter->getName(); //Gives Display Name of the filter such as Category,Price etc.
        $items = $filter->getItems(); //Gives all available filter options in that particular filter
        $filterValues = array();
        $j = 0;
        foreach ($items as $item)
        {

            $filterValues[$j]['display'] = strip_tags($item->getLabel());
            $filterValues[$j]['value'] = $item->getValue();
            $filterValues[$j]['count'] = $item->getCount(); //Gives no. of products in each filter options
            $j++;
        }
        if (!empty($filterValues) && count($filterValues) > 1)
        {
            $filterArray['availablefilter'][$availablefilter] = $filterValues;

            $i++;
        }
    }

    return $filterArray;
    exit;
}

exit;

}

| improve this answer | |

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.