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

Make product list filter counts dependent on product visibility configuration #6035

Conversation

allanpaiste
Copy link

@allanpaiste allanpaiste commented Aug 7, 2016

Fixes the issue that was caused by two factors:

  1. Visibility attribute was not indexed in EAV
  2. Visibility filter was never applied due to a in_array check that compared int and string values which resulted in false-negative check.

Honestly tried to add a tests to this change as well, but instantiating product collection is a MAJOR head-ache due to things getting created, accessed and type-checked left and right - so - after seeing that just the setup for a test was going to be 100+ lines long - decided against creating it as it would just be unmaintainable.

Addresses issue: #5670

…_array check that fails in case integer and string values are compared
@allanpaiste allanpaiste changed the title Make filtering aware of product visibility and fixe an issue with in_array check Make filtering aware of product visibility and fix an issue with in_array check Aug 7, 2016
@allanpaiste allanpaiste changed the title Make filtering aware of product visibility and fix an issue with in_array check Make product filtering aware of product visibility and fix an issue with in_array check Aug 7, 2016
… even when only one product re-indexing was ordered
@allanpaiste allanpaiste changed the title Make product filtering aware of product visibility and fix an issue with in_array check Make product list filtering counts VS product visibility Aug 10, 2016
@allanpaiste allanpaiste changed the title Make product list filtering counts VS product visibility Make product list filtering counts dependent on product visibility Aug 10, 2016
@allanpaiste allanpaiste changed the title Make product list filtering counts dependent on product visibility Make product list filter counts dependent on product visibility Aug 10, 2016
@allanpaiste allanpaiste changed the title Make product list filter counts dependent on product visibility Make product list filter counts dependent on product visibility configuration Aug 10, 2016
@@ -265,7 +265,7 @@ public function addFieldToFilter($field, $condition = null)

$this->getSearchCriteriaBuilder();
$this->getFilterBuilder();
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
if (!is_array($condition) || !in_array((string)key($condition), ['from', 'to'])) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use strict flag: like in_array(key($condition), ['from', 'to'], true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true that. was not aware of the 3rd argument :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that the suggested change by @v-r along with this pull request do solve the problem. We need this fix which we've made on our local install. @allanpaiste any chance you can update this one line and submit the PR again? I could make a new request but I'd just be copying your work!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed & pushed. I don't mind if my work gets copied as long as Magento gets better :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay it seems that the build fails with pretty cryptic error. Considerign that develop branch itself is all in red, I would rather wait the PR target to go to be back in green before looking into that one.

Considering the narrow scope of the change I really doubt that it's caused by this branch.

@tkacheva
Copy link

@allanpaiste please look into issues with your PR

@shuaiZend
Copy link

shuaiZend commented Nov 2, 2016

@allanpaiste i used 2.1.2,when i replace AbstractEav.php from https://github.com/magento/magento2/pull/6035/files

and flush cache, and reindex..

`[root@199 magento2]# bin/magento index:reindex 
Design Config Grid index has been rebuilt successfully in 00:00:02
Customer Grid index has been rebuilt successfully in 00:00:02
Category Products index has been rebuilt successfully in 00:00:00
Product Categories index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:00
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '254-99-1-4' for key 'PRIMARY', query was: INSERT INTO `catalog_product_index_eav_idx` SELECT DISTINCT  `pid`.`entity_id`, `pid`.`attribute_id`, `pid`.`store_id`, IFNULL(pis.value, pid.value) AS `value` FROM (SELECT DISTINCT  `s`.`store_id`, `s`.`website_id`, `dd`.`attribute_id`, COALESCE(ds.value, dd.value) AS `value`, `cpe`.`entity_id` FROM `store` AS `s`
 LEFT JOIN `catalog_product_entity_int` AS `dd` ON dd.store_id = 0
 LEFT JOIN `catalog_product_entity_int` AS `ds` ON ds.store_id = s.store_id AND ds.attribute_id = dd.attribute_id AND ds.entity_id = dd.entity_id
 LEFT JOIN `catalog_product_entity_int` AS `d2d` ON d2d.store_id = 0 AND d2d.entity_id = dd.entity_id AND d2d.attribute_id = 97
 LEFT JOIN `catalog_product_entity_int` AS `d2s` ON d2s.store_id = s.store_id AND d2s.attribute_id = d2d.attribute_id AND d2s.entity_id = d2d.entity_id
 LEFT JOIN `catalog_product_entity` AS `cpe` ON cpe.entity_id = dd.entity_id WHERE (s.store_id != 0) AND ((ds.value IS NOT NULL OR dd.value IS NOT NULL)) AND (COALESCE(d2s.value, d2d.value) = 1)) AS `pid`
 LEFT JOIN `catalog_product_entity_int` AS `pis` ON pis.entity_id = pid.entity_id AND pis.attribute_id = pid.attribute_id AND pis.store_id = pid.store_id WHERE (pid.attribute_id IN('99')) AND (IFNULL(pis.value, pid.value) IS NOT NULL) AND (NOT(pis.value IS NULL AND pis.value_id IS NOT NULL))
Stock index has been rebuilt successfully in 00:00:00
Catalog Rule Product index has been rebuilt successfully in 00:00:00
Catalog Product Rule index has been rebuilt successfully in 00:00:00
Catalog Search index has been rebuilt successfully in 00:00:03`

how to fix it?

@maghamed maghamed self-assigned this Feb 14, 2017
@maghamed maghamed self-requested a review February 14, 2017 14:47
@maghamed
Copy link
Contributor

maghamed commented Feb 14, 2017

Hi @allanpaiste

How does current fix could address issue #5670, if Layered Navigation uses CatalogSearch Fulltext index and there are dedicated filters for visibility there specified in search_request.xml file
<filter xsi:type="termFilter" name="visibility_filter" field="visibility" value="$visibility$"/>
?

*/
protected function _prepareVisibilityIndex($entityIds = null)
{
$attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'visibility');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use constant from Public Service Contract API
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE

protected function _prepareVisibilityIndex($entityIds = null)
{
$attribute = $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'visibility');
$this->_prepareIndex($entityIds, $attribute->getAttributeId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have additional call for _prepareIndex? if we had one before in chaining call.

This code looks awkward for me, as we have:

$this->_prepareIndex()->_prepareRelationIndex()->_prepareIndex($entityIds, $attribute->getAttributeId())->_removeNotVisibleEntityFromIndex();

The fact that we should to call the same method twice says about code smell

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional call to _prepareIndex is necessary for this to work. Removing it results in the same incorrect visibility behavior.

@magento magento locked and limited conversation to collaborators Feb 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants