Skip to content

Commit 251c3f4

Browse files
authored
Merge pull request #1517 from algolia/bugfix/MAGE-929
Bugfix/MAGE-929
2 parents 63566f3 + 4b32ad4 commit 251c3f4

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

Helper/Entity/Product/PriceManager/ProductWithoutChildren.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ protected function addTierPrices($tierPrice, $field, $currencyCode)
380380
$this->formatPrice($tierPrice[0], $currencyCode);
381381
}
382382
}
383-
# TODO bookmarking getRulePrice function for a future refactor effort.
383+
// TODO bookmarking getRulePrice function for a future refactor effort.
384384
/**
385385
* @param $groupId
386386
* @param $product

Plugin/SetAdminCurrentCategory.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Plugin;
4+
5+
use Algolia\AlgoliaSearch\Registry\CurrentCategory;
6+
use Magento\Catalog\Api\CategoryRepositoryInterface;
7+
use Magento\Catalog\Controller\Adminhtml\Category\Edit as EditController;
8+
use Magento\Framework\Exception\NoSuchEntityException;
9+
use Magento\Framework\View\Result\Page;
10+
11+
class SetAdminCurrentCategory
12+
{
13+
/** @var CurrentCategory */
14+
protected $currentCategory;
15+
16+
/**
17+
* @var CategoryRepositoryInterface
18+
*/
19+
private $categoryRepository;
20+
21+
/**
22+
* @param CurrentCategory $currentCategory
23+
* @param CategoryRepositoryInterface $categoryRepository
24+
*/
25+
public function __construct(
26+
CurrentCategory $currentCategory,
27+
CategoryRepositoryInterface $categoryRepository
28+
) {
29+
$this->currentCategory = $currentCategory;
30+
$this->categoryRepository = $categoryRepository;
31+
}
32+
33+
/**
34+
* Set the current category in adminhtml area in the Algolia registry without using Magento registry
35+
* (which is deprecated)
36+
*
37+
* @param EditController $subject
38+
* @param Page $result
39+
*
40+
* @return Page
41+
*/
42+
public function afterExecute(EditController $subject, $result)
43+
{
44+
$categoryId = $subject->getRequest()->getParam('id');
45+
try {
46+
$currentCategory = $this->categoryRepository->get($categoryId);
47+
$this->currentCategory->set($currentCategory);
48+
} catch (NoSuchEntityException $e) {
49+
return null;
50+
}
51+
52+
return $result;
53+
}
54+
}

etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<type name="Magento\Catalog\Model\Category">
66
<plugin name="algolia_algoliasearch_plugin_category_url" type="Algolia\AlgoliaSearch\Plugin\CategoryUrlPlugin"/>
77
</type>
8+
<type name="Magento\Catalog\Controller\Adminhtml\Category\Edit">
9+
<plugin name="algolia_algoliasearch_plugin_set_admin_current_category" type="Algolia\AlgoliaSearch\Plugin\SetAdminCurrentCategory"/>
10+
</type>
811
<type name="Algolia\AlgoliaSearch\Block\Adminhtml\LandingPage\Renderer\UrlBuilder">
912
<arguments>
1013
<argument name="frontendUrlBuilder" xsi:type="object">Magento\Framework\Url</argument>

etc/adminhtml/events.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,4 @@
6565
<event name="sales_order_shipment_save_after">
6666
<observer name="algoliasearch_reindex_product_on_last_item_purchase" instance="Algolia\AlgoliaSearch\Observer\ReindexProductOnLastItemPurchase"/>
6767
</event>
68-
<event name="catalog_controller_category_init_after">
69-
<observer name="algoliasearch_current_category" instance="Algolia\AlgoliaSearch\Observer\RegisterCurrentCategoryObserver"/>
70-
</event>
7168
</config>

0 commit comments

Comments
 (0)