0

I have two attributes option_id. 141, 633. I need to get the attribute_id for those attribute option id value and get attribute_code. when I loop the one option id at a time the below code is working fine, but some scenarios I have more than two option_id, at that time it returns duplicate attribute_id.

This is my ListProduct.php

foreach($selectedFilters as $key => $filter){

                $logger->info($filter->getValueString());
                // print_r('Comes');
                $attribute_id = $this->helper->getAttributeIdByOption($filter->getValueString());
                $attributeIdByOption = $attribute_id;
                $this->attibute->load($attributeIdByOption);
                $attibuteCodeByOption = $this->attibute->getData()['attribute_code'];
                $logger->info($attibuteCodeByOption);

This is my helper Data.php

 public function getAttributeIdByOption($optionId){

        $optionFactory = $this->optionFactory->create();
        $optionFactory->load($optionId);
        $attributeId = $optionFactory->getAttributeId();
        $optionData = $this->_attributeOptionCollection
                                    ->setPositionOrder('asc')
                                    ->setAttributeFilter($attributeId)
                                    ->setIdFilter($optionId)
                                    // ->setStoreFilter()
                                    ->load();

        return $optionData->getData()[0]['attribute_id'];                            
    }

And This is my current output in log file,

2018-12-29T08:38:31+00:00 INFO (6): 633
2018-12-29T08:38:31+00:00 INFO (6): thickness
2018-12-29T08:38:31+00:00 INFO (6): 141
2018-12-29T08:38:31+00:00 INFO (6): thickness

Expected Output :

2018-12-29T08:38:31+00:00 INFO (6): 633
2018-12-29T08:38:31+00:00 INFO (6): thickness
2018-12-29T08:38:31+00:00 INFO (6): 141
2018-12-29T08:38:31+00:00 INFO (6): sheet_size

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.