0

Hi i created custom API in magento 2 in that i need to implement advance search like store brand,model and year search like this enter image description here

i am able to get brand fileds `

public function getAddtocar($attribute) {

//        echo "sdfkjhsdkjfhsdkjhfkjdshfjkds";

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $filterableAttributes = $objectManager->getInstance()->get(\Magento\Catalog\Model\Layer\Category\FilterableAttributeList::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();
        $filters = $filterList->getFilters($layer);
//                    $maxPrice = $layer->getProductCollection();


        $i = 0;
        $values = [];
        $filterAttrs = [];
        foreach ($filters as $filter) {
            $attr_code = (string) $filter->getRequestVar();
            if ($attr_code == $attribute) {
                $attr_label = (string) $filter->getName();
                $items = $filter->getItems(); //Gives all available filter options in that particular filter
                foreach ($items as $item) {

                    $values[] = array(
                        "id" => $item->getValue(),
                        "count" => $item->getCount(),
                        "label" => strip_tags($item->getLabel()));
                }
//                $logger->info('Array Log count of values' . print_r($values, true)); // Array Log  
                if (!empty($values) && count($values) > 1) {
                    $filterAttrs[] = array(
                        "label" => $attr_label,
                        "options" => $values,
                        "code" => $attr_code);
                }
            }
        }
        $response = ['status' => 'true', 'layeredData' => $filterAttrs];
        echo $json = json_encode($response, JSON_UNESCAPED_UNICODE);
        die();

`by using abouve code i am able to show brand fileds which assigned to products after selection of brand need to get model filed forexample:: brand->hyundai,lexus,kia once select kia i need to get kia related model can any one suggest how to get like selection based

Your Answer

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

Browse other questions tagged or ask your own question.