community-features
community-features copied to clipboard
API: Product Reviews
See design suggested in https://github.com/magento/magento2/issues/9570
Overview
Currently, Magento 2 does not provide the REST API for the Reviews Extension of the products. In scope of this task we would implement WebAPI for product reviews and integrate review API into existing core modules
Resources
Resource | Request method | Permissions | Payload | Response | Implementation | Description |
---|---|---|---|---|---|---|
/V1/reviews/:id | GET | Guest, Customer, Admin | \Magento\Review\Api\Data\ReviewInterface | \Magento\Review\Api\ReviewRepositoryInterface::get | Get one review | |
/V1/reviews/:id | PUT | Admin | \Magento\Review\Api\Data\ReviewInterface | \Magento\Review\Api\ReviewRepositoryInterface::save | Update review | |
/V1/reviews/:id | DELETE | Admin | \Magento\Review\Api\ReviewRepositoryInterface::deleteById | Delete review | ||
/V1/reviews/ | POST | Guest, Customer, Admin | \Magento\Review\Api\Data\ReviewInterface | \Magento\Review\Api\Data\ReviewInterface | \Magento\Review\Api\ReviewRepositoryInterface::save | Create review |
/V1/reviews/ | GET | Admin | \Magento\Framework\Api\SearchCriteriaInterface | \Magento\Review\Api\Data\ReviewInterface[] | \Magento\Review\Api\ReviewRepositoryInterface::getList | Search reviews |
/V1/products/:sku/reviews | GET | Guest, Customer, Admin | \Magento\Review\Api\Data\ReviewInterface[] | \Magento\Review\Api\ReviewManagementInterface::getProductReviews | Get product reviews | |
/V1/customers/me/reviews | GET | Customer | \Magento\Review\Api\Data\ReviewInterface[] | \Magento\Review\Api\ReviewManagementInterface::getCustomerReviews | Get reviews created by current customer |
Interfaces
\Magento\Review\Api\ReviewRepositoryInterface
namespace Magento\Review\Api;
interface ReviewRepositoryInterface { /** * Save review. * * @param \Magento\Review\Api\Data\ReviewInterface $review * @return \Magento\Review\Api\Data\ReviewInterface * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function save(\Magento\Review\Api\Data\ReviewInterface $review);
/** * Get review by id. * * @param int $id * @return \Magento\Review\Api\Data\ReviewInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($id); /** * Delete review. * * @param \Magento\Review\Api\Data\ReviewInterface $review * @return bool * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function delete(\Magento\Review\Api\Data\ReviewInterface $review); /** * Delete review by id. * * @param int $id * @return bool * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function deleteById($id); /** * Lists the review items that match specified search criteria. * * @param \Magento\Framework\Api\SearchCriteria $searchCriteria * @return \Magento\Review\Api\Data\ReviewSearchResultInterface */ public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria);
}
\Magento\Review\Api\ReviewManagementInterface
namespace Magento\Review\Api;
interface ReviewManagementInterface { /** * Get customer's reviews. * * @param int $customerId * @return ReviewInterface[] */ public function getCustomerReviews($customerId);
/** * Get product reviews. * * @param string $sku * @return ReviewInterface[] */ public function getProductReviews($sku);
}
\Magento\Review\Api\Data\ReviewInterface
namespace Magento\Review\Api\Data; interface ReviewInterface { /** * Get review id. * * @return int / public function getId(); /* * Get Review title. * * @return string / public function getTitle(); /* * Get Review detail. * * @return string / public function getDetail(); /* * Get author nickname. * * @return string / public function getNickname(); /* * Get customer id. * * @return int|null / public function getCustomerId(); /* * Get review ratings. * * @return RatingInterface[] / public function getRatings(); /* * Get review entity type. * * @return string / public function getReviewEntity(); /* * Get reviewer type. * Possible values: 1 - Customer, 2 - Guest, 3 - Administrator. * * @return int / public function getReviewType(); /* * Get review status. * Possible values: 1 - Approved, 2 - Pending, 3 - Not Approved. * * @return int / public function getReviewStatus(); /* * Set review id. * * @param int $value * @return void / public function setId($value); /* * Set Review title. * * @param string $value * @return void / public function setTitle($value); /* * Set Review detail. * * @param void $value * @return void / public function setDetail($value); /* * Set author nickname. * * @param string $value * @return void / public function setNickname($value); /* * Set customer id. * * @param int|null $value * @return void / public function setCustomerId($value); /* * Set review ratings. * * @param RatingInterface[] $value * @return void / public function setRatings($value); /* * Set review entity type. * * @param string $value * @return void / public function setReviewEntity($value); /* * Set review status. * Possible values: 1 - Approved, 2 - Pending, 3 - Not Approved. * * @param int $value * @return void / public function setReviewStatus($value); /* * Set reviewer type. * Possible values: 1 - Customer, 2 - Guest, 3 - Administrator. * * @param int $value * @return string */ public function setReviewType($value); }
\Magento\Review\Api\Data\RatingInterface
namespace Magento\Review\Api\Data;
interface RatingInterface { /** * Get rating id. * * @return int|null */ public function getId();
/** * Get review id. * * @return int */ public function getReviewId(); /** * Get rating code. * * @return string */ public function getAttributeCode(); /** * Get rating value. * * @return int */ public function getValue(); /** * Set rating id. * * @param int|null $value * @return void */ public function setId($value); /** * Set review id. * * @param int $value * @return void */ public function setReviewId($value); /** * Set rating code. * * @param string $value * @return void */ public function setAttributeCode($value); /** * Set rating value. * * @param int $value * @return void */ public function setValue($value);
}
Hi, I'd like to attempt this one as well, the design seems a bit more fleshed out so it should provide some guidance for the other pull request as well.
@Tickles-BV that's great to hear! Let us know how we can support you in this effort.
Should this be developed against 2.2-develop or 2.3-develop?
2.3-develop
@ishakhsuvarov Could I ask you to assign me to this issue?
@ishakhsuvarov Could I ask you to assign me to this issue?
Are you still working on this issue? If you do not have any updates I would like to take care of this implementation because it blocks the implementation of https://github.com/magento/graphql-ce/pull/227
@bpicho do you mind if we reassign this ticket? Don't want to take it away if you're actively working
@misha-kotov @sky-hub we have almost ready code, but unfortunately I will not have time in the nearest future to finish it. I wouldn't like to block this task, so fell free. Please take a look on our repository https://github.com/DivanteLtd/magento2-review-api I hope that it will be useful for you to solve this task ;)
@bpicho Sounds good, thanks for working on this and providing the reference. We will assign to @sky-hub for now and hopefully we can get it across the finish line! @ishakhsuvarov can you please reassign?