Skip to content

Commit 76c288f

Browse files
authored
Merge pull request #798 from algolia/develop
2 parents 7b1404f + 46b6dac commit 76c288f

File tree

14 files changed

+211
-2859
lines changed

14 files changed

+211
-2859
lines changed

Block/Adminhtml/Category/Merchandising.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,24 @@ public function getCurrentStore()
116116

117117
return $this->storeManager->getDefaultStoreView();
118118
}
119+
120+
/**
121+
* @return string
122+
*/
123+
public function getPageModeOnly()
124+
{
125+
return Category::DM_PAGE;
126+
}
127+
128+
/**
129+
* @return bool
130+
*/
131+
public function canDisplayProducts()
132+
{
133+
if ($this->getCategory()->getDisplayMode() == $this->getPageModeOnly()) {
134+
return false;
135+
}
136+
137+
return true;
138+
}
119139
}

Helper/Entity/ProductHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ private function getAttributesForFaceting($storeId)
953953

954954
$currencies = $this->currencyManager->getConfigAllowCurrencies();
955955

956-
$facets = $this->configHelper->getFacets();
956+
$facets = $this->configHelper->getFacets($storeId);
957957
foreach ($facets as $facet) {
958958
if ($facet['attribute'] === 'price') {
959959
foreach ($currencies as $currency_code) {

Model/Indexer/CategoryObserver.php

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,74 @@
22

33
namespace Algolia\AlgoliaSearch\Model\Indexer;
44

5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
56
use Algolia\AlgoliaSearch\Model\Indexer\Category as CategoryIndexer;
67
use Magento\Catalog\Model\Category as CategoryModel;
78
use Magento\Catalog\Model\ResourceModel\Category as CategoryResourceModel;
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
810
use Magento\Framework\Indexer\IndexerRegistry;
911

1012
class CategoryObserver
1113
{
14+
/** @var CategoryIndexer */
1215
private $indexer;
1316

14-
public function __construct(IndexerRegistry $indexerRegistry)
17+
/** @var ConfigHelper */
18+
private $configHelper;
19+
20+
/**
21+
* @param IndexerRegistry $indexerRegistry
22+
* @param ConfigHelper $configHelper
23+
*/
24+
public function __construct(IndexerRegistry $indexerRegistry, ConfigHelper $configHelper)
1525
{
1626
$this->indexer = $indexerRegistry->get('algolia_categories');
27+
$this->configHelper = $configHelper;
1728
}
1829

19-
public function afterSave(
20-
CategoryResourceModel $categoryResource,
21-
$result,
22-
CategoryModel $category
23-
) {
24-
if (!$this->indexer->isScheduled()) {
25-
/** @var Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
26-
$productCollection = $category->getProductCollection();
27-
CategoryIndexer::$affectedProductIds = (array) $productCollection->getColumnValues('entity_id');
28-
29-
$this->indexer->reindexRow($category->getId());
30-
}
30+
/**
31+
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
32+
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
33+
* afterSave(CategoryResourceModel $categoryResource, CategoryResourceModel $result, CategoryModel $category)
34+
*
35+
* @param CategoryResourceModel $categoryResource
36+
* @param CategoryModel $category
37+
*
38+
* @return CategoryModel[]
39+
*/
40+
public function beforeSave(CategoryResourceModel $categoryResource, CategoryModel $category)
41+
{
42+
$categoryResource->addCommitCallback(function() use ($category) {
43+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
44+
/** @var ProductCollection $productCollection */
45+
$productCollection = $category->getProductCollection();
46+
CategoryIndexer::$affectedProductIds = (array) $productCollection->getColumnValues('entity_id');
47+
48+
$this->indexer->reindexRow($category->getId());
49+
}
50+
});
51+
52+
return [$category];
3153
}
3254

33-
public function beforeDelete(
34-
CategoryResourceModel $categoryResource,
35-
CategoryModel $category
36-
) {
37-
if (!$this->indexer->isScheduled()) {
38-
/* we are using products position because getProductCollection() does use correct store */
39-
$productCollection = $category->getProductsPosition();
40-
CategoryIndexer::$affectedProductIds = array_keys($productCollection);
41-
42-
$this->indexer->reindexRow($category->getId());
43-
}
55+
/**
56+
* @param CategoryResourceModel $categoryResource
57+
* @param CategoryModel $category
58+
*
59+
* @return CategoryModel[]
60+
*/
61+
public function beforeDelete(CategoryResourceModel $categoryResource, CategoryModel $category)
62+
{
63+
$categoryResource->addCommitCallback(function() use ($category) {
64+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
65+
/* we are using products position because getProductCollection() doesn't use correct store */
66+
$productCollection = $category->getProductsPosition();
67+
CategoryIndexer::$affectedProductIds = array_keys($productCollection);
68+
69+
$this->indexer->reindexRow($category->getId());
70+
}
71+
});
72+
73+
return [$category];
4474
}
4575
}

Model/Indexer/ProductObserver.php

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,98 @@
22

33
namespace Algolia\AlgoliaSearch\Model\Indexer;
44

5+
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
6+
use Magento\Catalog\Model\Product as ProductModel;
57
use Magento\Catalog\Model\Product\Action;
8+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
69
use Magento\Framework\Indexer\IndexerRegistry;
7-
use Magento\Framework\Model\AbstractModel;
810

911
class ProductObserver
1012
{
13+
/** @var Product */
1114
private $indexer;
1215

13-
public function __construct(IndexerRegistry $indexerRegistry)
16+
/** @var ConfigHelper */
17+
private $configHelper;
18+
19+
/**
20+
* @param IndexerRegistry $indexerRegistry
21+
* @param ConfigHelper $configHelper
22+
*/
23+
public function __construct(IndexerRegistry $indexerRegistry, ConfigHelper $configHelper)
1424
{
1525
$this->indexer = $indexerRegistry->get('algolia_products');
26+
$this->configHelper = $configHelper;
1627
}
1728

18-
public function aroundSave(
19-
\Magento\Catalog\Model\ResourceModel\Product $productResource,
20-
\Closure $proceed,
21-
AbstractModel $product
22-
) {
29+
/**
30+
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
31+
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
32+
* afterSave(ProductResource $productResource, ProductResource $result, ProductModel $product)
33+
*
34+
* @param ProductResource $productResource
35+
* @param ProductModel $product
36+
*
37+
* @return ProductModel[]
38+
*/
39+
public function beforeSave(ProductResource $productResource, ProductModel $product)
40+
{
2341
$productResource->addCommitCallback(function () use ($product) {
24-
if (!$this->indexer->isScheduled()) {
42+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
2543
$this->indexer->reindexRow($product->getId());
2644
}
2745
});
2846

29-
return $proceed($product);
47+
return [$product];
3048
}
3149

32-
public function aroundDelete(
33-
\Magento\Catalog\Model\ResourceModel\Product $productResource,
34-
\Closure $proceed,
35-
AbstractModel $product
36-
) {
50+
/**
51+
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
52+
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
53+
* public function afterDelete(ProductResource $productResource, ProductResource $result, ProductModel $product)
54+
*
55+
* @param ProductResource $productResource
56+
* @param ProductModel $product
57+
*
58+
* @return ProductModel[]
59+
*/
60+
public function beforeDelete(ProductResource $productResource, ProductModel $product)
61+
{
3762
$productResource->addCommitCallback(function () use ($product) {
38-
if (!$this->indexer->isScheduled()) {
63+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
3964
$this->indexer->reindexRow($product->getId());
4065
}
4166
});
4267

43-
return $proceed($product);
68+
return [$product];
4469
}
4570

46-
public function aroundUpdateAttributes(
47-
Action $subject,
48-
\Closure $closure,
49-
array $productIds,
50-
array $attrData,
51-
$storeId
52-
) {
53-
$result = $closure($productIds, $attrData, $storeId);
54-
if (!$this->indexer->isScheduled()) {
71+
/**
72+
* @param Action $subject
73+
* @param Action|null $result
74+
* @param array $productIds
75+
*
76+
* @return Action
77+
*/
78+
public function afterUpdateAttributes(Action $subject, Action $result = null, $productIds)
79+
{
80+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
5581
$this->indexer->reindexList(array_unique($productIds));
5682
}
5783

5884
return $result;
5985
}
6086

61-
public function aroundUpdateWebsites(
62-
Action $subject,
63-
\Closure $closure,
64-
array $productIds,
65-
array $websiteIds,
66-
$type
67-
) {
68-
$result = $closure($productIds, $websiteIds, $type);
69-
if (!$this->indexer->isScheduled()) {
87+
/**
88+
* @param Action $subject
89+
* @param Action|null $result
90+
* @param array $productIds
91+
*
92+
* @return mixed
93+
*/
94+
public function afterUpdateWebsites(Action $subject, Action $result = null, array $productIds)
95+
{
96+
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
7097
$this->indexer->reindexList(array_unique($productIds));
7198
}
7299

dev/frontend/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

dev/frontend/readme.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

dev/frontend/scripts/build.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)