Skip to content

Commit cb8efe4

Browse files
authored
Add changes from Develop 1.x (#942)
* Update testing timestamp on develop-1.x * Hide out of stock for configurable products (move PR #378) (#925) * Minor updates for optimization (#932) * remove duplicate ids before indexing/creating jobs * add check for value in getFacets config helper * update search query parameter numericFilters to pass in array value for countable error in php 7.2 * customRankings check value pass in empty array if empty configuration value * update test assert value and add in array_unique * update assert * Join 2 callbacks for autocomplete updated event (#926) * Replace class names to ::class instead string names (#936) * Remove Object manager and add factories to constructor (#937) * Added translation in menu, Ui component. Source option models. (#938) * Tests: improve class names usage and replace literal name to ::class (#940)
1 parent 2d9f2d6 commit cb8efe4

30 files changed

+223
-166
lines changed

Helper/ConfigHelper.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ public function getCategoryAdditionalAttributes($storeId = null)
620620
ScopeInterface::SCOPE_STORE,
621621
$storeId
622622
));
623+
624+
$customRankings = $customRankings ?: [];
623625
$customRankings = array_filter($customRankings, function ($customRanking) {
624626
return $customRanking['attribute'] !== 'custom_attribute';
625627
});
@@ -659,6 +661,8 @@ public function getProductAdditionalAttributes($storeId = null)
659661
ScopeInterface::SCOPE_STORE,
660662
$storeId
661663
));
664+
665+
$customRankings = $customRankings ?: [];
662666
$customRankings = array_filter($customRankings, function ($customRanking) {
663667
return $customRanking['attribute'] !== 'custom_attribute';
664668
});
@@ -679,14 +683,16 @@ public function getFacets($storeId = null)
679683
$storeId
680684
));
681685

