Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute Indexing ignores custom source model options #417

Closed
simonspoerri opened this issue Nov 21, 2013 · 15 comments
Closed

Attribute Indexing ignores custom source model options #417

simonspoerri opened this issue Nov 21, 2013 · 15 comments
Labels
Component: Eav Fixed in 2.3.x The issue has been fixed in 2.3 release line improvement Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@simonspoerri
Copy link

Currently The indexing of Attribute Values used for the product filters in the category overview only index multiselect attributes that use attribute options. If a custom source model is specified the values are not indexed and thus are not taken into account when filtering products.

To fix the issue in my case I created an interface which all Source Models that should be taken into account while indexing should implement. For Attributes implementing this interface not only attribute options from the DB are indexed but also all options provided by the source model.

the class in question is Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source . I've overridden the _prepareMultiselectIndex Method and added the following snippet after the attribute options are loaded from 'eav/attribute_option'

        foreach($attrIds as $attributeId) {
            $attributeModel = Mage::getModel(Mage_Eav_Model_Entity::DEFAULT_ATTRIBUTE_MODEL)->load($attributeId);
            if($attributeModel->getSource() instanceof MyNS_MyModule_Model_Product_Attribute_Source_Interface) {
                $sourceModelOptions = $attributeModel->getSource()->getAllOptions();
                foreach($sourceModelOptions as $o) {
                    $options[$attributeId][$o["value"]] = true;         
                }
            }
        }


Maybe I'm misusing some principles here but I really think custom source model based multiselect attributes should be filterable as well, thus they need to be indexed...

@Zifius
Copy link
Member

Zifius commented Nov 24, 2013

This is exactly the issue I've faced about a year ago and solved it in a similar (albeit a bit dirtier approach) but this is something bothers me still. Thank you for the good description of the issue

I wonder if this can be solved even more elegantly without changing core files by implementing own indexer or the indexing should be improved in the core. @IvanChepurnyi can you advise please?

@Zifius
Copy link
Member

Zifius commented Dec 12, 2013

@simonspoerri found my SO thread regarding the issue http://stackoverflow.com/questions/7597448/multi-select-filter-in-layered-navigation/

@mage2-team any insight on this? Thank you

@simonspoerri
Copy link
Author

@Zifius, sorry i didn't attach the following link, http://www.magestore.com/magento/multi-select-filter-in-layered-navigation.html/, upon which my suggestion is based. Thanks for your help on this!

@Zifius
Copy link
Member

Zifius commented Dec 12, 2013

@simonspoerri looks like that site just aggregated my answer on SO which is the origin

@maksek maksek added the MX label Jan 8, 2015
@kokoc
Copy link
Member

kokoc commented Feb 3, 2015

@simonspoerri Thank you for reporting the issue and sorry for so biiiiig delay.

Internal reference: MAGETWO-33570
We will fix the problem and get back to you once we have the working code.

@kokoc kokoc added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Feb 3, 2015
@LittleBigDev
Copy link

Hello @kokoc, did you plan a similar fix for Magento 1 ? I'm currently on EE 1.14 and iI have this bug too (class Mage_Catalog_Model_Resource_Product_Indexer_Eav_Source).
If my question should be asked somewhere else, please tell me :)

okorshenko pushed a commit that referenced this issue Mar 3, 2016
@vkorotun vkorotun added Component: Eav and removed MX labels Aug 4, 2016
@piotrekkaminski
Copy link
Contributor

Thank you for your submission.

We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues.

Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here).

We are closing this GitHub ticket and have moved your request to the new forum.

