-
Notifications
You must be signed in to change notification settings - Fork 661
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
PurchaceFlowの実装 #2424
Merged
chihiro-adachi
merged 75 commits into
EC-CUBE:experimental/3.1
from
chihiro-adachi:experimental/purchase-flow
Jul 24, 2017
Merged
PurchaceFlowの実装 #2424
chihiro-adachi
merged 75 commits into
EC-CUBE:experimental/3.1
from
chihiro-adachi:experimental/purchase-flow
Jul 24, 2017
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jul 24, 2017
Closed
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概要(Overview・Refs Issue)
受注・受注明細を抽象化し、バリデーションや明細の丸め処理、集計処理を、カート/購入確認画面/受注登録・編集画面で共通して利用できるように整備しました
方針(Policy)
集計処理や、在庫チェックなどのバリデーションは、受注に関わる共通したロジックです。
従来は、CartServiceやShoppingServiceなど、利用される画面で個別に実装されており、カスタマイズ時の影響が読みづらい、再利用しにくいなどの課題がありました(たとえば、配送料の計算ロジックを変更する際には複数箇所を修正する必要があります)
集計フローを制御するPurchaseFlowと、各処理を行うProcessorに分離し、ロジックを差し替えたり、新たなバリデーションを追加したりなどが簡易に行えるように変更しました。
実装に関する補足(Appendix)
アクティビティ
全体のアクティビティは以下の通りです。
フローの制御の流れ
カートを例にすると、集計処理やバリデーションは以下のように実行されています。
現在の
状態をチェックする(明細単位で整合性を担保する)現在の
状態をチェックする(明細全体で整合性を担保する)クラス図
全体のクラス構成を以下に記載します。
主要なクラスの役割は以下の通りです。
ItemIHoldernterface
明細一覧(明細のサマリ)を表すインターフェース。
CartやOrderが実装クラスとなります。
ItemInterface
明細を表すインターフェース。
CartItemやShipmentItemが実装クラスとなります。
PurchaseFlow
明細処理や集計処理の全体のフローを制御するクラスです。
PurchaseFlowは、集計を行うcalculate()と完了処理を行うpurchase()メソッドを持っています。
メソッドが実行されると、ItemやItemHolderをProcessorに渡し、Processorを順次実行していきます。また、Processorの実行結果を呼び出し元に返却します。
ItemHolderProcessor
ItemHolder(OrderやCart)に対して処理を実行するProcessorです
支払方法の整合性チェックや、購入金額上限チェックが該当します。
ItemProcessor
Itemに対して処理を実行するProcessorです。
在庫チェックや販売制限数のチェックが該当します。
PurchaseProcessor
完了処理を行うタイミングで呼び出されるProcessorです。
ItemHolderに対して処理を行います。また、PurchaseContextを通じて、変更前のItemHolderを取得することもできます。
PurchaseContext
実行時の情報を持つクラスです。
呼び出し側のコントローラで、Contextに情報が追加すると、各Processorからアクセスすることができます。
PurchaseFlowResult
PurchaseFlowの実行結果を保持しています。
ItemProcessorで発生したエラーはWarning、ItemHolderProcessorで発生したエラーはErrorとして扱います。
Processorの拡張サンプル
Processorの拡張サンプルを以下にコミットしています。
e8faad2