Skip to content
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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

justd88
Copy link

@justd88 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. )

@DavidBelicza DavidBelicza self-requested a review October 8, 2018 09:18
Copy link
Owner

@DavidBelicza DavidBelicza left a 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.

/**
* @return string
*/
public function getFrontendComment()
Copy link
Owner

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

/**
* @param Order $order
*/
private function createInvoice(Order $order)
Copy link
Owner

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.

Copy link
Author

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 :)

Copy link
Owner

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"
Copy link
Owner

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",
Copy link
Owner

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.

*/
public function __construct(
OrderRepositoryInterface $orderRepository,
OrderFinderInterface $orderFinder,
OrderStatusHistoryInterfaceFactory $orderStatusHistoryInterfaceFactory,
OrderCommentSender $orderCommentSender,
Config $configHelper
Config $configHelper,
\Magento\Sales\Model\Service\InvoiceService $invoiceService,
Copy link
Owner

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,



/** Create Invoice if order was virtual */
if ($order->getIsVirtual()) {
Copy link
Owner

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
Copy link
Owner

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.

@justd88
Copy link
Author

justd88 commented Oct 19, 2018

Hi David! I made some changes. Can you have a look pls and let me know if anything wrong?
Thank you!

Copy link
Owner

@DavidBelicza DavidBelicza left a 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.

/**
* @var InvoiceService
*/
protected $invoiceService;
Copy link
Owner

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.

Copy link
Author

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);
Copy link
Owner

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.

Copy link
Author

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?

Copy link
Owner

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.

/**
* Youama_OTP
*
* @author David Belicza <[email protected]>
Copy link
Owner

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]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants