Skip to content

Commit

Permalink
Merge pull request #798 from algolia/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bsuravech authored Jun 17, 2019
2 parents 7b1404f + 46b6dac commit 76c288f
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 2,859 deletions.
20 changes: 20 additions & 0 deletions Block/Adminhtml/Category/Merchandising.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,24 @@ public function getCurrentStore()

return $this->storeManager->getDefaultStoreView();
}

/**
* @return string
*/
public function getPageModeOnly()
{
return Category::DM_PAGE;
}

/**
* @return bool
*/
public function canDisplayProducts()
{
if ($this->getCategory()->getDisplayMode() == $this->getPageModeOnly()) {
return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion Helper/Entity/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ private function getAttributesForFaceting($storeId)

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

$facets = $this->configHelper->getFacets();
$facets = $this->configHelper->getFacets($storeId);
foreach ($facets as $facet) {
if ($facet['attribute'] === 'price') {
foreach ($currencies as $currency_code) {
Expand Down
78 changes: 54 additions & 24 deletions Model/Indexer/CategoryObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,74 @@

namespace Algolia\AlgoliaSearch\Model\Indexer;

use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Algolia\AlgoliaSearch\Model\Indexer\Category as CategoryIndexer;
use Magento\Catalog\Model\Category as CategoryModel;
use Magento\Catalog\Model\ResourceModel\Category as CategoryResourceModel;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Framework\Indexer\IndexerRegistry;

class CategoryObserver
{
/** @var CategoryIndexer */
private $indexer;

public function __construct(IndexerRegistry $indexerRegistry)
/** @var ConfigHelper */
private $configHelper;

/**
* @param IndexerRegistry $indexerRegistry
* @param ConfigHelper $configHelper
*/
public function __construct(IndexerRegistry $indexerRegistry, ConfigHelper $configHelper)
{
$this->indexer = $indexerRegistry->get('algolia_categories');
$this->configHelper = $configHelper;
}

public function afterSave(
CategoryResourceModel $categoryResource,
$result,
CategoryModel $category
) {
if (!$this->indexer->isScheduled()) {
/** @var Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $category->getProductCollection();
CategoryIndexer::$affectedProductIds = (array) $productCollection->getColumnValues('entity_id');

$this->indexer->reindexRow($category->getId());
}
/**
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
* afterSave(CategoryResourceModel $categoryResource, CategoryResourceModel $result, CategoryModel $category)
*
* @param CategoryResourceModel $categoryResource
* @param CategoryModel $category
*
* @return CategoryModel[]
*/
public function beforeSave(CategoryResourceModel $categoryResource, CategoryModel $category)
{
$categoryResource->addCommitCallback(function() use ($category) {
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
/** @var ProductCollection $productCollection */
$productCollection = $category->getProductCollection();
CategoryIndexer::$affectedProductIds = (array) $productCollection->getColumnValues('entity_id');

$this->indexer->reindexRow($category->getId());
}
});

return [$category];
}

public function beforeDelete(
CategoryResourceModel $categoryResource,
CategoryModel $category
) {
if (!$this->indexer->isScheduled()) {
/* we are using products position because getProductCollection() does use correct store */
$productCollection = $category->getProductsPosition();
CategoryIndexer::$affectedProductIds = array_keys($productCollection);

$this->indexer->reindexRow($category->getId());
}
/**
* @param CategoryResourceModel $categoryResource
* @param CategoryModel $category
*
* @return CategoryModel[]
*/
public function beforeDelete(CategoryResourceModel $categoryResource, CategoryModel $category)
{
$categoryResource->addCommitCallback(function() use ($category) {
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
/* we are using products position because getProductCollection() doesn't use correct store */
$productCollection = $category->getProductsPosition();
CategoryIndexer::$affectedProductIds = array_keys($productCollection);

$this->indexer->reindexRow($category->getId());
}
});

return [$category];
}
}
95 changes: 61 additions & 34 deletions Model/Indexer/ProductObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,98 @@

namespace Algolia\AlgoliaSearch\Model\Indexer;

use Algolia\AlgoliaSearch\Helper\ConfigHelper;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\Product\Action;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Model\AbstractModel;

class ProductObserver
{
/** @var Product */
private $indexer;

public function __construct(IndexerRegistry $indexerRegistry)
/** @var ConfigHelper */
private $configHelper;

/**
* @param IndexerRegistry $indexerRegistry
* @param ConfigHelper $configHelper
*/
public function __construct(IndexerRegistry $indexerRegistry, ConfigHelper $configHelper)
{
$this->indexer = $indexerRegistry->get('algolia_products');
$this->configHelper = $configHelper;
}

public function aroundSave(
\Magento\Catalog\Model\ResourceModel\Product $productResource,
\Closure $proceed,
AbstractModel $product
) {
/**
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
* afterSave(ProductResource $productResource, ProductResource $result, ProductModel $product)
*
* @param ProductResource $productResource
* @param ProductModel $product
*
* @return ProductModel[]
*/
public function beforeSave(ProductResource $productResource, ProductModel $product)
{
$productResource->addCommitCallback(function () use ($product) {
if (!$this->indexer->isScheduled()) {
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
$this->indexer->reindexRow($product->getId());
}
});

return $proceed($product);
return [$product];
}

public function aroundDelete(
\Magento\Catalog\Model\ResourceModel\Product $productResource,
\Closure $proceed,
AbstractModel $product
) {
/**
* Using "before" method here instead of "after", because M2.1 doesn't pass "$product" argument
* to "after" methods. When M2.1 support will be removed, this method can be rewriten to:
* public function afterDelete(ProductResource $productResource, ProductResource $result, ProductModel $product)
*
* @param ProductResource $productResource
* @param ProductModel $product
*
* @return ProductModel[]
*/
public function beforeDelete(ProductResource $productResource, ProductModel $product)
{
$productResource->addCommitCallback(function () use ($product) {
if (!$this->indexer->isScheduled()) {
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
$this->indexer->reindexRow($product->getId());
}
});

return $proceed($product);
return [$product];
}

public function aroundUpdateAttributes(
Action $subject,
\Closure $closure,
array $productIds,
array $attrData,
$storeId
) {
$result = $closure($productIds, $attrData, $storeId);
if (!$this->indexer->isScheduled()) {
/**
* @param Action $subject
* @param Action|null $result
* @param array $productIds
*
* @return Action
*/
public function afterUpdateAttributes(Action $subject, Action $result = null, $productIds)
{
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
$this->indexer->reindexList(array_unique($productIds));
}

return $result;
}

public function aroundUpdateWebsites(
Action $subject,
\Closure $closure,
array $productIds,
array $websiteIds,
$type
) {
$result = $closure($productIds, $websiteIds, $type);
if (!$this->indexer->isScheduled()) {
/**
* @param Action $subject
* @param Action|null $result
* @param array $productIds
*
* @return mixed
*/
public function afterUpdateWebsites(Action $subject, Action $result = null, array $productIds)
{
if (!$this->indexer->isScheduled() || $this->configHelper->isQueueActive()) {
$this->indexer->reindexList(array_unique($productIds));
}

Expand Down
15 changes: 0 additions & 15 deletions dev/frontend/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions dev/frontend/readme.md

This file was deleted.

6 changes: 0 additions & 6 deletions dev/frontend/scripts/build.sh

This file was deleted.

Loading

0 comments on commit 76c288f

Please sign in to comment.