Skip to content

Commit edb4db9

Browse files
committed
Merge branch 'develop'
2 parents 085448b + d954a4d commit edb4db9

File tree

17 files changed

+624
-6
lines changed

17 files changed

+624
-6
lines changed

.gitignore

100644100755
File mode changed.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2017 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Andreas von Studnitz <[email protected]>
9+
*/
10+
namespace IntegerNet\SolrCategories\Controller;
11+
12+
use IntegerNet\SolrCategories\Model\Indexer\Fulltext as FulltextIndexer;
13+
use Magento\TestFramework\ObjectManager;
14+
15+
class ResultTest extends \Magento\TestFramework\TestCase\AbstractController
16+
{
17+
/** @var ObjectManager */
18+
protected $objectManager;
19+
20+
protected function setUp()
21+
{
22+
parent::setUp();
23+
$this->objectManager = ObjectManager::getInstance();
24+
}
25+
26+
/**
27+
* @magentoDataFixture loadFixture
28+
* @magentoConfigFixture current_store integernet_solr/general/is_active 1
29+
* @magentoConfigFixture current_store integernet_solr/category/is_indexer_active 1
30+
* @magentoAppArea frontend
31+
* @magentoAppIsolation enabled
32+
* @magentoDbIsolation enabled
33+
*/
34+
public function testNoCategoriesOnSearchResultPage()
35+
{
36+
/** @var FulltextIndexer $indexer */
37+
$indexer = $this->objectManager->create(FulltextIndexer::class);
38+
$indexer->executeFull();
39+
40+
$this->dispatch('catalogsearch/result/index?q=abcdefgh');
41+
42+
$this->assertNotContains('solr-search-result-categories', $this->getResponse()->getBody());
43+
$this->assertNotContains('Description Category 1', $this->getResponse()->getBody());
44+
}
45+
46+
/**
47+
* @magentoDataFixture loadFixture
48+
* @magentoConfigFixture current_store integernet_solr/general/is_active 1
49+
* @magentoConfigFixture current_store integernet_solr/category/is_indexer_active 1
50+
* @magentoAppArea frontend
51+
* @magentoAppIsolation enabled
52+
* @magentoDbIsolation enabled
53+
*/
54+
public function testCategoriesOnSearchResultPage()
55+
{
56+
/** @var FulltextIndexer $indexer */
57+
$indexer = $this->objectManager->create(FulltextIndexer::class);
58+
$indexer->executeFull();
59+
60+
$this->dispatch('catalogsearch/result/index?q=category');
61+
62+
$this->assertContains('solr-search-result-categories', $this->getResponse()->getBody());
63+
$this->assertContains('Description Category 1', $this->getResponse()->getBody());
64+
$this->assertNotContains('Description Category 3', $this->getResponse()->getBody());
65+
$this->assertNotContains('Description Other Name 4', $this->getResponse()->getBody());
66+
}
67+
68+
/**
69+
* @magentoDataFixture loadFixture
70+
* @magentoConfigFixture current_store integernet_solr/general/is_active 1
71+
* @magentoConfigFixture current_store integernet_solr/category/is_indexer_active 1
72+
* @magentoAppArea frontend
73+
* @magentoAppIsolation enabled
74+
* @magentoDbIsolation enabled
75+
*/
76+
public function testFuzzyCategoriesOnSearchResultPage()
77+
{
78+
/** @var FulltextIndexer $indexer */
79+
$indexer = $this->objectManager->create(FulltextIndexer::class);
80+
$indexer->executeFull();
81+
82+
$this->dispatch('catalogsearch/result/index?q=catgeory');
83+
84+
$this->assertContains('solr-search-result-categories', $this->getResponse()->getBody());
85+
$this->assertContains('Description Category 1', $this->getResponse()->getBody());
86+
}
87+
88+
public static function loadFixture()
89+
{
90+
if (file_exists(__DIR__ . '/../_files/solr_config.php')) {
91+
include __DIR__ . '/../_files/solr_config.php';
92+
} else {
93+
include __DIR__ . '/../_files/solr_config.dist.php';
94+
}
95+
96+
include __DIR__ . '/../_files/products.php';
97+
include __DIR__ . '/../_files/categories.php';
98+
99+
}
100+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
solr_config.php
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
use Magento\Catalog\Model\Category;
3+
4+
\call_user_func(function() {
5+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
6+
7+
$store = $objectManager->create('Magento\Store\Model\Store');
8+
$storeId = $store->load('base', 'code')->getId();
9+
10+
/** @var \Magento\Framework\Registry $registry */
11+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry');
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
15+
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
16+
$collection = $objectManager->get(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
17+
$collection->addFieldToFilter('level', ['gt' => 1])->delete();
18+
19+
$registry->unregister('isSecureArea');
20+
$registry->register('isSecureArea', false);
21+
22+
/** @var Category $category */
23+
$category = $objectManager->create(
24+
Category::class
25+
);
26+
$category->isObjectNew(true);
27+
$category->setId(
28+
333
29+
)->setCreatedAt(
30+
'2014-06-23 09:50:07'
31+
)->setName(
32+
'Category 1'
33+
)->setData('description',
34+
'Description Category 1'
35+
)->setParentId(
36+
2
37+
)->setPath(
38+
'1/2/333'
39+
)->setLevel(
40+
2
41+
)->setIsActive(
42+
true
43+
)->setIncludeInMenu(
44+
true
45+
)->save();
46+
$category->setStoreId($storeId)->save();
47+
48+
$category = $objectManager->create(
49+
Category::class
50+
);
51+
$category->isObjectNew(true);
52+
$category->setId(
53+
444
54+
)->setCreatedAt(
55+
'2015-07-24 10:55:10'
56+
)->setName(
57+
'Category 2'
58+
)->setData('description',
59+
'Description Category 2'
60+
)->setParentId(
61+
2
62+
)->setPath(
63+
'1/2/444'
64+
)->setLevel(
65+
2
66+
)->setIsActive(
67+
true
68+
)->setIncludeInMenu(
69+
true
70+
)->save();
71+
$category->setStoreId($storeId)->save();
72+
73+
$category = $objectManager->create(
74+
Category::class
75+
);
76+
$category->isObjectNew(true);
77+
$category->setId(
78+
555
79+
)->setCreatedAt(
80+
'2016-08-25 12:13:14'
81+
)->setName(
82+
'Category 3'
83+
)->setData('description',
84+
'Description Category 3'
85+
)->setParentId(
86+
2
87+
)->setPath(
88+
'1/2/555'
89+
)->setLevel(
90+
2
91+
)->setIsActive(
92+
false
93+
)->setIncludeInMenu(
94+
true
95+
)->save();
96+
$category->setStoreId($storeId)->save();
97+
98+
$category = $objectManager->create(
99+
Category::class
100+
);
101+
$category->isObjectNew(true);
102+
$category->setId(
103+
666
104+
)->setCreatedAt(
105+
'2016-09-24 11:11:11'
106+
)->setName(
107+
'Other Name 4'
108+
)->setData('description',
109+
'Description Other Name 4'
110+
)->setParentId(
111+
2
112+
)->setPath(
113+
'1/2/666'
114+
)->setLevel(
115+
2
116+
)->setIsActive(
117+
true
118+
)->setIncludeInMenu(
119+
false
120+
)->save();
121+
$category->setStoreId($storeId)->save();
122+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
use Magento\Catalog\Model\Category;
3+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
4+
use Magento\Catalog\Model\Product\Type;
5+
use Magento\Catalog\Model\Product\Visibility;
6+
7+
\call_user_func(function() {
8+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
9+
10+
/** @var \Magento\Catalog\Model\Product $product */
11+
$product = $objectManager->create(
12+
\Magento\Catalog\Model\Product::class
13+
);
14+
$product->isObjectNew(true);
15+
$product->setSku('product-1')
16+
->setId(
17+
333
18+
)
19+
->setAttributeSetId(4)
20+
->setWebsiteIds([1])
21+
->setTypeId(Type::TYPE_SIMPLE)
22+
->setVisibility(Visibility::VISIBILITY_BOTH)
23+
->setStatus(Status::STATUS_ENABLED)
24+
->setUrlKey('product-1-global')
25+
->setPrice(10)
26+
->setWeight(1)
27+
->setTaxClassId(0)
28+
->setCategoryIds([2])
29+
->setStockData(
30+
[
31+
'use_config_manage_stock' => 1,
32+
'qty' => 100,
33+
'is_qty_decimal' => 0,
34+
'is_in_stock' => 1,
35+
]
36+
)
37+
->setName('Global product name')
38+
->save();
39+
40+
$product->setStoreId(1)
41+
->setName('Product name in store')
42+
->setStatus(Status::STATUS_ENABLED)
43+
->setUrlKey('product-1-store-1')
44+
->save();
45+
46+
47+
/** @var Category $category */
48+
$category = $objectManager->create(
49+
Category::class
50+
);
51+
$category->isObjectNew(true);
52+
$category->setId(
53+
333
54+
)->setCreatedAt(
55+
'2014-06-23 09:50:07'
56+
)->setName(
57+
'Category 1'
58+
)->setParentId(
59+
2
60+
)->setPath(
61+
'1/2/333'
62+
)->setLevel(
63+
2
64+
)->setAvailableSortBy(
65+
['position', 'name']
66+
)->setIsActive(
67+
true
68+
)->setPosition(
69+
1
70+
)->setIncludeInMenu(
71+
true
72+
)->setPostedProducts(
73+
[333 => 10]
74+
)->setDefaultSortBy(
75+
'name'
76+
)->save();
77+
78+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
$solrConfig = [
3+
'integernet_solr/server/host' => 'localhost',
4+
'integernet_solr/server/port' => '8983',
5+
'integernet_solr/server/path' => '/solr/',
6+
'integernet_solr/server/core' => 'solr-magento2-tests',
7+
];
8+
9+
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
/** @var \Magento\Framework\App\Config\MutableScopeConfigInterface $mutableScopeConfig */
12+
$mutableScopeConfig = $objectManager->create(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
13+
14+
foreach ($solrConfig as $path => $value) {
15+
$mutableScopeConfig->setValue($path, $value, 'stores', 'default');
16+
}

doc/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ This is the preferred method. Please follow these steps:
2424
To check, try to access https://github.com/integer-net/solr-magento2/.
2525
2. Add the necessary private repositories by calling the following commands from the command line inside your Magento base directory:
2626
```
27-
composer config repositories.solr-magento2 vcs https://github.com/integer-net/solr-magento2/
28-
composer config repositories.solr-magento2-autosuggest vcs https://github.com/integer-net/solr-magento2-autosuggest/
29-
composer config repositories.solr-pro vcs https://github.com/integer-net/solr-pro/
27+
composer config repositories.solr-magento2 git git@github.com:integer-net/solr-magento2.git
28+
composer config repositories.solr-magento2-autosuggest git git@github.com:integer-net/solr-magento2-autosuggest.git
29+
composer config repositories.solr-pro git git@github.com:integer-net/solr-pro.git
3030
3131
```
3232
3. Download the repositories by calling:

doc/release-notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ IntegerNet_Solr for Magento 2
22
===============
33
Release Notes
44

5+
Ongoing Work
6+
---------------
7+
8+
- Fix bug with fuzzy search for categories not working
9+
510
Version 1.1.1 (Apr 12, 2017)
611
---------------
712

main/src/Model/Bridge/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function getCategoryConfig()
306306
$this->_getConfigFlag($prefix . 'is_indexer_active'),
307307
$this->_getConfigFlag($prefix . 'use_in_search_results'),
308308
$this->_getConfig($prefix . 'max_number_results'),
309-
$this->_getConfigFlag($prefix . 'is_fuzzy_active'),
309+
$this->_getConfigFlag($prefix . 'fuzzy_is_active'),
310310
$this->_getConfig($prefix . 'fuzzy_sensitivity')
311311
);
312312
}

main/src/Observer/RedirectToProductOrCategory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private function getProductPageRedirectUrl($query)
136136
$matchingProductCollection = $this->productCollectionFactory->create();
137137
$matchingProductCollection->addStoreFilter();
138138
$matchingProductCollection->addAttributeToFilter($filters);
139+
$matchingProductCollection->addAttributeToFilter('status', Product\Attribute\Source\Status::STATUS_ENABLED);
139140
$matchingProductCollection->addAttributeToSelect(['status', 'visibility', 'url_key']);
140141
$matchingProductCollection->setOrder('visibility', 'desc');
141142

0 commit comments

Comments
 (0)