Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb10508
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 6, 2020
2379303
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 6, 2020
dff90f8
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 12, 2020
924304b
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 12, 2020
72e92c6
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 16, 2020
5d4e423
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 19, 2020
2646128
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 20, 2020
aaf6fd7
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 20, 2020
d25a4c5
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 21, 2020
55b0f40
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 27, 2020
161bbeb
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 27, 2020
79d1543
Support for ratings & reviews in Storefront App
aleksejsbaranovs Oct 29, 2020
57f2980
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 2, 2020
ad44ece
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 5, 2020
3a12b6f
Merge branch 'main' of github.com:aleksejsbaranovs10/commerce-data-ex…
aleksejsbaranovs Nov 5, 2020
b780b96
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 9, 2020
8a2ea40
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 11, 2020
84df965
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 11, 2020
9a645ec
Merge branch 'main' of github.com:aleksejsbaranovs10/commerce-data-ex…
aleksejsbaranovs Nov 17, 2020
97c3213
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 17, 2020
a9abe68
Web-API tests fix.
RuslanKostiv1 Nov 19, 2020
44633ff
Web-API tests fix.
RuslanKostiv1 Nov 19, 2020
d9451d8
Web-API tests fixes. Extra code removed from di.xml/module.xml
RuslanKostiv1 Nov 19, 2020
4f6ddf2
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 23, 2020
e024a01
Support for ratings & reviews in Storefront App
aleksejsbaranovs Nov 23, 2020
d1c38c1
Merge branch 'main' of github.com:aleksejsbaranovs10/commerce-data-ex…
aleksejsbaranovs Dec 7, 2020
d8abe5d
Merge remote-tracking branch 'commerce/main' into story-351-product-r…
RuslanKostiv1 Dec 10, 2020
7dd9129
Rating and reviews.
RuslanKostiv1 Dec 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogDataExporter/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@
<argument name="feedIdentity" xsi:type="string">productId</argument>
<argument name="sourceTableName" xsi:type="string">catalog_product_entity</argument>
<argument name="sourceTableField" xsi:type="string">entity_id</argument>
<argument name="scopeTableName" xsi:type="string">catalog_product_website</argument>
<argument name="scopeTableField" xsi:type="string">product_id</argument>
<argument name="scopeCode" xsi:type="string">website_id</argument>
<argument name="feedTableName" xsi:type="string">catalog_data_exporter_products</argument>
<argument name="feedTableField" xsi:type="string">id</argument>
<argument name="feedTableMutableColumns" xsi:type="array">
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CatalogDataExporter/etc/et_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<using field="id" />
</field>
</record>

