-
Notifications
You must be signed in to change notification settings - Fork 4
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
Extend the functionality #1
base: master
Are you sure you want to change the base?
Conversation
justd88
commented
Oct 7, 2018
- If the order is virtual then create the invoice automatically and set the order status to complete
- Add frontend comment before redirect to the OTP. ( The admin can leave a note for the users about the redirect etc. )
Add Order status to complete if the order is virtual.
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 a good feature. Thanks for the contribution.
Before merge there are things should be changed first:
- There are double empty lines, missing empty lines, not well alignments, PSR should be followed
- missing dock blocks
- If you feel this PR is too big, it could be split to two parts (invoicing and information text on checkout)
- I added other comments to the PR inline.
Helper/Config.php
Outdated
/** | ||
* @return string | ||
*/ | ||
public function getFrontendComment() |
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.
Return type declaration is missing from here:
public function getFrontendComment(): string
Model/Order/StatusUpdater.php
Outdated
/** | ||
* @param Order $order | ||
*/ | ||
private function createInvoice(Order $order) |
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 think the createInvoice method shouldn't be part of this StatusUpdater. StatusUpdater is responsible only for updating statuses and states of order, this class is already too big.
The order related things should be in Order namespace and Invoice related thing outside of Order namespace, for example: \Youama\OTP\Model\Invoice\StatusUpdater. The invoice updater could be injected to order updater through the constructor.
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.
Fixed, Sorry I was very busy... but now back on track :)
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.
No need to sorry, there are no deadlines :)
@@ -87,6 +87,12 @@ | |||
<label>Shop Comment</label> | |||
<comment>Short text about the webshop or order on the OTP payment user interface.</comment> | |||
</field> | |||
<field id="frontend_comment" translate="label" type="textarea" sortOrder="90" showInDefault="1" |
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 should be defined in config.xml too because of when admin does not click on save button in module settings area after module installation, there will be no default value. Config.xml contains default values.
composer.json
Outdated
@@ -2,7 +2,7 @@ | |||
"name": "youama/module-otp-2", | |||
"description": "OTP Payment integration for Magento 2", | |||
"type": "magento2-module", | |||
"version": "1.0.5", | |||
"version": "1.0.6", |
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 could be 1.1.0, because of this is a new feature. I would also increase the setup version to make consistent the module version number to the composer package version number.
Model/Order/StatusUpdater.php
Outdated
*/ | ||
public function __construct( | ||
OrderRepositoryInterface $orderRepository, | ||
OrderFinderInterface $orderFinder, | ||
OrderStatusHistoryInterfaceFactory $orderStatusHistoryInterfaceFactory, | ||
OrderCommentSender $orderCommentSender, | ||
Config $configHelper | ||
Config $configHelper, | ||
\Magento\Sales\Model\Service\InvoiceService $invoiceService, |
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.
FQN should be used, because of this module use FQN almost everywhere, except those parts where Magento's magic functionalities require the full import path.
Instead of this:
\Magento\Sales\Model\Service\InvoiceService $invoiceService,
Use this:
InvoiceService $invoiceService,
Model/Order/StatusUpdater.php
Outdated
|
||
|
||
/** Create Invoice if order was virtual */ | ||
if ($order->getIsVirtual()) { |
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.
There should be a config checking here to check if admin approved the invoicing in the store. Many of shop owners don't want to create invoice inside Magento for different reasons.
/** | ||
* Put order to processing, notify customer about it. | ||
* | ||
* @param string $orderIncrementId | ||
* @param int $transactionId |
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.
Dockblock param list should be aligned to each other.
Hi David! I made some changes. Can you have a look pls and let me know if anything wrong? |
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've just found 3 things. I think it can be merged after you modify these.
Model/Invoice/StatusUpdater.php
Outdated
/** | ||
* @var InvoiceService | ||
*/ | ||
protected $invoiceService; |
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.
These fields don't have to be protected, they can be private according to SOLID principles. Same in Order's StatusUpdater.
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.
Fixed
|
||
$order->addStatusHistory($history); | ||
$order->setStatus(Order::STATE_COMPLETE); | ||
$this->orderRepository->save($order); |
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.
At this point this is a second order saving in the success flow. This method createInvoice has called at the end of the Order's StatusUpdater::success where the order already has been saved.
Is there any reason why is get two saves? If order save is required after invoice saving then I think this createInvoice could be easily before the order saving.
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.
That is a good point. shall I pass the order as a pointer?
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 think it's not necessary, the $order already points back because objects are reference types.
Model/Invoice/StatusUpdater.php
Outdated
/** | ||
* Youama_OTP | ||
* | ||
* @author David Belicza <[email protected]> |
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.
In any file what you created, you can add your own name, real one or nickname and your own email address if you want, instead of mine because you are the author of those files. :) (The other parts like license should be the same as it was before.)
You can append your name to the other files what you just modified, it is valid in PHPDoc:
@author David Belicza <[email protected]>
@author Other Author <[email protected]>