Skip to content

Commit

Permalink
Merge pull request #2424 from chihiro-adachi/experimental/purchase-flow
Browse files Browse the repository at this point in the history
PurchaceFlowの実装
  • Loading branch information
Chihiro Adachi authored Jul 24, 2017
2 parents 9655114 + 335bbdd commit 751c7ac
Show file tree
Hide file tree
Showing 72 changed files with 4,477 additions and 2,071 deletions.
39 changes: 39 additions & 0 deletions app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php
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;
}
}
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;
}
);
}
}
5 changes: 5 additions & 0 deletions app/Plugin/FormExtension/config.yml
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 app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php
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();
}
}
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);
}
}
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;
}
);
}
}
5 changes: 5 additions & 0 deletions app/Plugin/PurchaseProcessors/config.yml
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"fzaninotto/faker":"1.5.*",
"phing/phing": "2.*",
"symfony/browser-kit": "3.3.*",
"friendsofphp/php-cs-fixer": "^1.11",
"friendsofphp/php-cs-fixer": "^2.2",
"satooshi/php-coveralls": "2.0.x-dev"
},
"autoload": {
Expand Down
Loading

0 comments on commit 751c7ac

Please sign in to comment.