Skip to content

Commit

Permalink
Category indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
ugljesaspx committed Sep 3, 2024
1 parent 95324ee commit ced4270
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Exception/ParentCategoryDisabledException.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class ParentCategoryDisabledException extends NostoException
{
public function __construct(int $categoryId, $code = 0, Throwable $previous = null)
public function __construct($categoryId, $code = 0, Throwable $previous = null)
{
$message = "Parent category is disabled for category with id: " . $categoryId;
parent::__construct($message, $code, $previous);
Expand Down
7 changes: 3 additions & 4 deletions Model/Indexer/CategoryIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function getModeSwitcher(): ModeSwitcherInterface
public function doIndex(Store $store, array $ids = [])
{
$collection = $this->getCollection($store, $ids);

$this->categoryUpdateService->addCollectionToUpdateMessageQueue(
$collection,
$store
Expand All @@ -144,7 +145,7 @@ public function getIndexerId(): string
* @param array $ids
* @return CategoryCollection
*/
public function getCollection(Store $store, array $ids = []) //: CategoryCollection
public function getCollection(Store $store, array $ids = []) : CategoryCollection
{
$this->categoryCollectionBuilder->initDefault($store);

Expand All @@ -154,8 +155,6 @@ public function getCollection(Store $store, array $ids = []) //: CategoryCollect
$this->categoryCollectionBuilder->withStore($store);
}

return null;
// @TODO: Implement logic
// return $this->categoryCollectionBuilder->build();
return $this->categoryCollectionBuilder->build();
}
}
10 changes: 8 additions & 2 deletions Model/ResourceModel/Magento/Category/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Nosto\Tagging\Model\ResourceModel\Magento\Category;

use Magento\Catalog\Model\Category\Attribute\Source\Status;
//use Magento\Catalog\Model\Category\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Category\Collection as MagentoCategoryCollection;

class Collection extends MagentoCategoryCollection
Expand All @@ -46,8 +46,11 @@ class Collection extends MagentoCategoryCollection
*/
public function addActiveFilter()
{
echo '<pre>';

Check warning on line 49 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of echo language construct is discouraged.

Check failure on line 49 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of echo language construct is discouraged.
print_r(44);

Check failure on line 50 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

The use of function print_r() is forbidden
die;

Check failure on line 51 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of die language construct is discouraged.
// @TODO: Here should be included in the menu
return $this->addAttributeToFilter('status', ['eq' => Status::STATUS_ENABLED]);
return $this->addAttributeToFilter('status', ['eq' => 1]);
}

/**
Expand All @@ -56,6 +59,9 @@ public function addActiveFilter()
*/
public function addIdsToFilter(array $ids)
{
echo '<pre>';

Check failure on line 62 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of echo language construct is discouraged.
print_r(222);

Check failure on line 63 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

The use of function print_r() is forbidden
die;

Check failure on line 64 in Model/ResourceModel/Magento/Category/Collection.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of die language construct is discouraged.
return $this->addAttributeToFilter($this->getIdFieldName(), ['in' => $ids]);
}
}
12 changes: 6 additions & 6 deletions Model/ResourceModel/Magento/Category/CollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\Data\EntityInterface;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
//use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Nosto\Tagging\Model\ResourceModel\Magento\Category\Collection as CategoryCollection;
use Magento\Framework\DB\Select;

/**
* A builder class for building product collection with the most common filters
*/
class CollectionBuilder
{

/** @var CategoryCollection */
private CategoryCollection $categoryCollection;

/**
* Collection constructor.
* @param CategoryCollection $categoryCollection,
* @param CategoryCollection $categoryCollection
*/
public function __construct(
CategoryCollection $categoryCollection
) {
public function __construct(CategoryCollection $categoryCollection)
{
$this->categoryCollection = $categoryCollection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
*/

namespace Nosto\Tagging\Model\Service\Sync\Upsert;
namespace Nosto\Tagging\Model\Service\Sync\Upsert\Category;

use Magento\Framework\EntityManager\EntityManager;
use Magento\Framework\Json\Helper\Data as JsonHelper;
Expand All @@ -45,13 +45,14 @@
use Nosto\Tagging\Logger\Logger;
use Nosto\Tagging\Model\ResourceModel\Magento\Product\CollectionFactory;
use Nosto\Tagging\Model\Service\Sync\AbstractBulkConsumer;
use Nosto\Tagging\Model\Service\Sync\Upsert\SyncService;

/**
* Asynchronous Bulk Consumer
*
* Class AsyncBulkConsumer
*/
class BulkConsumer extends AbstractBulkConsumer
class AsyncBulkConsumer extends AbstractBulkConsumer
{
/** @var SyncService */
private SyncService $syncService;
Expand Down Expand Up @@ -99,6 +100,9 @@ public function __construct(
*/
public function doOperation(array $categoryIds, string $storeId)
{
echo '<pre>';

Check failure on line 103 in Model/Service/Sync/Upsert/Category/AsyncBulkConsumer.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of echo language construct is discouraged.
print_r(122);

Check failure on line 104 in Model/Service/Sync/Upsert/Category/AsyncBulkConsumer.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

The use of function print_r() is forbidden
die;

Check failure on line 105 in Model/Service/Sync/Upsert/Category/AsyncBulkConsumer.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Use of die language construct is discouraged.
$store = $this->nostoScopeHelper->getStore($storeId);
$categoryCollection = $this->collectionFactory->create()
->addIdsToFilter($categoryIds)
Expand Down
3 changes: 3 additions & 0 deletions Model/Service/Sync/Upsert/Category/BulkPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class BulkPublisher extends AbstractBulkPublisher
*/
public function getTopicName(): string
{
echo '<pre>';
print_r(122);
die;
return self::NOSTO_SYNC_MESSAGE_QUEUE;
}

Expand Down
3 changes: 3 additions & 0 deletions etc/communication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@
<topic name="nosto_product_sync.delete" request="Magento\AsynchronousOperations\Api\Data\OperationInterface">
<handler name="nosto_product_sync.delete" type="Nosto\Tagging\Model\Service\Sync\Delete\AsyncBulkConsumer" method="processOperation"/>
</topic>
<topic name="nosto_category_sync.update" request="Magento\AsynchronousOperations\Api\Data\OperationInterface">
<handler name="nosto_category_sync.update" type="Nosto\Tagging\Model\Service\Sync\Upsert\Category\AsyncBulkConsumer" method="processOperation"/>
</topic>
</config>
11 changes: 9 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@
</argument>
</arguments>
</type>
<type name="Nosto\Tagging\Model\Service\Sync\Upsert\Category\BulkPublisher">
<arguments>
<argument name="AsyncBulkConsumer" xsi:type="object" shared="false">
Nosto\Tagging\Model\Service\Sync\Upsert\Category\AsyncBulkConsumer
</argument>
</arguments>
</type>
<type name="Nosto\Tagging\Model\Service\Sync\Upsert\SyncService">
<arguments>
<argument name="productService" xsi:type="object" shared="false">
Expand Down Expand Up @@ -251,8 +258,8 @@
</type>
<type name="Nosto\Tagging\Model\Service\Update\CategoryUpdateService">
<arguments>
<argument name="upsertBulkPublisher" xsi:type="object" shared="false">
Nosto\Tagging\Model\Service\Sync\Upsert\AsyncBulkPublisher
<argument name="upsertCategoryBulkPublisher" xsi:type="object" shared="false">
Nosto\Tagging\Model\Service\Sync\Upsert\Category\BulkPublisher
</argument>
<argument name="deleteBulkPublisher" xsi:type="object" shared="false">
Nosto\Tagging\Model\Service\Sync\Delete\AsyncBulkPublisher
Expand Down
6 changes: 6 additions & 0 deletions etc/queue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@
consumerInstance="Magento\Framework\MessageQueue\Consumer"
handler="Nosto\Tagging\Model\Service\Sync\Delete\AsyncBulkConsumer::process"/>
</broker>
<broker topic="nosto_category_sync.update" exchange="magento-amqp" type="amqp">
<queue name="nosto_category_sync.update"
consumer="nosto_category_sync.update"
consumerInstance="Magento\Framework\MessageQueue\Consumer"
handler="Nosto\Tagging\Model\Service\Sync\Upsert\Category\AsyncBulkConsumer::process"/>
</broker>
</config>
6 changes: 6 additions & 0 deletions etc/queue_consumer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@
maxMessages="100"
consumerInstance="Magento\Framework\MessageQueue\Consumer"
handler="Nosto\Tagging\Model\Service\Sync\Delete\AsyncBulkConsumer::processOperation"/>
<consumer name="nosto_category_sync.update"
queue="nosto_category_sync.update"
connection="amqp"
maxMessages="200"
consumerInstance="Magento\Framework\MessageQueue\Consumer"
handler="Nosto\Tagging\Model\Service\Sync\Upsert\Category\AsyncBulkConsumer::processOperation"/>
</config>
3 changes: 3 additions & 0 deletions etc/queue_publisher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@
<publisher topic="nosto_product_sync.delete">
<connection name="amqp" exchange="magento-amqp"/>
</publisher>
<publisher topic="nosto_category_sync.update">
<connection name="amqp" exchange="magento-amqp"/>
</publisher>
</config>

0 comments on commit ced4270

Please sign in to comment.