mmansoor-magento pushed a commit that referenced this issue Sep 22, 2016
Bug 
MAGETWO-58373 Set return code for SetModeCommand [GITHUB PR#4845]
MAGETWO-58372 Added 'target' attribute to the allowed attributes array for link block [GITHUB PR#1935]
MAGETWO-56552 [GITHUB PR#4733] Escape Js Quote for layout updates
MAGETWO-58369 [GITHUB PR#4733] Update Container.php [GITHUB PR#4565]
@maderlock
Copy link

This is a bug, not a feature request - one documented feature does not work with another documented feature. Please could we have an update on MAGETWO-33570?

@maderlock
Copy link

maderlock commented Dec 6, 2016

Update to the previously suggested code - this works if added at around line 246 of magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

// Add options from custom source models
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$select = $this->getConnection()->select()->from(
    ['ea' => $this->getTable('eav_attribute')],
    ['attribute_id','source_model']
)->where('attribute_id IN(?)', $attrIds)
 ->where('source_model is not null');
$query = $select->query();
while ($row = $query->fetch()) {
    try {
        // Load custom source class and its options
        $source = $objectManager->create($row['source_model']);
        $sourceModelOptions = $source->getAllOptions();
        // Add options to list used below
        foreach ($sourceModelOptions as $o) {
            $options[$row['attribute_id']][$o["value"]] = true;
        }
    } catch (\BadMethodCallException $e) {
        // Skip
    }
}

I'm not sure if there is a better method for creating instances of the source class without the overhead of loading all the attributes, but this does fix the issue.

@maderlock
Copy link

If you are using the above for a temp fix, obviously use DI to create a preference for \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source and override just the _prepareMultiselectIndex method.

@pravalitera
Copy link

@maderlock This fix does not work with custom source that has varchar values. it causes an integrity constraint on reindex. With integer values, it's ok.
I know it's "normal" that it does not work with varchar, but it should not provoke an error on reindex.

@JosephMaxwell
Copy link
Contributor

@maderlock: thanks for that fix. I packaged it up, here: https://github.com/SwiftOtter/AttributeIndexFix

@maderlock
Copy link

Any update on this? I note that 2.1.8 has no fix for this.

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Dec 6, 2018
@leoquijano
Copy link

Hi @magento-engcom-team,

Is this one going to be applied to the 2.2-develop line? I see PR #16727 but it doesn't seem to have commits. 2.2.7 doesn't seem to have any changes to Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source either.

magento-engcom-team added a commit that referenced this issue Mar 1, 2019
…ngMethod.amount #417

 - Merge Pull Request magento/graphql-ce#417 from XxXgeoXxX/graphql-ce:2.3-devlop#402
 - Merged commits:
   1. 5bbb8bb
magento-engcom-team added a commit that referenced this issue Mar 20, 2019
Accepted Public Pull Requests:
 - #21785: [Forwardport] [Checkout] Fix clearing admin quote address when removing all items (by @eduard13)
 - #21469: Update price-bundle.js so that correct tier price is calculated while displaying in bundle product (by @adarshkhatri)
 - #21751: fix #21750 remove translation of product attribute label (by @Karlasa)
 - #21774: MSI: Add deprecation message to CatalogInventory SPIs (by @lbajsarowicz)
 - #21575: Fix for issue #21510: Can't access backend indexers page after creating a custom index (by @ccasciotti)
 - #21288: #12396: Total Amount cart rule without tax (by @AleksLi)
 - magento-commerce/magento-functional-tests-migration#679: #417 Removed unnecessary default values in action groups (by @hws47a)
 - magento-commerce/magento-functional-tests-migration#678: Convert FlushStaticFilesCacheButtonVisibilityTest to MFTF (by @Leandry)
 - magento-commerce/magento-functional-tests-migration#676: Convert VerifyDisabledCustomerGroupFieldTest to MFTF #664 (by @Michalk39)


Fixed GitHub Issues:
 - #21467: Tier price of simple item not working in Bundle product (reported by @adarshkhatri) has been fixed in #21469 by @adarshkhatri in 2.3-develop branch
   Related commits:
     1. caabef2
     2. 4c1c653
     3. d4dd2e6
     4. e7589ad
     5. 6f49b07
     6. 0332391

 - #21750: Product attribute labels are translated (reported by @Karlasa) has been fixed in #21751 by @Karlasa in 2.3-develop branch
   Related commits:
     1. a07eda3

 - #21510: Can't access backend indexers page after creating a custom index (reported by @ccasciotti) has been fixed in #21575 by @ccasciotti in 2.3-develop branch
   Related commits:
     1. 318425f
     2. 486e21c
     3. 409e00e
     4. 0acd6b6

 - #12396: "Total Amount" cart rule without tax (reported by @Chei20) has been fixed in #21288 by @AleksLi in 2.3-develop branch
   Related commits:
     1. 6ae859a
     2. c25656b
     3. 23ed015
     4. e9389ee
     5. 571f055
magento-devops-reposync-svc pushed a commit that referenced this issue May 24, 2022
…in-session

CABPI-290: prolong admin session if access token is valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Eav Fixed in 2.3.x The issue has been fixed in 2.3 release line improvement Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests