Skip to content

Commit

Permalink
プラグインからの追加サンプル
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed Jul 20, 2017
1 parent 06267a4 commit e8faad2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Plugin\PurchaseProcessors\Processor;

use Eccube\Entity\ItemInterface;
use Eccube\Service\PurchaseFlow\ItemProcessor;
use Eccube\Service\PurchaseFlow\ProcessResult;

class EmptyProcessor implements ItemProcessor
{
/**
* @param ItemInterface $item
* @return ProcessResult
*/
public function process(ItemInterface $item)
{
log_info('empty processor executed', [__METHOD__]);
return ProcessResult::success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Plugin\PurchaseProcessors\Processor;

use Eccube\Entity\ItemInterface;
use Eccube\Service\PurchaseFlow\ItemValidateException;
use Eccube\Service\PurchaseFlow\ValidatableItemProcessor;

class ValidatableEmptyProcessor extends ValidatableItemProcessor
{
protected function validate(ItemInterface $item)
{
$error = false;
if ($error) {
throw new ItemValidateException('ValidatableEmptyProcessorのエラーです');
}
}

protected function handle(ItemInterface $item)
{
$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

0 comments on commit e8faad2

Please sign in to comment.