-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2424 from chihiro-adachi/experimental/purchase-flow
PurchaceFlowの実装
- Loading branch information
Showing
72 changed files
with
4,477 additions
and
2,071 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Plugin\FormExtension\Form\Extension; | ||
|
||
use Eccube\Form\Type\Front\EntryType; | ||
use Eccube\Form\Type\Master\JobType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
||
class EntryTypeExtension extends AbstractTypeExtension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
// 職業を必須項目に変更するサンプル | ||
$builder->remove('job'); | ||
$builder->add( | ||
'job', | ||
JobType::class, | ||
[ | ||
'required' => true, | ||
'constraints' => [ | ||
new NotBlank(), | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getExtendedType() | ||
{ | ||
return EntryType::class; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/Plugin/FormExtension/ServiceProvider/FormExtensionServiceProvider.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Plugin\FormExtension\ServiceProvider; | ||
|
||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
use Plugin\FormExtension\Form\Extension\EntryTypeExtension; | ||
|
||
class FormExtensionServiceProvider implements ServiceProviderInterface | ||
{ | ||
public function register(Container $app) | ||
{ | ||
$app->extend( | ||
'form.type.extensions', | ||
function ($extensions) { | ||
$extensions[] = new EntryTypeExtension(); | ||
|
||
return $extensions; | ||
} | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: FormExtensionのサンプル | ||
code: FormExtension | ||
version: 1.0.0 | ||
service: | ||
- FormExtensionServiceProvider |
22 changes: 22 additions & 0 deletions
22
app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Plugin\PurchaseProcessors\Processor; | ||
|
||
use Eccube\Entity\ItemInterface; | ||
use Eccube\Service\PurchaseFlow\ItemProcessor; | ||
use Eccube\Service\PurchaseFlow\PurchaseContext; | ||
use Eccube\Service\PurchaseFlow\ProcessResult; | ||
|
||
class EmptyProcessor implements ItemProcessor | ||
{ | ||
/** | ||
* @param ItemInterface $item | ||
* @param PurchaseContext $context | ||
* @return ProcessResult | ||
*/ | ||
public function process(ItemInterface $item, PurchaseContext $context) | ||
{ | ||
log_info('empty processor executed', [__METHOD__]); | ||
return ProcessResult::success(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Plugin\PurchaseProcessors\Processor; | ||
|
||
use Eccube\Entity\ItemInterface; | ||
use Eccube\Service\PurchaseFlow\ItemValidateException; | ||
use Eccube\Service\PurchaseFlow\PurchaseContext; | ||
use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; | ||
|
||
class ValidatableEmptyProcessor extends ValidatableItemProcessor | ||
{ | ||
protected function validate(ItemInterface $item, PurchaseContext $context) | ||
{ | ||
$error = false; | ||
if ($error) { | ||
throw new ItemValidateException('ValidatableEmptyProcessorのエラーです'); | ||
} | ||
} | ||
|
||
protected function handle(ItemInterface $item, PurchaseContext $context) | ||
{ | ||
$item->setQuantity(100); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/Plugin/PurchaseProcessors/ServiceProvider/PurchaseProcessorsServiceProvider.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Plugin\PurchaseProcessors\ServiceProvider; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Pimple\Container; | ||
use Pimple\ServiceProviderInterface; | ||
use Plugin\PurchaseProcessors\Processor\EmptyProcessor; | ||
use Plugin\PurchaseProcessors\Processor\ValidatableEmptyProcessor; | ||
|
||
class PurchaseProcessorsServiceProvider implements ServiceProviderInterface | ||
{ | ||
public function register(Container $app) | ||
{ | ||
$app->extend( | ||
'eccube.purchase.flow.cart.item_processors', | ||
function (ArrayCollection $processors, Container $app) { | ||
$processors[] = new EmptyProcessor(); | ||
$processors[] = new ValidatableEmptyProcessor(); | ||
return $processors; | ||
} | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: PurchaseFlowにProcessorを追加するサンプル | ||
code: PurchaseProcessors | ||
version: 1.0.0 | ||
service: | ||
- PurchaseProcessorsServiceProvider |
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
Oops, something went wrong.