-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CheckoutAgreements getList refactoring #13221
CheckoutAgreements getList refactoring #13221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using aliases instead of long class names where possible.
* | ||
* @api | ||
*/ | ||
interface CheckoutAgreementsListingInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose to rename this to CheckoutAgreementsListInterface
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria | ||
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface[] | ||
*/ | ||
public function getListing(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) : array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remain consistent with the rest of the codebase it would make sense to rename method to getList
namespace Magento\CheckoutAgreements\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor; | ||
|
||
class StoreFilter implements | ||
\Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using alias for this long name.
\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor | ||
) { | ||
$this->collectionFactory = $collectionFactory; | ||
$this->extAttributesJoinProcessor = $extensionAttributesJoinProcessor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid shortened names like extAttributes
as it may be unclear what it is supposed to do
namespace Magento\CheckoutAgreements\Api; | ||
|
||
/** | ||
* Interface CheckoutAgreementsListingInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to include background for such kind of interface
@@ -13,4 +13,10 @@ | |||
<resource ref="Magento_Sales::sales" /> | |||
</resources> | |||
</route> | |||
<route url="/V1/carts/licence/listing" method="GET"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest renaming route to list
.
Please refer to Magento\Catalog\Api\CategoryListInterface
to remain consistent with it.
-- review fixes
) { | ||
$this->agreementsValidator = $agreementsValidator; | ||
$this->scopeConfiguration = $scopeConfiguration; | ||
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository; | ||
$this->checkoutAgreementsList = $checkoutAgreementsList ?: ObjectManager::getInstance()->get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugins are not covered by backward compatibility policy. You may add dependencies as required parameters here.
@@ -117,7 +158,21 @@ private function isAgreementEnabled() | |||
AgreementsProvider::PATH_ENABLED, | |||
ScopeInterface::SCOPE_STORE | |||
); | |||
$agreementsList = $isAgreementsEnabled ? $this->checkoutAgreementsRepository->getList() : []; | |||
$storeFilter = $this->filterBuilder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code occurs multiple times in this PR along with 3 dependencies to support it.
It would make sense to extract it to a separate service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just workflow with searchCriteria mechanism, I think it will be useless create new service only for couple of filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing this many boilerplate code creates a challenge in maintenance of it.
It is much easier to fix/update only 1 service instead of searching all over the module in the future.
) { | ||
$this->agreementsValidator = $agreementsValidator; | ||
$this->scopeConfiguration = $scopeConfiguration; | ||
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository; | ||
$this->checkoutAgreementsList = $checkoutAgreementsList ?: ObjectManager::getInstance()->get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plugins are not covered by BC policy. See above.
@@ -74,7 +115,7 @@ public function beforeSavePaymentInformationAndPlaceOrder( | |||
* @param string $email | |||
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod | |||
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress | |||
* @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method still seems to return void
.
|
||
namespace Magento\CheckoutAgreements\Model; | ||
|
||
class CheckoutAgreementsList implements \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class description or inheritdoc would be worth adding here.
$storeFilterMock = $this->createMock(\Magento\Framework\Api\Filter::class); | ||
$activeFilterMock = $this->createMock(\Magento\Framework\Api\Filter::class); | ||
|
||
$this->filterBuilderMock->expects($this->at(0))->method('setField')->with('store_id')->willReturnSelf(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of test looks like it is intended to freeze code state but not ensure quality.
I would suggest using other approaches or even test types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic also covered with integration test \Magento\CheckoutAgreements\Model\Checkout\Plugin\GuestValidationTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unit test may be redundant in this case. You may remove it or leave as is.
ff20fff
to
3dc9dc5
Compare
Description
Introduced new listing interface for Checkout Agreements with ability to set search criteria.
Manual testing scenarios
Contribution checklist