Skip to content

Commit d43cc10

Browse files
committed
MAGETWO-56095: When category has products that are not visible to catalog the pager still shows is this expected behavior?
2 parents 7ba3189 + ab14bb4 commit d43cc10

File tree

2 files changed

+57
-0
lines changed
  • app/code/Magento/Catalog/Model/ResourceModel/Eav
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action

2 files changed

+57
-0
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Eav/Attribute.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ public function isIndexable()
417417
if ($this->getAttributeCode() == 'price') {
418418
return false;
419419
}
420+
if ($this->getAttributeCode() == 'visibility') {
421+
return true;
422+
}
420423

421424
if (!$this->getIsFilterableInSearch() && !$this->getIsVisibleInAdvancedSearch() && !$this->getIsFilterable()) {
422425
return false;

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,47 @@ public function testSaveActionRedirectsSuccessfully()
4545
$this->assertTrue($isRedirectPresent);
4646
}
4747

48+
/**
49+
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
50+
*
51+
* @dataProvider saveActionVisibilityAttrDataProvider
52+
* @param array $attributes
53+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
54+
*/
55+
public function testSaveActionChangeVisibility($attributes)
56+
{
57+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
58+
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
59+
\Magento\Catalog\Model\ProductRepository::class
60+
);
61+
$product = $repository->get('simple');
62+
$product->setOrigData();
63+
$product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE);
64+
$product->save();
65+
66+
/** @var $session \Magento\Backend\Model\Session */
67+
$session = $objectManager->get(\Magento\Backend\Model\Session::class);
68+
$session->setProductIds([$product->getId()]);
69+
$this->getRequest()->setParam('attributes', $attributes);
70+
71+
$this->dispatch('backend/catalog/product_action_attribute/save/store/0');
72+
/** @var \Magento\Catalog\Model\Category $category */
73+
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
74+
\Magento\Catalog\Model\CategoryFactory::class
75+
);
76+
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
77+
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
78+
\Magento\Catalog\Block\Product\ListProduct::class
79+
);
80+
81+
$category = $categoryFactory->create()->load(2);
82+
$layer = $listProduct->getLayer();
83+
$layer->setCurrentCategory($category);
84+
$productCollection = $layer->getProductCollection();
85+
$productItem = $productCollection->getFirstItem();
86+
$this->assertEquals($session->getProductIds(), [$productItem->getId()]);
87+
}
88+
4889
/**
4990
* @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute
5091
*
@@ -97,4 +138,17 @@ public function validateActionDataProvider()
97138
]
98139
];
99140
}
141+
142+
/**
143+
* Data Provider for save with visibility attribute
144+
*
145+
* @return array
146+
*/
147+
public function saveActionVisibilityAttrDataProvider()
148+
{
149+
return [
150+
['arguments' => ['visibility' => \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH]],
151+
['arguments' => ['visibility' => \Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG]]
152+
];
153+
}
100154
}

0 commit comments

Comments
 (0)