<!-- TODO: delete deprecated "ImageDeprecated" type. use "Image" instead -->
<record name="ImageDeprecated">
<field name="url" type="String"/>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function build(string $eventType, array $entities, ?string $scope = null)
$entitiesArray = [];
foreach ($entities as $entityData) {
$entity = $this->entityFactory->create();
$entity->setEntityId($entityData['entity_id']);
$entity->setEntityId((string)$entityData['entity_id']);
$entity->setAttributes($entityData['attributes'] ?? []);

$entitiesArray[] = $entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,21 @@ public function __construct(
public function execute(array $entityData, array $deleteIds) : void
{
foreach ($this->getDeleteEntitiesData($deleteIds) as $storeCode => $entities) {
$scope = $storeCode ?: null;
foreach (\array_chunk($entities, $this->batchSize) as $chunk) {
$this->publishMessage(
$this->deletedEventType,
$chunk,
$scope
$storeCode
);
}
}

foreach ($this->getUpdateEntitiesData($entityData) as $storeCode => $entities) {
$scope = $storeCode ?: null;
foreach (\array_chunk($entities, $this->batchSize) as $chunk) {
$this->publishMessage(
$this->updatedEventType,
$chunk,
$scope
$storeCode
);
}
}
Expand All @@ -138,7 +136,7 @@ private function getDeleteEntitiesData(array $deleteIds): array
$feed = $this->feedPool->getFeed($this->feedIndexMetadata->getFeedName());
foreach ($feed->getDeletedByIds($deleteIds) as $entity) {
$deleted[$entity['storeViewCode'] ?? null][] = [
'entity_id' => (string)$entity[$this->feedIndexMetadata->getFeedIdentity()],
'entity_id' => $entity[$this->feedIndexMetadata->getFeedIdentity()],
];
}

Expand All @@ -157,7 +155,7 @@ private function getUpdateEntitiesData(array $entityData): array
$entitiesArray = [];
foreach ($entityData as $entity) {
$entitiesArray[$entity['storeViewCode'] ?? null][] = [
'entity_id' => (string)$entity[$this->feedIndexMetadata->getFeedIdentity()],
'entity_id' => $entity[$this->feedIndexMetadata->getFeedIdentity()],
'attributes' => $entity['attributes'] ?? [],
];
}
Expand All @@ -170,13 +168,13 @@ private function getUpdateEntitiesData(array $entityData): array
*
* @param string $eventType
* @param array $entities
* @param string|null $scope
* @param string $scope
*
* @return void
*/
private function publishMessage(string $eventType, array $entities, ?string $scope): void
private function publishMessage(string $eventType, array $entities, string $scope): void
{
$message = $this->messageBuilder->build($eventType, $entities, $scope);
$message = $this->messageBuilder->build($eventType, $entities, $scope ?: null);

try {
$this->queuePublisher->publish($this->topicName, $message);
Expand Down
91 changes: 91 additions & 0 deletions app/code/Magento/CatalogExport/Model/RatingMetadataRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogExport\Model;

use Magento\CatalogExportApi\Api\Data\RatingMetadata;
use Magento\CatalogExportApi\Api\Data\RatingMetadataFactory;
use Magento\CatalogExportApi\Api\EntityRequest;
use Magento\CatalogExportApi\Api\EntityRequest\Item;
use Magento\CatalogExportApi\Api\RatingMetadataRepositoryInterface;
use Magento\DataExporter\Model\FeedPool;
use Magento\Framework\Api\DataObjectHelper;

/**
* @inheritdoc
*/
class RatingMetadataRepository implements RatingMetadataRepositoryInterface
{
/**
* @var RatingMetadataFactory
*/
private $ratingMetadataFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

/**
* @var ExportConfiguration
*/
private $exportConfiguration;

/**
* @var FeedPool
*/
private $feedPool;

/**
* @param FeedPool $feedPool
* @param RatingMetadataFactory $ratingMetadataFactory
* @param DataObjectHelper $dataObjectHelper
* @param ExportConfiguration $exportConfiguration
*/
public function __construct(
FeedPool $feedPool,
RatingMetadataFactory $ratingMetadataFactory,
DataObjectHelper $dataObjectHelper,
ExportConfiguration $exportConfiguration
) {
$this->feedPool = $feedPool;
$this->ratingMetadataFactory = $ratingMetadataFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->exportConfiguration = $exportConfiguration;
}

/**
* @inheritdoc
*/
public function get(EntityRequest $request): array
{
$storeViewCodes = $request->getStoreViewCodes();
$ids = \array_map(function (Item $item) {
return $item->getEntityId();
}, $request->getEntities());

if (count($ids) > $this->exportConfiguration->getMaxItemsInResponse()) {
throw new \InvalidArgumentException(
'Max items in the response can\'t exceed '
. $this->exportConfiguration->getMaxItemsInResponse()
. '.'
);
}

$ratingsMetadata = [];
$feedData = $this->feedPool->getFeed('ratingMetadata')->getFeedByIds($ids, $storeViewCodes);

foreach ($feedData['feed'] as $feedItem) {
$ratingMetadata = $this->ratingMetadataFactory->create();
$feedItem['id'] = $feedItem['ratingId'];
$this->dataObjectHelper->populateWithArray($ratingMetadata, $feedItem, RatingMetadata::class);
$ratingsMetadata[] = $ratingMetadata;
}

return $ratingsMetadata;
}
}
90 changes: 90 additions & 0 deletions app/code/Magento/CatalogExport/Model/ReviewRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogExport\Model;

use Magento\CatalogExportApi\Api\Data\ReviewFactory;
use Magento\CatalogExportApi\Api\Data\Review;
use Magento\CatalogExportApi\Api\EntityRequest;
use Magento\CatalogExportApi\Api\EntityRequest\Item;
use Magento\CatalogExportApi\Api\ReviewRepositoryInterface;
use Magento\DataExporter\Model\FeedPool;
use Magento\Framework\Api\DataObjectHelper;

/**
* @inheritdoc
*/
class ReviewRepository implements ReviewRepositoryInterface
{
/**
* @var ReviewFactory
*/
private $reviewFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

/**
* @var ExportConfiguration
*/
private $exportConfiguration;

/**
* @var FeedPool
*/
private $feedPool;

/**
* @param FeedPool $feedPool
* @param ReviewFactory $reviewFactory
* @param DataObjectHelper $dataObjectHelper
* @param ExportConfiguration $exportConfiguration
*/
public function __construct(
FeedPool $feedPool,
ReviewFactory $reviewFactory,
DataObjectHelper $dataObjectHelper,
ExportConfiguration $exportConfiguration
) {
$this->feedPool = $feedPool;
$this->reviewFactory = $reviewFactory;
$this->dataObjectHelper = $dataObjectHelper;
$this->exportConfiguration = $exportConfiguration;
}

/**
* @inheritdoc
*/
public function get(EntityRequest $request): array
{
$ids = \array_map(function (Item $item) {
return $item->getEntityId();
}, $request->getEntities());

if (count($ids) > $this->exportConfiguration->getMaxItemsInResponse()) {
throw new \InvalidArgumentException(
'Max items in the response can\'t exceed '
. $this->exportConfiguration->getMaxItemsInResponse()
. '.'
);
}

$reviews = [];
$feedData = $this->feedPool->getFeed('reviews')->getFeedByIds($ids);

foreach ($feedData['feed'] as $feedItem) {
$review = $this->reviewFactory->create();
$feedItem['id'] = $feedItem['reviewId'];
$this->dataObjectHelper->populateWithArray($review, $feedItem, Review::class);
$reviews[] = $review;
}

return $reviews;
}
}
2 changes: 2 additions & 0 deletions app/code/Magento/CatalogExport/etc/communication.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
<topic name="catalog.export.product.data" request="Magento\CatalogExport\Event\Data\ChangedEntities"/>
<topic name="catalog.export.category.data" request="Magento\CatalogExport\Event\Data\ChangedEntities"/>
<topic name="catalog.export.product.variants.data" request="Magento\CatalogExport\Event\Data\ChangedEntities"/>
<topic name="export.product.reviews" request="Magento\CatalogExport\Event\Data\ChangedEntities"/>
<topic name="export.rating.metadata" request="Magento\CatalogExport\Event\Data\ChangedEntities"/>
</config>
4 changes: 4 additions & 0 deletions app/code/Magento/CatalogExport/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
<preference for="Magento\CatalogExportApi\Api\ProductRepositoryInterface" type="Magento\CatalogExport\Model\ProductRepository"/>
<preference for="Magento\CatalogExportApi\Api\CategoryRepositoryInterface" type="Magento\CatalogExport\Model\CategoryRepository"/>
<preference for="Magento\CatalogExportApi\Api\ProductVariantRepositoryInterface" type="Magento\CatalogExport\Model\ProductVariantRepository"/>
<preference for="Magento\CatalogExportApi\Api\ReviewRepositoryInterface" type="Magento\CatalogExport\Model\ReviewRepository"/>
<preference for="Magento\CatalogExportApi\Api\RatingMetadataRepositoryInterface" type="Magento\CatalogExport\Model\RatingMetadataRepository"/>

<type name="Magento\CatalogExport\Model\GenerateDTOs">
<arguments>
<argument name="baseConfigEntities" xsi:type="array">
<item name="Product" xsi:type="string">Product</item>
<item name="Category" xsi:type="string">Category</item>
<item name="ProductVariant" xsi:type="string">ProductVariant</item>
<item name="Review" xsi:type="string">Review</item>
<item name="RatingMetadata" xsi:type="string">RatingMetadata</item>
</argument>
</arguments>
</type>
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/CatalogExport/etc/queue_publisher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<publisher topic="catalog.export.product.variants.data">
<connection name="amqp" exchange="catalog.export.exchange" />
</publisher>

<publisher topic="export.product.reviews">
<connection name="amqp" exchange="catalog.export.exchange" />
</publisher>
<publisher topic="export.rating.metadata">
<connection name="amqp" exchange="catalog.export.exchange" />
</publisher>
</config>
2 changes: 2 additions & 0 deletions app/code/Magento/CatalogExport/etc/queue_topology.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<binding id="catalog.product.export.consumer" topic="catalog.export.product.data" destinationType="queue" destination="catalog.product.export.queue"/>
<binding id="catalog.category.export.consumer" topic="catalog.export.category.data" destinationType="queue" destination="catalog.category.export.queue"/>
<binding id="catalog.product.variants.export.consumer" topic="catalog.export.product.variants.data" destinationType="queue" destination="catalog.product.variants.export.queue"/>
<binding id="export.product.reviews.consumer" topic="export.product.reviews" destinationType="queue" destination="export.product.reviews.queue"/>
<binding id="export.rating.metadata.consumer" topic="export.rating.metadata" destinationType="queue" destination="export.rating.metadata.queue"/>
</exchange>
</config>
14 changes: 14 additions & 0 deletions app/code/Magento/CatalogExport/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<!-- <resource ref="Magento_Catalog::categories" />-->
</resources>
</route>

<route url="/V1/catalog-export/product-variants" method="GET">
<service class="Magento\CatalogExportApi\Api\ProductVariantRepositoryInterface" method="get"/>
<resources>
Expand All @@ -39,4 +40,17 @@
<!-- <resource ref="Magento_Catalog::products" />-->
</resources>
</route>

<route url="/V1/reviews-export/reviews" method="GET">
<service class="Magento\CatalogExportApi\Api\ReviewRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V1/reviews-export/ratings-metadata" method="GET">
<service class="Magento\CatalogExportApi\Api\RatingMetadataRepositoryInterface" method="get"/>
<resources>
<resource ref="anonymous" />
</resources>
</route>
</routes>
Loading