682-
foreach ($attrs as &$attr) {
683-
if ($attr['type'] === 'other') {
684-
$attr['type'] = $attr['other_type'];
686+
if ($attrs) {
687+
foreach ($attrs as &$attr) {
688+
if ($attr['type'] === 'other') {
689+
$attr['type'] = $attr['other_type'];
690+
}
685691
}
686-
}
687692

688-
if (is_array($attrs)) {
689-
return array_values($attrs);
693+
if (is_array($attrs)) {
694+
return array_values($attrs);
695+
}
690696
}
691697

692698
return [];

Helper/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getSearchResult($query, $storeId, $searchParams = null, $targete
119119
'attributesToRetrieve' => 'objectID',
120120
'attributesToHighlight' => '',
121121
'attributesToSnippet' => '',
122-
'numericFilters' => 'visibility_search=1',
122+
'numericFilters' => ['visibility_search=1'],
123123
'removeWordsIfNoResults' => $this->configHelper->getRemoveWordsIfNoResult($storeId),
124124
'analyticsTags' => 'backend-search',
125125
'facets' => $facetsToRetrieve,

Helper/Entity/AdditionalSectionHelper.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,42 @@
22

33
namespace Algolia\AlgoliaSearch\Helper\Entity;
44

5+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
56
use Magento\Eav\Model\Config;
67
use Magento\Framework\DataObject;
78
use Magento\Framework\Event\ManagerInterface;
8-
use Magento\Framework\ObjectManagerInterface;
99

1010
class AdditionalSectionHelper
1111
{
12+
/**
13+
* @var ManagerInterface
14+
*/
1215
private $eventManager;
1316

14-
private $objectManager;
17+
/**
18+
* @var CollectionFactory
19+
*/
20+
private $collectionFactory;
1521

22+
/**
23+
* @var Config
24+
*/
1625
private $eavConfig;
1726

27+
/**
28+
* AdditionalSectionHelper constructor.
29+
*
30+
* @param ManagerInterface $eventManager
31+
* @param CollectionFactory $collectionFactory
32+
* @param Config $eavConfig
33+
*/
1834
public function __construct(
1935
ManagerInterface $eventManager,
20-
ObjectManagerInterface $objectManager,
36+
CollectionFactory $collectionFactory,
2137
Config $eavConfig
2238
) {
2339
$this->eventManager = $eventManager;
24-
$this->objectManager = $objectManager;
40+
$this->collectionFactory = $collectionFactory;
2541
$this->eavConfig = $eavConfig;
2642
}
2743

@@ -51,8 +67,8 @@ public function getAttributeValues($storeId, $section)
5167
$attributeCode = $section['name'];
5268

5369
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $products */
54-
$products = $this->objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
55-
$products = $products->addStoreFilter($storeId)
70+
$products = $this->collectionFactory->create()
71+
->addStoreFilter($storeId)
5672
->addAttributeToFilter($attributeCode, ['notnull' => true])
5773
->addAttributeToFilter($attributeCode, ['neq' => ''])
5874
->addAttributeToSelect($attributeCode);

Helper/Entity/PageHelper.php

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,69 @@
44

55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
66
use Magento\Cms\Model\Page;
7+
use Magento\Cms\Model\ResourceModel\Page\CollectionFactory as PageCollectionFactory;
78
use Magento\Cms\Model\Template\FilterProvider;
89
use Magento\Framework\DataObject;
910
use Magento\Framework\Event\ManagerInterface;
10-
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\UrlInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213

1314
class PageHelper
1415
{
16+
/**
17+
* @var ManagerInterface
18+
*/
1519
private $eventManager;
1620

17-
private $objectManager;
21+
/**
22+
* @var PageCollectionFactory
23+
*/
24+
private $pageCollectionFactory;
1825

26+
/**
27+
* @var ConfigHelper
28+
*/
1929
private $configHelper;
2030

31+
/**
32+
* @var FilterProvider
33+
*/
2134
private $filterProvider;
2235

36+
/**
37+
* @var StoreManagerInterface
38+
*/
2339
private $storeManager;
2440

25-
private $storeUrls;
26-
41+
/**
42+
* @var UrlInterface
43+
*/
44+
private $frontendUrlBuilder;
45+
46+
/**
47+
* PageHelper constructor.
48+
*
49+
* @param ManagerInterface $eventManager
50+
* @param PageCollectionFactory $pageCollectionFactory
51+
* @param ConfigHelper $configHelper
52+
* @param FilterProvider $filterProvider
53+
* @param StoreManagerInterface $storeManager
54+
* @param UrlInterface $frontendUrlBuilder
55+
*/
2756
public function __construct(
2857
ManagerInterface $eventManager,
29-
ObjectManagerInterface $objectManager,
58+
PageCollectionFactory $pageCollectionFactory,
3059
ConfigHelper $configHelper,
3160
FilterProvider $filterProvider,
32-
StoreManagerInterface $storeManager
61+
StoreManagerInterface $storeManager,
62+
UrlInterface $frontendUrlBuilder
3363
) {
3464
$this->eventManager = $eventManager;
35-
$this->objectManager = $objectManager;
65+
$this->pageCollectionFactory = $pageCollectionFactory;
3666
$this->configHelper = $configHelper;
3767
$this->filterProvider = $filterProvider;
3868
$this->storeManager = $storeManager;
69+
$this->frontendUrlBuilder = $frontendUrlBuilder;
3970
}
4071

4172
public function getIndexNameSuffix()
@@ -62,12 +93,8 @@ public function getIndexSettings($storeId)
6293

6394
public function getPages($storeId)
6495
{
65-
/** @var \Magento\Cms\Model\Page $pageModel */
66-
$pageModel = $this->objectManager->create('\Magento\Cms\Model\Page');
67-
6896
/** @var \Magento\Cms\Model\ResourceModel\Page\Collection $magentoPages */
69-
$magentoPages = $pageModel->getCollection();
70-
$magentoPages = $magentoPages
97+
$magentoPages = $this->pageCollectionFactory->create()
7198
->addStoreFilter($storeId)
7299
->addFieldToFilter('is_active', 1);
73100

@@ -102,7 +129,7 @@ public function getPages($storeId)
102129
}
103130

104131
$pageObject['objectID'] = $page->getId();
105-
$pageObject['url'] = $this->getStoreUrl($storeId)
132+
$pageObject['url'] = $this->frontendUrlBuilder->setStore($storeId)
106133
->getUrl(
107134
null,
108135
[
@@ -125,17 +152,6 @@ public function getPages($storeId)
125152
return $pages;
126153
}
127154

128-
private function getStoreUrl($storeId)
129-
{
130-
if (!isset($this->storeUrls[$storeId])) {
131-
$url = $this->objectManager->create('Magento\Framework\Url');
132-
$url->setData('store', $storeId);
133-
$this->storeUrls[$storeId] = $url;
134-
}
135-
136-
return $this->storeUrls[$storeId];
137-
}
138-
139155
public function getStores($storeId = null)
140156
{
141157
$storeIds = [];

Helper/Entity/SuggestionHelper.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
use Magento\Framework\App\Cache\Type\Config as ConfigCache;
77
use Magento\Framework\DataObject;
88
use Magento\Framework\Event\ManagerInterface;
9-
use Magento\Framework\ObjectManagerInterface;
109
use Magento\Framework\Serialize\SerializerInterface;
1110
use Magento\Search\Model\Query;
11+
use Magento\Search\Model\ResourceModel\Query\CollectionFactory as QueryCollectionFactory;
1212

1313
class SuggestionHelper
1414
{
1515
private $eventManager;
1616

17-
private $objectManager;
17+
/**
18+
* @var QueryCollectionFactory
19+
*/
20+
private $queryCollectionFactory;
1821

1922
private $cache;
2023

@@ -24,15 +27,24 @@ class SuggestionHelper
2427

2528
private $popularQueriesCacheId = 'algoliasearch_popular_queries_cache_tag';
2629

30+
/**
31+
* SuggestionHelper constructor.
32+
*
33+
* @param ManagerInterface $eventManager
34+
* @param QueryCollectionFactory $queryCollectionFactory
35+
* @param ConfigCache $cache
36+
* @param ConfigHelper $configHelper
37+
* @param SerializerInterface $serializer
38+
*/
2739
public function __construct(
2840
ManagerInterface $eventManager,
29-
ObjectManagerInterface $objectManager,
41+
QueryCollectionFactory $queryCollectionFactory,
3042
ConfigCache $cache,
3143
ConfigHelper $configHelper,
3244
SerializerInterface $serializer
3345
) {
3446
$this->eventManager = $eventManager;
35-
$this->objectManager = $objectManager;
47+
$this->queryCollectionFactory = $queryCollectionFactory;
3648
$this->cache = $cache;
3749
$this->configHelper = $configHelper;
3850
$this->serializer = $serializer;
@@ -89,7 +101,8 @@ public function getPopularQueries($storeId)
89101
return $this->serializer->unserialize($queries);
90102
}
91103

92-
$collection = $this->objectManager->create('\Magento\Search\Model\ResourceModel\Query\Collection');
104+
/** @var \Magento\Search\Model\ResourceModel\Query\Collection $collection */
105+
$collection = $this->queryCollectionFactory->create();
93106
$collection->getSelect()->where(
94107
'num_results >= ' . $this->configHelper->getMinNumberOfResults() . '
95108
AND popularity >= ' . $this->configHelper->getMinPopularity() . '
@@ -124,8 +137,9 @@ public function getPopularQueries($storeId)
124137
public function getSuggestionCollectionQuery($storeId)
125138
{
126139
/** @var \Magento\Search\Model\ResourceModel\Query\Collection $collection */
127-
$collection = $this->objectManager->create('\Magento\Search\Model\ResourceModel\Query\Collection');
128-
$collection = $collection->addStoreFilter($storeId)->setStoreId($storeId);
140+
$collection = $this->queryCollectionFactory->create()
141+
->addStoreFilter($storeId)
142+
->setStoreId($storeId);
129143

130144
$collection->getSelect()->where(
131145
'num_results >= ' . $this->configHelper->getMinNumberOfResults($storeId) . '

Model/Indexer/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function execute($productIds)
6565
}
6666

6767
if ($productIds) {
68-
$productIds = array_merge($productIds, $this->productHelper->getParentProductIds($productIds));
68+
$productIds = array_unique(array_merge($productIds, $this->productHelper->getParentProductIds($productIds)));
6969
}
7070

7171
$storeIds = array_keys($this->storeManager->getStores());

Model/Product/Url.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
*/
2222
class Url extends ProductUrl
2323
{
24-
const FRONTEND_URL = 'Magento\Framework\Url';
25-
const BACKEND_URL = 'Magento\Backend\Model\Url';
26-
2724
private $objectManager;
2825

2926
public function __construct(
@@ -131,10 +128,10 @@ public function getUrl(Product $product, $params = [])
131128
public function getStoreScopeUrlInstance($storeId)
132129
{
133130
if (!$storeId) {
134-
return $this->objectManager->create(self::BACKEND_URL);
131+
return $this->objectManager->create(\Magento\Backend\Model\Url::class);
135132
}
136133

137-
return $this->objectManager->create(self::FRONTEND_URL);
134+
return $this->objectManager->create(\Magento\Framework\Url::class);
138135
}
139136

140137
private function getCategoryId(Product $product, $params)

Model/ResourceModel/Job/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
1818
protected function _construct()
1919
{
2020
$this->_init(
21-
'Algolia\AlgoliaSearch\Model\Job',
22-
'Algolia\AlgoliaSearch\Model\ResourceModel\Job'
21+
\Algolia\AlgoliaSearch\Model\Job::class,
22+
\Algolia\AlgoliaSearch\Model\ResourceModel\Job::class
2323
);
2424
}
2525
}

Model/Source/AbstractTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function getRenderer($columnId, $columnData)
4040
if (!array_key_exists($columnId, $this->selectFields) || !$this->selectFields[$columnId]) {
4141
/** @var \Algolia\AlgoliaSearch\Block\System\Form\Field\Select $select */
4242
$select = $this->getLayout()
43-
->createBlock('Algolia\AlgoliaSearch\Block\System\Form\Field\Select', '', [
43+
->createBlock(\Algolia\AlgoliaSearch\Block\System\Form\Field\Select::class, '', [
4444
'data' => ['is_render_to_js_template' => true],
4545
]);
4646

Model/Source/CustomPages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class CustomPages extends AbstractTable
99
protected function getTableData()
1010
{
1111
$objectManager = ObjectManager::getInstance();
12-
$pageCollection = $objectManager->create('Magento\Cms\Model\ResourceModel\Page\Collection');
12+
$pageCollection = $objectManager->create(\Magento\Cms\Model\ResourceModel\Page\Collection::class);
1313

1414
return [
1515
'attribute' => [

0 commit comments

Comments
 (0)