From 5992b4733755883ad479ccc1704daf85c08e3535 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Mon, 3 Jul 2017 15:58:24 +0900 Subject: [PATCH 01/75] purchaseFlow --- src/Eccube/Entity/ItemHolderInterface.php | 11 ++++ src/Eccube/Service/ItemHolderProcessor.php | 11 ++++ src/Eccube/Service/ItemProcessor.php | 9 ++++ src/Eccube/Service/PurchaseFlow.php | 28 ++++++++++ .../ValidatableItemHolderProcessor.php | 14 +++++ .../Eccube/Tests/Service/PurchaseFlowTest.php | 53 +++++++++++++++++++ .../Service/ValidatablelderProcessorTest.php | 18 +++++++ 7 files changed, 144 insertions(+) create mode 100644 src/Eccube/Entity/ItemHolderInterface.php create mode 100644 src/Eccube/Service/ItemHolderProcessor.php create mode 100644 src/Eccube/Service/ItemProcessor.php create mode 100644 src/Eccube/Service/PurchaseFlow.php create mode 100644 src/Eccube/Service/ValidatableItemHolderProcessor.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlowTest.php create mode 100644 tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php new file mode 100644 index 00000000000..983af00d132 --- /dev/null +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -0,0 +1,11 @@ +itemHolderProsessors[] = $prosessor; + } + + public function addItemProcessor(ItemProcessor $prosessor) + { + $this->itemProsessors[] = $prosessor; + } +} \ No newline at end of file diff --git a/src/Eccube/Service/ValidatableItemHolderProcessor.php b/src/Eccube/Service/ValidatableItemHolderProcessor.php new file mode 100644 index 00000000000..c7c71624835 --- /dev/null +++ b/src/Eccube/Service/ValidatableItemHolderProcessor.php @@ -0,0 +1,14 @@ +flow = new PurchaseFlow(); + } + + public function testExecute() + { + + $this->assertInstanceOf(PurchaseFlow::class, $this->flow); + + $itemHolder = new Cart(); + $this->assertEquals($itemHolder, $this->flow->execute($itemHolder)); + } + + public function testAddProcesser() + { + $processor = new PurchaseFlowTest_HogeProcessor(); + $this->flow->addItemHolderProcessor($processor); + + $processor = new PurchaseFlowTest_FugaProcessor(); + $this->flow->addItemProcessor($processor); + } +} + +class PurchaseFlowTest_HogeProcessor implements ItemHolderProcessor +{ + public function process(ItemHolderInterface $itemHolder) + { + // TODO: Implement process() method. + } +} + +class PurchaseFlowTest_FugaProcessor implements ItemProcessor +{ + +} \ No newline at end of file diff --git a/tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php b/tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php new file mode 100644 index 00000000000..0e5f6c44f97 --- /dev/null +++ b/tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php @@ -0,0 +1,18 @@ + Date: Mon, 3 Jul 2017 15:59:00 +0900 Subject: [PATCH 02/75] cart --- src/Eccube/Entity/Cart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 17230235694..7107040d123 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -24,7 +24,7 @@ namespace Eccube\Entity; -class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface +class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface { /** * @var bool @@ -266,4 +266,8 @@ public function setPayments($payments) return $this; } + public function addError($error) + { + // TODO: Implement addError() method. + } } From 52c07df9f6da97c36f9e316d89075733f14f13a0 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Mon, 3 Jul 2017 16:47:45 +0900 Subject: [PATCH 03/75] =?UTF-8?q?ValidatableItemProcessor=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 22 +++- src/Eccube/Entity/ItemHolderInterface.php | 13 ++- src/Eccube/Service/ItemProcessor.php | 4 +- src/Eccube/Service/ItemValidateException.php | 30 +++++ src/Eccube/Service/PurchaseFlow.php | 9 ++ .../Service/ValidatableItemProcessor.php | 51 ++++++++ .../Eccube/Tests/Service/PurchaseFlowTest.php | 71 +++++++++++- ...=> ValidatableItemHolderProcessorTest.php} | 2 +- .../Service/ValidatableItemProcessorTest.php | 109 ++++++++++++++++++ 9 files changed, 304 insertions(+), 7 deletions(-) create mode 100644 src/Eccube/Service/ItemValidateException.php create mode 100644 src/Eccube/Service/ValidatableItemProcessor.php rename tests/Eccube/Tests/Service/{ValidatablelderProcessorTest.php => ValidatableItemHolderProcessorTest.php} (70%) create mode 100644 tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 7107040d123..453e14f2331 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -24,6 +24,8 @@ namespace Eccube\Entity; +use Eccube\Service\ItemValidateException; + class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface { /** @@ -52,6 +54,11 @@ class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, I */ private $Payments = array(); + /** + * @var ItemValidateException[] + */ + private $errors = []; + public function __construct() { $this->CartItems = new \Doctrine\Common\Collections\ArrayCollection(); @@ -266,8 +273,19 @@ public function setPayments($payments) return $this; } - public function addError($error) + /** + * @param $error + */ + public function addError(ItemValidateException $error) + { + $this->errors[] = $error; + } + + /** + * @return ItemValidateException[] + */ + public function getErrors() { - // TODO: Implement addError() method. + return $this->errors; } } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index 983af00d132..c5b34d376a2 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -3,9 +3,20 @@ namespace Eccube\Entity; +use Eccube\Service\ItemValidateException; + interface ItemHolderInterface { - public function addError($error); + /** + * @param ItemValidateException $error + * @return void + */ + public function addError(ItemValidateException $error); public function getItems(); + + /** + * @return ItemValidateException[] + */ + public function getErrors(); } \ No newline at end of file diff --git a/src/Eccube/Service/ItemProcessor.php b/src/Eccube/Service/ItemProcessor.php index cdf0b981dea..e94a3407711 100644 --- a/src/Eccube/Service/ItemProcessor.php +++ b/src/Eccube/Service/ItemProcessor.php @@ -3,7 +3,9 @@ namespace Eccube\Service; +use Eccube\Entity\ItemInterface; + interface ItemProcessor { - + public function process(ItemInterface $item); } \ No newline at end of file diff --git a/src/Eccube/Service/ItemValidateException.php b/src/Eccube/Service/ItemValidateException.php new file mode 100644 index 00000000000..75500690a18 --- /dev/null +++ b/src/Eccube/Service/ItemValidateException.php @@ -0,0 +1,30 @@ +getItems() as $item) { + foreach ($this->itemProsessors as $itemProsessor) { + try { + $itemProsessor->process($item); + } catch (ItemValidateException $exception) { + $itemHolder->addError($exception); + } + } + } return $itemHolder; } diff --git a/src/Eccube/Service/ValidatableItemProcessor.php b/src/Eccube/Service/ValidatableItemProcessor.php new file mode 100644 index 00000000000..54ab99940e6 --- /dev/null +++ b/src/Eccube/Service/ValidatableItemProcessor.php @@ -0,0 +1,51 @@ +validate($item); + } catch (ItemValidateException $e) { + if ($item instanceof CartItem) { + $this->handle($item); + } + throw $e; + } + } + + protected abstract function validate(ItemInterface $item); + + protected function handle(ItemInterface $item) {} +} \ No newline at end of file diff --git a/tests/Eccube/Tests/Service/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlowTest.php index c74ec1ce4c6..7dbb367743a 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlowTest.php @@ -3,14 +3,21 @@ namespace Eccube\Tests\Service; use Eccube\Entity\Cart; +use Eccube\Entity\CartItem; use Eccube\Entity\ItemHolderInterface; +use Eccube\Entity\ItemInterface; use Eccube\Service\ItemHolderProcessor; use Eccube\Service\ItemProcessor; +use Eccube\Service\ItemValidateException; use Eccube\Service\PurchaseFlow; +use Eccube\Service\ValidatableItemProcessor; use Eccube\Tests\EccubeTestCase; class PurchaseFlowTest extends EccubeTestCase { + /** + * @var PurchaseFlow $flow + */ protected $flow; public function setUp() @@ -37,17 +44,77 @@ public function testAddProcesser() $processor = new PurchaseFlowTest_FugaProcessor(); $this->flow->addItemProcessor($processor); } + + public function testProcessItemProcessors() + { + $this->flow->addItemProcessor(new PurchaseFlowTest_FugaProcessor()); + $itemHolder = new Cart(); + + self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + } + + public function testProcessItemProcessors_validationErrors() + { + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); + $itemHolder = new Cart(); + $itemHolder->addCartItem(new CartItem()); + + self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + + self::assertEquals([ + "error 1", "error 2" + ], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); + } + + public function testProcessItemProcessors_validationErrors_with_multi_items() + { + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); + $itemHolder = new Cart(); + $itemHolder->addCartItem(new CartItem()); + $itemHolder->addCartItem(new CartItem()); + + self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + + self::assertEquals([ + "error 1", "error 2", "error 1", "error 2" + ], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); + } + } class PurchaseFlowTest_HogeProcessor implements ItemHolderProcessor { public function process(ItemHolderInterface $itemHolder) { - // TODO: Implement process() method. } } + class PurchaseFlowTest_FugaProcessor implements ItemProcessor { -} \ No newline at end of file + public function process(ItemInterface $item) + { + } +} + +class PurchaseFlowTest_FailProcessor extends ValidatableItemProcessor +{ + private $errorMessage; + + /** + * PurchaseFlowTest_FailProcessor constructor. + * @param $errorMessage + */ + public function __construct($errorMessage) + { + $this->errorMessage = $errorMessage; + } + + protected function validate(ItemInterface $item) + { + throw new ItemValidateException($this->errorMessage); + } +} diff --git a/tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php b/tests/Eccube/Tests/Service/ValidatableItemHolderProcessorTest.php similarity index 70% rename from tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php rename to tests/Eccube/Tests/Service/ValidatableItemHolderProcessorTest.php index 0e5f6c44f97..41c20be0261 100644 --- a/tests/Eccube/Tests/Service/ValidatablelderProcessorTest.php +++ b/tests/Eccube/Tests/Service/ValidatableItemHolderProcessorTest.php @@ -9,7 +9,7 @@ namespace Eccube\Tests\Service; -class ValidatablelderProcessorTest extends \PHPUnit_Framework_TestCase +class ValidatableItemHolderProcessorTest extends \PHPUnit_Framework_TestCase { public function testHoge() { diff --git a/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php new file mode 100644 index 00000000000..1e62769a577 --- /dev/null +++ b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php @@ -0,0 +1,109 @@ +process($item); + $this->assertFalse($validator->handleCalled); + } + + public function testValidateCartFail() + { + $validator = new ValidatableItemProcessorTest_FailValidator(); + $item = new CartItem(); + + $validator->process($item); + $this->assertTrue($validator->handleCalled); + } + + public function testValidateOrderSuccess() + { + $validator = new ValidatableItemProcessorTest_NormalValidator(); + $item = new ShipmentItem(); + + $validator->process($item); + $this->assertFalse($validator->handleCalled); + } + + public function testValidateOrderFail() + { + $validator = new ValidatableItemProcessorTest_FailValidator(); + $item = new ShipmentItem(); + + $validator->process($item); + $this->assertFalse($validator->handleCalled); + } +} + +class ValidatableItemProcessorTest_NormalValidator extends ValidatableItemProcessor +{ + + public $handleCalled = false; + + protected function validate(ItemInterface $item) {} + + protected function handle(ItemInterface $item) + { + $this->handleCalled = true; + } +} + +class ValidatableItemProcessorTest_FailValidator extends ValidatableItemProcessor +{ + + public $handleCalled = false; + + protected function validate(ItemInterface $item) + { + throw new ItemValidateException(); + } + + protected function handle(ItemInterface $item) + { + $this->handleCalled = true; + } + +} \ No newline at end of file From 2fe8b2e5fb594a80ce538a432b19efac7af62f46 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 3 Jul 2017 18:05:10 +0900 Subject: [PATCH 04/75] Add StockValidator --- src/Eccube/Service/PurchaseFlow.php | 11 +++- src/Eccube/Service/StockValidator.php | 22 ++++++++ .../ValidatableItemHolderProcessor.php | 21 +++++-- .../Eccube/Tests/Service/PurchaseFlowTest.php | 52 +++++++++++++++-- .../Tests/Service/StockValidatorTest.php | 56 +++++++++++++++++++ 5 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 src/Eccube/Service/StockValidator.php create mode 100644 tests/Eccube/Tests/Service/StockValidatorTest.php diff --git a/src/Eccube/Service/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow.php index 99d7fb59123..fdd86c99b9d 100644 --- a/src/Eccube/Service/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow.php @@ -21,6 +21,15 @@ public function execute(ItemHolderInterface $itemHolder) { $itemHolder->addError($exception); } } + + } + + foreach ($this->itemHolderProsessors as $holderProcessor) { + try { + $holderProcessor->process($itemHolder); + } catch (ItemValidateException $exception) { + $itemHolder->addError($exception); + } } return $itemHolder; } @@ -34,4 +43,4 @@ public function addItemProcessor(ItemProcessor $prosessor) { $this->itemProsessors[] = $prosessor; } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/StockValidator.php b/src/Eccube/Service/StockValidator.php new file mode 100644 index 00000000000..f46233988bc --- /dev/null +++ b/src/Eccube/Service/StockValidator.php @@ -0,0 +1,22 @@ +getObject()->getStock(); + $quantity = $item->getQuantity(); + if ($stock < $quantity) { + throw new ItemValidateException(); + } + } + + protected function handle(ItemInterface $item) { + $stock = $item->getObject()->getStock(); + $item->setQuantity($stock); + } +} diff --git a/src/Eccube/Service/ValidatableItemHolderProcessor.php b/src/Eccube/Service/ValidatableItemHolderProcessor.php index c7c71624835..4d5070142d0 100644 --- a/src/Eccube/Service/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/ValidatableItemHolderProcessor.php @@ -2,13 +2,24 @@ namespace Eccube\Service; - +use Eccube\Entity\Cart; use Eccube\Entity\ItemHolderInterface; -abstract class ValidatablelderProcessor implements ItemHolderProcessor +abstract class ValidatableItemHolderProcessor implements ItemHolderProcessor { - public function process(ItemHolderInterface $itemHolder) + public final function process(ItemHolderInterface $itemHolder) { - + try { + $this->validate($itemHolder); + } catch (ItemValidateException $e) { + if ($itemHolder instanceof Cart) { + $this->handle($itemHolder); + } + throw $e; + } } -} \ No newline at end of file + + protected abstract function validate(ItemHolderInterface $item); + + protected function handle(ItemHolderInterface $item) {} +} diff --git a/tests/Eccube/Tests/Service/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlowTest.php index 7dbb367743a..8c4c8062b4c 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlowTest.php @@ -11,6 +11,7 @@ use Eccube\Service\ItemValidateException; use Eccube\Service\PurchaseFlow; use Eccube\Service\ValidatableItemProcessor; +use Eccube\Service\ValidatableItemHolderProcessor; use Eccube\Tests\EccubeTestCase; class PurchaseFlowTest extends EccubeTestCase @@ -20,6 +21,8 @@ class PurchaseFlowTest extends EccubeTestCase */ protected $flow; + protected $Product; + public function setUp() { parent::setUp(); @@ -38,19 +41,36 @@ public function testExecute() public function testAddProcesser() { - $processor = new PurchaseFlowTest_HogeProcessor(); + $processor = new PurchaseFlowTest_ItemHolderProcessor(); $this->flow->addItemHolderProcessor($processor); - $processor = new PurchaseFlowTest_FugaProcessor(); + $processor = new PurchaseFlowTest_ItemProcessor(); $this->flow->addItemProcessor($processor); } public function testProcessItemProcessors() { - $this->flow->addItemProcessor(new PurchaseFlowTest_FugaProcessor()); + $this->flow->addItemProcessor(new PurchaseFlowTest_ItemProcessor()); + $itemHolder = new Cart(); + + self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + } + + public function testProcessItemHolderProcessor() + { + $this->flow->addItemHolderProcessor(new PurchaseFlowTest_ItemHolderProcessor()); + $itemHolder = new Cart(); + + self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + } + + public function testProcessItemHolderProcessor_validationErrors() + { + $this->flow->addItemHolderProcessor(new PurchaseFlowTest_FailItemHolderProcessor('error 1')); $itemHolder = new Cart(); self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + self::assertEquals(['error 1'], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); } public function testProcessItemProcessors_validationErrors() @@ -84,15 +104,14 @@ public function testProcessItemProcessors_validationErrors_with_multi_items() } -class PurchaseFlowTest_HogeProcessor implements ItemHolderProcessor +class PurchaseFlowTest_ItemHolderProcessor implements ItemHolderProcessor { public function process(ItemHolderInterface $itemHolder) { } } - -class PurchaseFlowTest_FugaProcessor implements ItemProcessor +class PurchaseFlowTest_ItemProcessor implements ItemProcessor { public function process(ItemInterface $item) @@ -118,3 +137,24 @@ protected function validate(ItemInterface $item) throw new ItemValidateException($this->errorMessage); } } + +class PurchaseFlowTest_FailItemHolderProcessor extends ValidatableItemHolderProcessor +{ + private $errorMessage; + + /** + * PurchaseFlowTest_FailProcessor constructor. + * @param $errorMessage + */ + public function __construct($errorMessage) + { + $this->errorMessage = $errorMessage; + } + + protected function validate(ItemHolderInterface $item) + { + // TODO ItemHolerValidateException が必要か検討 + throw new ItemValidateException($this->errorMessage); + } +} + diff --git a/tests/Eccube/Tests/Service/StockValidatorTest.php b/tests/Eccube/Tests/Service/StockValidatorTest.php new file mode 100644 index 00000000000..ae02532fcc2 --- /dev/null +++ b/tests/Eccube/Tests/Service/StockValidatorTest.php @@ -0,0 +1,56 @@ +Product = $this->createProduct('テスト商品', 1); + $this->validator = new StockValidator(); + $this->cartItem = new CartItem(); + $this->cartItem->setObject($this->Product->getProductClasses()[0]); + } + + public function testInstance() + { + self::assertInstanceOf(StockValidator::class, $this->validator); + self::assertSame($this->Product->getProductClasses()[0], $this->cartItem->getObject()); + } + + public function testValidStock() + { + $this->cartItem->setQuantity(1); + $this->validator->process($this->cartItem); + self::assertEquals(1, $this->cartItem->getQuantity()); + } + + public function testValidStockFail() + { + $this->cartItem->setQuantity(PHP_INT_MAX); + try { + $this->validator->process($this->cartItem); + self::fail('エラーチェックに失敗しました'); + } catch (ItemValidateException $e) { + self::assertEquals($this->Product->getProductClasses()[0]->getStock(), $this->cartItem->getQuantity()); + } + } +} From 3be35276f134373340b06b2b0714a28e253ece8b Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 4 Jul 2017 09:36:45 +0900 Subject: [PATCH 05/75] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/ValidatableItemProcessorTest.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php index 1e62769a577..99b126e25bf 100644 --- a/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php @@ -55,8 +55,12 @@ public function testValidateCartFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new CartItem(); - $validator->process($item); - $this->assertTrue($validator->handleCalled); + try { + $validator->process($item); + self::fail(); + } catch (ItemValidateException $e) { + $this->assertTrue($validator->handleCalled); + } } public function testValidateOrderSuccess() @@ -73,8 +77,12 @@ public function testValidateOrderFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new ShipmentItem(); - $validator->process($item); - $this->assertFalse($validator->handleCalled); + try { + $validator->process($item); + self::fail(); + } catch (ItemValidateException $e) { + $this->assertFalse($validator->handleCalled); + } } } @@ -83,7 +91,9 @@ class ValidatableItemProcessorTest_NormalValidator extends ValidatableItemProces public $handleCalled = false; - protected function validate(ItemInterface $item) {} + protected function validate(ItemInterface $item) + { + } protected function handle(ItemInterface $item) { From f4a4a466747f920ab01d6dffec39fa2e1a50fbc2 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 4 Jul 2017 09:58:06 +0900 Subject: [PATCH 06/75] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=81StockValidator=E3=82=92=E5=8F=97=E6=B3=A8?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/CartItem.php | 8 +++++ src/Eccube/Entity/ItemInterface.php | 5 +++ src/Eccube/Entity/Order.php | 20 ++++++++++- src/Eccube/Service/StockValidator.php | 4 +-- .../Tests/Service/StockValidatorTest.php | 34 +++++++++++++------ 5 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/Eccube/Entity/CartItem.php b/src/Eccube/Entity/CartItem.php index 018ce745991..d80904c0dc0 100644 --- a/src/Eccube/Entity/CartItem.php +++ b/src/Eccube/Entity/CartItem.php @@ -201,4 +201,12 @@ public function getOrderItemType() $ItemType = new \Eccube\Entity\Master\OrderItemType(); return $ItemType; } + + /** + * @return ProductClass + */ + public function getProductClass() + { + return $this->getObject(); + } } diff --git a/src/Eccube/Entity/ItemInterface.php b/src/Eccube/Entity/ItemInterface.php index 33b072e9547..44e237e1a9d 100644 --- a/src/Eccube/Entity/ItemInterface.php +++ b/src/Eccube/Entity/ItemInterface.php @@ -39,4 +39,9 @@ public function isDiscount(); public function isTax(); public function getOrderItemType(); + + /** + * @return ProductClass + */ + public function getProductClass(); } diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 1f48de0033e..20f82a24d93 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -26,6 +26,7 @@ use Eccube\Common\Constant; use Eccube\Service\Calculator\ShipmentItemCollection; +use Eccube\Service\ItemValidateException; use Eccube\Util\EntityUtil; use Eccube\Entity\Master\OrderItemType; use Doctrine\ORM\Mapping as ORM; @@ -39,7 +40,7 @@ * @ORM\HasLifecycleCallbacks() * @ORM\Entity(repositoryClass="Eccube\Repository\OrderRepository") */ -class Order extends \Eccube\Entity\AbstractEntity implements PurchaseInterface +class Order extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface { /** * isMultiple @@ -1870,4 +1871,21 @@ public function getOrderStatus() { return $this->OrderStatus; } + + /** + * @param ItemValidateException $error + * @return void + */ + public function addError(ItemValidateException $error) + { + // TODO: Implement addError() method. + } + + /** + * @return ItemValidateException[] + */ + public function getErrors() + { + // TODO: Implement getErrors() method. + } } diff --git a/src/Eccube/Service/StockValidator.php b/src/Eccube/Service/StockValidator.php index f46233988bc..cffad79e0ea 100644 --- a/src/Eccube/Service/StockValidator.php +++ b/src/Eccube/Service/StockValidator.php @@ -8,7 +8,7 @@ class StockValidator extends ValidatableItemProcessor { protected function validate(ItemInterface $item) { - $stock = $item->getObject()->getStock(); + $stock = $item->getProductClass()->getStock(); $quantity = $item->getQuantity(); if ($stock < $quantity) { throw new ItemValidateException(); @@ -16,7 +16,7 @@ protected function validate(ItemInterface $item) } protected function handle(ItemInterface $item) { - $stock = $item->getObject()->getStock(); + $stock = $item->getProductClass()->getStock(); $item->setQuantity($stock); } } diff --git a/tests/Eccube/Tests/Service/StockValidatorTest.php b/tests/Eccube/Tests/Service/StockValidatorTest.php index ae02532fcc2..db3040ff334 100644 --- a/tests/Eccube/Tests/Service/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/StockValidatorTest.php @@ -2,38 +2,36 @@ namespace Eccube\Tests\Service; -use Eccube\Entity\Cart; use Eccube\Entity\CartItem; -use Eccube\Entity\ItemHolderInterface; -use Eccube\Entity\ItemInterface; -use Eccube\Service\ItemHolderProcessor; -use Eccube\Service\ItemProcessor; use Eccube\Service\ItemValidateException; -use Eccube\Service\PurchaseFlow; use Eccube\Service\StockValidator; -use Eccube\Service\ValidatableItemProcessor; -use Eccube\Service\ValidatableItemHolderProcessor; use Eccube\Tests\EccubeTestCase; class StockValidatorTest extends EccubeTestCase { + /** + * @var StockValidator + */ protected $validator; protected $cartItem; protected $Product; + protected $ProductClass; + public function setUp() { parent::setUp(); $this->Product = $this->createProduct('テスト商品', 1); + $this->ProductClass = $this->Product->getProductClasses()[0]; $this->validator = new StockValidator(); $this->cartItem = new CartItem(); - $this->cartItem->setObject($this->Product->getProductClasses()[0]); + $this->cartItem->setObject($this->ProductClass); } public function testInstance() { self::assertInstanceOf(StockValidator::class, $this->validator); - self::assertSame($this->Product->getProductClasses()[0], $this->cartItem->getObject()); + self::assertSame($this->ProductClass, $this->cartItem->getObject()); } public function testValidStock() @@ -50,7 +48,21 @@ public function testValidStockFail() $this->validator->process($this->cartItem); self::fail('エラーチェックに失敗しました'); } catch (ItemValidateException $e) { - self::assertEquals($this->Product->getProductClasses()[0]->getStock(), $this->cartItem->getQuantity()); + self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); } } + + public function testValidStockOrder() + { + $Customer = $this->createCustomer(); + $Order = $this->app['eccube.fixture.generator']->createOrder($Customer, array($this->ProductClass)); + + self::assertEquals($Order->getShipmentItems()[0]->getProductClass(), $this->ProductClass); + + $Order->getShipmentItems()[0]->setQuantity(1); + $this->ProductClass->setStock(100); + + $this->validator->process($Order->getShipmentItems()[0]); + self::assertEquals(1, $Order->getShipmentItems()[0]->getQuantity()); + } } From db5b9e5f8e1c5b0a4a07e5df7e39f42778a5deb3 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 4 Jul 2017 10:33:01 +0900 Subject: [PATCH 07/75] =?UTF-8?q?=E4=BE=8B=E5=A4=96=E3=81=8B=E3=82=89Proce?= =?UTF-8?q?ssResult=E3=81=B8=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 2 +- src/Eccube/Entity/ItemHolderInterface.php | 4 +- src/Eccube/Entity/Order.php | 4 +- src/Eccube/Service/ItemHolderProcessor.php | 4 ++ src/Eccube/Service/ItemProcessor.php | 4 ++ src/Eccube/Service/ProcessResult.php | 37 +++++++++++++++++++ src/Eccube/Service/PurchaseFlow.php | 21 ++++++----- .../ValidatableItemHolderProcessor.php | 5 ++- .../Service/ValidatableItemProcessor.php | 9 ++++- .../Eccube/Tests/Service/PurchaseFlowTest.php | 9 +++-- .../Tests/Service/StockValidatorTest.php | 2 +- 11 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 src/Eccube/Service/ProcessResult.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 453e14f2331..c869cc5b0dc 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -276,7 +276,7 @@ public function setPayments($payments) /** * @param $error */ - public function addError(ItemValidateException $error) + public function addError($error) { $this->errors[] = $error; } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index c5b34d376a2..4969af03cea 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -8,10 +8,10 @@ interface ItemHolderInterface { /** - * @param ItemValidateException $error + * @param string $error * @return void */ - public function addError(ItemValidateException $error); + public function addError($error); public function getItems(); diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 20f82a24d93..e31e29e1112 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1873,10 +1873,10 @@ public function getOrderStatus() } /** - * @param ItemValidateException $error + * @param string $error * @return void */ - public function addError(ItemValidateException $error) + public function addError($error) { // TODO: Implement addError() method. } diff --git a/src/Eccube/Service/ItemHolderProcessor.php b/src/Eccube/Service/ItemHolderProcessor.php index 588a19edb90..c90af4960f5 100644 --- a/src/Eccube/Service/ItemHolderProcessor.php +++ b/src/Eccube/Service/ItemHolderProcessor.php @@ -7,5 +7,9 @@ interface ItemHolderProcessor { + /** + * @param ItemHolderInterface $itemHolder + * @return ProcessResult + */ public function process(ItemHolderInterface $itemHolder); } \ No newline at end of file diff --git a/src/Eccube/Service/ItemProcessor.php b/src/Eccube/Service/ItemProcessor.php index e94a3407711..d025012bd57 100644 --- a/src/Eccube/Service/ItemProcessor.php +++ b/src/Eccube/Service/ItemProcessor.php @@ -7,5 +7,9 @@ interface ItemProcessor { + /** + * @param ItemInterface $item + * @return ProcessResult + */ public function process(ItemInterface $item); } \ No newline at end of file diff --git a/src/Eccube/Service/ProcessResult.php b/src/Eccube/Service/ProcessResult.php new file mode 100644 index 00000000000..29072dfbf26 --- /dev/null +++ b/src/Eccube/Service/ProcessResult.php @@ -0,0 +1,37 @@ +error = $error; + $this->message = $message; + } + + public static function fail($message) + { + return new self(true, $message); + } + + public static function success() + { + return new self(false); + } + + public function isError() + { + return $this->error; + } + + public function getErrorMessage() + { + return $this->message; + } +} \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow.php index fdd86c99b9d..8bf6f879fb2 100644 --- a/src/Eccube/Service/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow.php @@ -8,27 +8,30 @@ class PurchaseFlow { // TODO collection? + /** + * @var ItemHolderProcessor[] + */ protected $itemHolderProsessors = []; + /** + * @var ItemProcessor[] + */ protected $itemProsessors = []; public function execute(ItemHolderInterface $itemHolder) { foreach ($itemHolder->getItems() as $item) { foreach ($this->itemProsessors as $itemProsessor) { - try { - $itemProsessor->process($item); - } catch (ItemValidateException $exception) { - $itemHolder->addError($exception); + $result = $itemProsessor->process($item); + if ($result->isError()) { + $itemHolder->addError($result->getErrorMessage()); } } - } foreach ($this->itemHolderProsessors as $holderProcessor) { - try { - $holderProcessor->process($itemHolder); - } catch (ItemValidateException $exception) { - $itemHolder->addError($exception); + $result = $holderProcessor->process($itemHolder); + if ($result->isError()) { + $itemHolder->addError($result->getErrorMessage()); } } return $itemHolder; diff --git a/src/Eccube/Service/ValidatableItemHolderProcessor.php b/src/Eccube/Service/ValidatableItemHolderProcessor.php index 4d5070142d0..f0ffaa8007b 100644 --- a/src/Eccube/Service/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/ValidatableItemHolderProcessor.php @@ -11,11 +11,14 @@ public final function process(ItemHolderInterface $itemHolder) { try { $this->validate($itemHolder); + + return ProcessResult::success(); } catch (ItemValidateException $e) { if ($itemHolder instanceof Cart) { $this->handle($itemHolder); } - throw $e; + + return ProcessResult::fail($e->getMessage()); } } diff --git a/src/Eccube/Service/ValidatableItemProcessor.php b/src/Eccube/Service/ValidatableItemProcessor.php index 54ab99940e6..460f0f18761 100644 --- a/src/Eccube/Service/ValidatableItemProcessor.php +++ b/src/Eccube/Service/ValidatableItemProcessor.php @@ -37,15 +37,20 @@ public function process(ItemInterface $item) { try { $this->validate($item); + + return ProcessResult::success(); } catch (ItemValidateException $e) { if ($item instanceof CartItem) { $this->handle($item); } - throw $e; + + return ProcessResult::fail($e->getMessage()); } } protected abstract function validate(ItemInterface $item); - protected function handle(ItemInterface $item) {} + protected function handle(ItemInterface $item) + { + } } \ No newline at end of file diff --git a/tests/Eccube/Tests/Service/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlowTest.php index 8c4c8062b4c..09a83282c6f 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlowTest.php @@ -9,6 +9,7 @@ use Eccube\Service\ItemHolderProcessor; use Eccube\Service\ItemProcessor; use Eccube\Service\ItemValidateException; +use Eccube\Service\ProcessResult; use Eccube\Service\PurchaseFlow; use Eccube\Service\ValidatableItemProcessor; use Eccube\Service\ValidatableItemHolderProcessor; @@ -70,7 +71,7 @@ public function testProcessItemHolderProcessor_validationErrors() $itemHolder = new Cart(); self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); - self::assertEquals(['error 1'], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); + self::assertEquals(['error 1'], $itemHolder->getErrors()); } public function testProcessItemProcessors_validationErrors() @@ -84,7 +85,7 @@ public function testProcessItemProcessors_validationErrors() self::assertEquals([ "error 1", "error 2" - ], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); + ], $itemHolder->getErrors()); } public function testProcessItemProcessors_validationErrors_with_multi_items() @@ -99,7 +100,7 @@ public function testProcessItemProcessors_validationErrors_with_multi_items() self::assertEquals([ "error 1", "error 2", "error 1", "error 2" - ], array_map(function($exception) { return $exception->getMessage(); }, $itemHolder->getErrors())); + ], $itemHolder->getErrors()); } } @@ -108,6 +109,7 @@ class PurchaseFlowTest_ItemHolderProcessor implements ItemHolderProcessor { public function process(ItemHolderInterface $itemHolder) { + return ProcessResult::success(); } } @@ -116,6 +118,7 @@ class PurchaseFlowTest_ItemProcessor implements ItemProcessor public function process(ItemInterface $item) { + return ProcessResult::success(); } } diff --git a/tests/Eccube/Tests/Service/StockValidatorTest.php b/tests/Eccube/Tests/Service/StockValidatorTest.php index db3040ff334..e69ec6a0c37 100644 --- a/tests/Eccube/Tests/Service/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/StockValidatorTest.php @@ -51,7 +51,7 @@ public function testValidStockFail() self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); } } - + public function testValidStockOrder() { $Customer = $this->createCustomer(); From 45f620dc8935308288ae1e5f889f92cc03e1b655 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 4 Jul 2017 10:39:21 +0900 Subject: [PATCH 08/75] =?UTF-8?q?=E5=A4=B1=E6=95=97=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tests/Service/StockValidatorTest.php | 10 ++++----- .../Service/ValidatableItemProcessorTest.php | 21 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/Eccube/Tests/Service/StockValidatorTest.php b/tests/Eccube/Tests/Service/StockValidatorTest.php index e69ec6a0c37..1f1b022e8c0 100644 --- a/tests/Eccube/Tests/Service/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/StockValidatorTest.php @@ -44,12 +44,10 @@ public function testValidStock() public function testValidStockFail() { $this->cartItem->setQuantity(PHP_INT_MAX); - try { - $this->validator->process($this->cartItem); - self::fail('エラーチェックに失敗しました'); - } catch (ItemValidateException $e) { - self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); - } + $result = $this->validator->process($this->cartItem); + + self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); + self::assertTrue($result->isError()); } public function testValidStockOrder() diff --git a/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php index 99b126e25bf..95ad487ade6 100644 --- a/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/ValidatableItemProcessorTest.php @@ -55,12 +55,7 @@ public function testValidateCartFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new CartItem(); - try { - $validator->process($item); - self::fail(); - } catch (ItemValidateException $e) { - $this->assertTrue($validator->handleCalled); - } + $validator->process($item); } public function testValidateOrderSuccess() @@ -68,8 +63,9 @@ public function testValidateOrderSuccess() $validator = new ValidatableItemProcessorTest_NormalValidator(); $item = new ShipmentItem(); - $validator->process($item); - $this->assertFalse($validator->handleCalled); + $result = $validator->process($item); + self::assertFalse($validator->handleCalled); + self::assertFalse($result->isError()); } public function testValidateOrderFail() @@ -77,12 +73,9 @@ public function testValidateOrderFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new ShipmentItem(); - try { - $validator->process($item); - self::fail(); - } catch (ItemValidateException $e) { - $this->assertFalse($validator->handleCalled); - } + $result = $validator->process($item); + self::assertFalse($validator->handleCalled); + self::assertTrue($result->isError()); } } From 30b379dd826fb15d6976d16c4e43b9ceaedc9b34 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 4 Jul 2017 10:48:36 +0900 Subject: [PATCH 09/75] =?UTF-8?q?=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => PurchaseFlow}/ItemHolderProcessor.php | 2 +- .../{ => PurchaseFlow}/ItemProcessor.php | 2 +- .../ItemValidateException.php | 2 +- .../{ => PurchaseFlow}/ProcessResult.php | 2 +- .../Processor}/StockValidator.php | 4 +++- .../{ => PurchaseFlow}/PurchaseFlow.php | 2 +- .../ValidatableItemHolderProcessor.php | 2 +- .../ValidatableItemProcessor.php | 2 +- .../Processor}/StockValidatorTest.php | 3 +-- .../{ => PurchaseFlow}/PurchaseFlowTest.php | 16 ++++++++-------- .../ValidatableItemProcessorTest.php | 6 +++--- .../ValidatableItemHolderProcessorTest.php | 18 ------------------ 12 files changed, 22 insertions(+), 39 deletions(-) rename src/Eccube/Service/{ => PurchaseFlow}/ItemHolderProcessor.php (85%) rename src/Eccube/Service/{ => PurchaseFlow}/ItemProcessor.php (83%) rename src/Eccube/Service/{ => PurchaseFlow}/ItemValidateException.php (95%) rename src/Eccube/Service/{ => PurchaseFlow}/ProcessResult.php (93%) rename src/Eccube/Service/{ => PurchaseFlow/Processor}/StockValidator.php (75%) rename src/Eccube/Service/{ => PurchaseFlow}/PurchaseFlow.php (96%) rename src/Eccube/Service/{ => PurchaseFlow}/ValidatableItemHolderProcessor.php (94%) rename src/Eccube/Service/{ => PurchaseFlow}/ValidatableItemProcessor.php (97%) rename tests/Eccube/Tests/Service/{ => PurchaseFlow/Processor}/StockValidatorTest.php (96%) rename tests/Eccube/Tests/Service/{ => PurchaseFlow}/PurchaseFlowTest.php (91%) rename tests/Eccube/Tests/Service/{ => PurchaseFlow}/ValidatableItemProcessorTest.php (95%) delete mode 100644 tests/Eccube/Tests/Service/ValidatableItemHolderProcessorTest.php diff --git a/src/Eccube/Service/ItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php similarity index 85% rename from src/Eccube/Service/ItemHolderProcessor.php rename to src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php index c90af4960f5..cdac6590996 100644 --- a/src/Eccube/Service/ItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php @@ -1,6 +1,6 @@ Date: Tue, 4 Jul 2017 11:21:12 +0900 Subject: [PATCH 10/75] =?UTF-8?q?PaymentTotalLimitValidator=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 1 + src/Eccube/Entity/ItemHolderInterface.php | 6 ++ src/Eccube/Entity/PurchaseInterface.php | 10 +++ .../Processor/PaymentTotalLimitValidator.php | 54 +++++++++++++ .../Service/PurchaseFlow/PurchaseFlow.php | 3 + .../PaymentTotalLimitValidatorTest.php | 76 +++++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index c869cc5b0dc..dd3e8a72ac9 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -288,4 +288,5 @@ public function getErrors() { return $this->errors; } + } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index 4969af03cea..df349a3ad9f 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -19,4 +19,10 @@ public function getItems(); * @return ItemValidateException[] */ public function getErrors(); + + /** + * 合計金額を返します。 + * @return int + */ + public function getTotal(); } \ No newline at end of file diff --git a/src/Eccube/Entity/PurchaseInterface.php b/src/Eccube/Entity/PurchaseInterface.php index 54e091f76ac..73f60d6819b 100644 --- a/src/Eccube/Entity/PurchaseInterface.php +++ b/src/Eccube/Entity/PurchaseInterface.php @@ -4,7 +4,17 @@ interface PurchaseInterface { + /** + * 合計金額を設定します。 + * @param $total|int + */ public function setTotal($total); + + /** + * 合計金額を返す。 + * @return int + */ public function getTotal(); + public function getItems(); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php new file mode 100644 index 00000000000..27ac1b6af27 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -0,0 +1,54 @@ +maxTotalFee = $maxTotalFee; + } + + protected function validate(ItemHolderInterface $item) + { + $totalPrice = $item->getTotal(); + if ($totalPrice > $this->maxTotalFee) { + throw new ItemValidateException(); + } + } +} \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 2d4d90258a9..9a52de6c1d3 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -19,6 +19,9 @@ class PurchaseFlow protected $itemProsessors = []; public function execute(ItemHolderInterface $itemHolder) { + + // TODO 集計する + foreach ($itemHolder->getItems() as $item) { foreach ($this->itemProsessors as $itemProsessor) { $result = $itemProsessor->process($item); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php new file mode 100644 index 00000000000..0983aef689f --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php @@ -0,0 +1,76 @@ +setTotal(100); + + $result = $validator->process($cart); + self::assertFalse($result->isError()); + } + + public function testCartValidateFail() + { + $validator = new PaymentTotalLimitValidator(1000); + + $cart = new Cart(); + $cart->setTotal(1001); + + $result = $validator->process($cart); + self::assertTrue($result->isError()); + } + + public function testOrderValidate() + { + $validator = new PaymentTotalLimitValidator(1000); + + $order = new Order(); + $order->setTotal(100); + + $result = $validator->process($order); + self::assertFalse($result->isError()); + } + + public function testOrderValidateFail() + { + $validator = new PaymentTotalLimitValidator(1000); + + $order = new Order(); + $order->setTotal(1001); + + $result = $validator->process($order); + self::assertTrue($result->isError()); + } +} From fa358fc4a085bcdd05619dd3d46b98c2eb857c22 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 4 Jul 2017 13:38:24 +0900 Subject: [PATCH 11/75] =?UTF-8?q?DeliveryFeeProcessor=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 7 ++ src/Eccube/Entity/ItemHolderInterface.php | 8 ++ src/Eccube/Entity/Order.php | 8 ++ .../Processor/DeliveryFeeProcessor.php | 95 +++++++++++++++++++ .../Processor/PaymentTotalLimitValidator.php | 3 + .../PurchaseFlow/Processor/StockValidator.php | 3 + .../Processor/DeliveryFeeProcessorTest.php | 86 +++++++++++++++++ 7 files changed, 210 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index dd3e8a72ac9..738ae913701 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -289,4 +289,11 @@ public function getErrors() return $this->errors; } + /** + * @param ItemInterface $item + */ + public function addItem(ItemInterface $item) + { + $this->CartItems->add($item); + } } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index df349a3ad9f..f966919a053 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -13,6 +13,9 @@ interface ItemHolderInterface */ public function addError($error); + /** + * @return ItemInterface[] + */ public function getItems(); /** @@ -25,4 +28,9 @@ public function getErrors(); * @return int */ public function getTotal(); + + /** + * @param ItemInterface $item + */ + public function addItem(ItemInterface $item); } \ No newline at end of file diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index e31e29e1112..c4aa28d3257 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1888,4 +1888,12 @@ public function getErrors() { // TODO: Implement getErrors() method. } + + /** + * @param ItemInterface $item + */ + public function addItem(ItemInterface $item) + { + $this->ShipmentItems->add($item); + } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php new file mode 100644 index 00000000000..a2e4f5b93e5 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -0,0 +1,95 @@ +app = $app; + } + + /** + * @param ItemHolderInterface $itemHolder + * @return ProcessResult + */ + public function process(ItemHolderInterface $itemHolder) + { + /** + * @var ShipmentItem $ShipmentItem + */ + foreach ($itemHolder->getItems() as $ShipmentItem) { + if ($ShipmentItem->isDeliveryFee()) { + return; + } + } + + $DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE); + // TODO + $TaxInclude = $this->app['orm.em']->getRepository(TaxDisplayType::class)->find(TaxDisplayType::INCLUDED); + $Taxion = $this->app['orm.em']->getRepository(TaxType::class)->find(TaxType::TAXATION); + + /** @var Order $Order */ + $Order = $itemHolder; + /* @var Shipping $Shipping */ + foreach ($Order->getShippings() as $Shipping) { + $ShipmentItem = new ShipmentItem(); + $ShipmentItem->setProductName("送料") + ->setPrice($Shipping->getShippingDeliveryFee()) + ->setPriceIncTax($Shipping->getShippingDeliveryFee()) + ->setTaxRate(8) + ->setQuantity(1) + ->setOrderItemType($DeliveryFeeType) + ->setShipping($Shipping) + ->setTaxDisplayType($TaxInclude) + ->setTaxType($Taxion); + + $itemHolder->addItem($ShipmentItem); + $Shipping->addShipmentItem($ShipmentItem); + } + } + + +} \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php index 27ac1b6af27..65ef69dba0d 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -28,6 +28,9 @@ use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; +/** + * 購入金額上限チェック. + */ class PaymentTotalLimitValidator extends ValidatableItemHolderProcessor { /** diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 17e080df206..f1c08a29444 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -6,6 +6,9 @@ use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +/** + * 在庫制限チェック. + */ class StockValidator extends ValidatableItemProcessor { protected function validate(ItemInterface $item) diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php new file mode 100644 index 00000000000..d32aa0327c1 --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php @@ -0,0 +1,86 @@ +app); + $Order = $this->createOrder($this->createCustomer()); + /** + * @var ShipmentItem $ShipmentItem + */ + foreach ($Order->getShipmentItems() as $ShipmentItem) { + if ($ShipmentItem->isDeliveryFee()) { + $Order->getShipmentItems()->removeElement($ShipmentItem); + } + } + $processor->process($Order); + self::assertNotEmpty($this->getDeliveryFees($Order)); + } + + /** + * すでに送料がある場合は送料を追加しない + */ + public function testProcessWithDeliveryFee() + { + $processor = new DeliveryFeeProcessor($this->app); + $Order = $this->createOrder($this->createCustomer()); + /** + * @var ShipmentItem $ShipmentItem + */ + foreach ($Order->getShipmentItems() as $ShipmentItem) { + if ($ShipmentItem->isDeliveryFee()) { + $Order->getShipmentItems()->removeElement($ShipmentItem); + } + } + + $DeliveryFee = new ShipmentItem(); + $OrderItemType = new OrderItemType(); + $OrderItemType->setId(OrderItemType::DELIVERY_FEE); + $DeliveryFee->setOrderItemType($OrderItemType); + $Order->addItem($DeliveryFee); + + $processor->process($Order); + + $DeliveryFeeList = $this->getDeliveryFees($Order); + self::assertCount(1, $DeliveryFeeList); + self::assertSame($DeliveryFee, array_shift($DeliveryFeeList)); + } + + private function getDeliveryFees(Order $Order) + { + return array_filter($Order->getShipmentItems()->toArray(), function($ShipmentItem) { + return $ShipmentItem->isDeliveryFee(); + }); + } +} From 58e5d7595551a1b518bd7592cceded284b6fa903 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 4 Jul 2017 14:07:13 +0900 Subject: [PATCH 12/75] =?UTF-8?q?Cart=E3=83=95=E3=83=AD=E3=83=BC=E3=82=92?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 3 ++- src/Eccube/Entity/ItemHolderInterface.php | 6 ++++++ src/Eccube/Entity/ItemInterface.php | 4 ++++ .../Service/PurchaseFlow/PurchaseFlow.php | 15 ++++++++++++++- .../ServiceProvider/EccubeServiceProvider.php | 19 +++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 07bdf20b8fa..a37bfdea1ad 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -42,7 +42,8 @@ class CartController extends AbstractController public function index(Application $app, Request $request) { // カートの集計結果を取得 - $Cart = $app['eccube.service.calculate']($app['eccube.service.cart']->getCart(), $app->user())->calculate(); + $Cart = $app['eccube.service.cart']->getCart(); + $app['eccube.purchase.flow.cart']->execute($Cart); // FRONT_CART_INDEX_INITIALIZE $event = new EventArgs( diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index f966919a053..1a167de77f3 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -29,6 +29,12 @@ public function getErrors(); */ public function getTotal(); + /** + * 合計金額を設定します。 + * @param $total|int + */ + public function setTotal($total); + /** * @param ItemInterface $item */ diff --git a/src/Eccube/Entity/ItemInterface.php b/src/Eccube/Entity/ItemInterface.php index 44e237e1a9d..c03a21129ca 100644 --- a/src/Eccube/Entity/ItemInterface.php +++ b/src/Eccube/Entity/ItemInterface.php @@ -44,4 +44,8 @@ public function getOrderItemType(); * @return ProductClass */ public function getProductClass(); + + public function getPrice(); + + public function getQuantity(); } diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 9a52de6c1d3..3af4fb1430d 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -4,6 +4,7 @@ use Eccube\Entity\ItemHolderInterface; +use Eccube\Entity\ItemInterface; class PurchaseFlow { @@ -20,7 +21,7 @@ class PurchaseFlow public function execute(ItemHolderInterface $itemHolder) { - // TODO 集計する + $this->calculateTotal($itemHolder); foreach ($itemHolder->getItems() as $item) { foreach ($this->itemProsessors as $itemProsessor) { @@ -49,4 +50,16 @@ public function addItemProcessor(ItemProcessor $prosessor) { $this->itemProsessors[] = $prosessor; } + + /** + * @param ItemHolderInterface $itemHolder + */ + private function calculateTotal(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems(), function ($sum, ItemInterface $item) { + $sum += $item->getPrice() * $item->getQuantity(); + return $sum; + }, 0); + $itemHolder->setTotal($total); + } } diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index c2d12edc618..193b3bc7d1a 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -26,6 +26,10 @@ use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; +use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; +use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; +use Eccube\Service\PurchaseFlow\Processor\StockValidator; +use Eccube\Service\PurchaseFlow\PurchaseFlow; use Pimple\Container; use Pimple\ServiceProviderInterface; use Silex\Api\EventListenerProviderInterface; @@ -522,6 +526,21 @@ public function register(Container $app) }; // TODO QueryCustomizerの追加方法は要検討 $app['eccube.queries']->addCustomizer(new \Acme\Entity\AdminProductListCustomizer()); + + $app['eccube.purchase.flow.cart'] = function () use ($app) { + $flow = new PurchaseFlow(); + $flow->addItemProcessor(new StockValidator()); + $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + return $flow; + }; + + $app['eccube.purchase.flow.shopping'] = function () use ($app) { + $flow = new PurchaseFlow(); + $flow->addItemProcessor(new StockValidator()); + $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + $flow->addItemHolderProcessor(new DeliveryFeeProcessor($app)); + return $flow; + }; } public function subscribe(Container $app, EventDispatcherInterface $dispatcher) From fa25f37e9411f42f4ef3a594efd101d1635529f9 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 4 Jul 2017 14:44:08 +0900 Subject: [PATCH 13/75] =?UTF-8?q?PurchaseFlow=20=E3=82=92=20Controller=20?= =?UTF-8?q?=E3=81=B8=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 43 ++++++++++++++++++- .../Service/PurchaseFlow/PurchaseFlow.php | 2 +- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index a37bfdea1ad..bc81efbb730 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -25,6 +25,7 @@ namespace Eccube\Controller; use Eccube\Application; +use Eccube\Entity\CartItem; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Exception\CartException; @@ -110,6 +111,8 @@ public function add(Application $app, Request $request) { $productClassId = $request->get('product_class_id'); $quantity = $request->request->has('quantity') ? $request->get('quantity') : 1; + /** @var ProductClass $ProductClass */ + $ProductClass = $app['eccube.repository.product_class']->find($productClassId); // FRONT_CART_ADD_INITIALIZE $event = new EventArgs( @@ -128,7 +131,23 @@ public function add(Application $app, Request $request) log_info('カート追加処理開始', array('product_class_id' => $productClassId, 'quantity' => $quantity)); - $app['eccube.service.cart']->addProduct($productClassId, $quantity)->save(); + $Cart = $app['eccube.service.cart']->getCart(); + $CartItem = new CartItem(); + $CartItem + ->setClassName('Eccube\Entity\ProductClass') + ->setClassId($productClassId) + ->setPrice($ProductClass->getPrice02IncTax()) + ->setQuantity($quantity); + $Cart->setCartItem($CartItem); + $app['eccube.purchase.flow.cart']->execute($Cart); + + $errors = $Cart->getErrors(); + if (!empty($errors)) { + foreach($errors as $error) { + $app->addRequestError($error); + } + } + // $app['eccube.service.cart']->addProduct($productClassId, $quantity)->save(); log_info('カート追加処理完了', array('product_class_id' => $productClassId, 'quantity' => $quantity)); @@ -196,7 +215,27 @@ public function up(Application $app, Request $request, $productClassId) $productClassId = $event->getArgument('productClassId'); - $app['eccube.service.cart']->upProductQuantity($productClassId)->save(); + /** @var ProductClass $ProductClass */ + $ProductClass = $app['eccube.repository.product_class']->find($productClassId); + $Cart = $app['eccube.service.cart']->getCart(); + $CartItem = new CartItem(); + $CartItem + ->setClassName('Eccube\Entity\ProductClass') + ->setClassId($productClassId) + ->setPrice($ProductClass->getPrice02IncTax()) + ->setQuantity(6); + $Cart->setCartItem($CartItem); + $app['eccube.purchase.flow.cart']->execute($Cart); + + $errors = $Cart->getErrors(); + if (!empty($errors)) { + foreach($errors as $error) { + $app->addRequestError($error); + } + } else { + $app['eccube.service.cart']->save(); + } + //$app['eccube.service.cart']->upProductQuantity($productClassId)->save(); // FRONT_CART_UP_COMPLETE $event = new EventArgs( diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 3af4fb1430d..f6ce57a0a7a 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -56,7 +56,7 @@ public function addItemProcessor(ItemProcessor $prosessor) */ private function calculateTotal(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems(), function ($sum, ItemInterface $item) { + $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { $sum += $item->getPrice() * $item->getQuantity(); return $sum; }, 0); From f1cf1193c5cdff0e084b4898df6820758abc3e94 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 10:47:20 +0900 Subject: [PATCH 14/75] =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=AB=E3=83=BC=E3=83=86=E3=82=A3=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 109 ------------------ .../FrontControllerProvider.php | 3 - 2 files changed, 112 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index bc81efbb730..32d65ca7478 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -100,94 +100,6 @@ public function index(Application $app, Request $request) ); } - /** - * カートに商品を追加する. - * - * @param Application $app - * @param Request $request - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function add(Application $app, Request $request) - { - $productClassId = $request->get('product_class_id'); - $quantity = $request->request->has('quantity') ? $request->get('quantity') : 1; - /** @var ProductClass $ProductClass */ - $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - - // FRONT_CART_ADD_INITIALIZE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - 'quantity' => $quantity, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_INITIALIZE, $event); - - try { - - $productClassId = $event->getArgument('productClassId'); - $quantity = $event->getArgument('quantity'); - - log_info('カート追加処理開始', array('product_class_id' => $productClassId, 'quantity' => $quantity)); - - $Cart = $app['eccube.service.cart']->getCart(); - $CartItem = new CartItem(); - $CartItem - ->setClassName('Eccube\Entity\ProductClass') - ->setClassId($productClassId) - ->setPrice($ProductClass->getPrice02IncTax()) - ->setQuantity($quantity); - $Cart->setCartItem($CartItem); - $app['eccube.purchase.flow.cart']->execute($Cart); - - $errors = $Cart->getErrors(); - if (!empty($errors)) { - foreach($errors as $error) { - $app->addRequestError($error); - } - } - // $app['eccube.service.cart']->addProduct($productClassId, $quantity)->save(); - - log_info('カート追加処理完了', array('product_class_id' => $productClassId, 'quantity' => $quantity)); - - // FRONT_CART_ADD_COMPLETE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - 'quantity' => $quantity, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_COMPLETE, $event); - - if ($event->hasResponse()) { - return $event->getResponse(); - } - - } catch (CartException $e) { - - log_info('カート追加エラー', array($e->getMessage())); - - // FRONT_CART_ADD_EXCEPTION - $event = new EventArgs( - array( - 'exception' => $e, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_ADD_EXCEPTION, $event); - - if ($event->hasResponse()) { - return $event->getResponse(); - } - - $app->addRequestError($e->getMessage()); - } - - return $app->redirect($app->url('cart')); - } - /** * カートに入っている商品の個数を1増やす. * @@ -385,27 +297,6 @@ public function remove(Application $app, Request $request, $productClassId) return $app->redirect($app->url('cart')); } - /** - * カートに商品を個数を指定して設定する. - * - * @param Application $app - * @param Request $request - * @param $productClassId - * @param $quantity - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - * @throws CartException - * - * @deprecated since 3.0.0, to be removed in 3.1 - */ - public function setQuantity(Application $app, Request $request, $productClassId, $quantity) - { - $this->isTokenValid($app); - - $app['eccube.service.cart']->setProductQuantity($productClassId, $quantity)->save(); - - return $app->redirect($app->url('cart')); - } - /** * カートをロック状態に設定し、購入確認画面へ遷移する. * diff --git a/src/Eccube/ControllerProvider/FrontControllerProvider.php b/src/Eccube/ControllerProvider/FrontControllerProvider.php index ef2c6f52b51..94977e204f8 100644 --- a/src/Eccube/ControllerProvider/FrontControllerProvider.php +++ b/src/Eccube/ControllerProvider/FrontControllerProvider.php @@ -48,11 +48,8 @@ public function connect(Application $app) // cart $c->match('/cart', '\Eccube\Controller\CartController::index')->bind('cart'); - $c->post('/cart/add', '\Eccube\Controller\CartController::add')->bind('cart_add'); $c->put('/cart/up/{productClassId}', '\Eccube\Controller\CartController::up')->bind('cart_up')->assert('productClassId', '\d+'); $c->put('/cart/down/{productClassId}', '\Eccube\Controller\CartController::down')->bind('cart_down')->assert('productClassId', '\d+'); - // setquantity deprecated since 3.0.0, to be removed in 3.1 - $c->put('/cart/setQuantity/{productClassId}/{quantity}', '\Eccube\Controller\CartController::setQuantity')->bind('cart_set_quantity')->assert('productClassId', '\d+')->assert('quantity', '\d+'); $c->put('/cart/remove/{productClassId}', '\Eccube\Controller\CartController::remove')->bind('cart_remove')->assert('productClassId', '\d+'); $c->match('/cart/buystep', '\Eccube\Controller\CartController::buystep')->bind('cart_buystep'); From 9db9ba96b548b1b2e465e01e9a14a3e593ef590b Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 6 Jul 2017 14:00:16 +0900 Subject: [PATCH 15/75] =?UTF-8?q?PurchaseFlow=20=E3=82=92=E5=8F=97?= =?UTF-8?q?=E6=B3=A8=E7=AE=A1=E7=90=86=E3=81=AB=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/Admin/Order/EditController.php | 4 ++-- .../PurchaseFlow/Processor/DeliveryFeeProcessor.php | 4 +--- .../Service/PurchaseFlow/Processor/StockValidator.php | 3 +++ .../Service/PurchaseFlow/ValidatableItemProcessor.php | 2 +- src/Eccube/ServiceProvider/EccubeServiceProvider.php | 7 +++++++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index 83deeccf272..bd355efb15b 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -133,8 +133,8 @@ public function index(Application $app, Request $request, $id = null) // プラグインで Strategy をセットしたりする // TODO 編集前のOrder情報が必要かもしれない // TODO 手数料, 値引きの集計は未実装 - $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); - + // $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); + $app['eccube.purchase.flow.order']->execute($TargetOrder); // 登録ボタン押下 switch ($request->get('mode')) { case 'register': diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php index a2e4f5b93e5..b34cd9c97f4 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -90,6 +90,4 @@ public function process(ItemHolderInterface $itemHolder) $Shipping->addShipmentItem($ShipmentItem); } } - - -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index f1c08a29444..639dbdf2c85 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -13,6 +13,9 @@ class StockValidator extends ValidatableItemProcessor { protected function validate(ItemInterface $item) { + if (!$item->isProduct()) { + return; + } $stock = $item->getProductClass()->getStock(); $quantity = $item->getQuantity(); if ($stock < $quantity) { diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index 80a5998e1a3..922ebdfbdb9 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -53,4 +53,4 @@ protected abstract function validate(ItemInterface $item); protected function handle(ItemInterface $item) { } -} \ No newline at end of file +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 193b3bc7d1a..e7cf358b732 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -541,6 +541,13 @@ public function register(Container $app) $flow->addItemHolderProcessor(new DeliveryFeeProcessor($app)); return $flow; }; + + $app['eccube.purchase.flow.order'] = function () use ($app) { + $flow = new PurchaseFlow(); + $flow->addItemProcessor(new StockValidator()); + $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + return $flow; + }; } public function subscribe(Container $app, EventDispatcherInterface $dispatcher) From ab1105c38543242f50c903d9152fff203a65272e Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 14:44:02 +0900 Subject: [PATCH 16/75] =?UTF-8?q?=E5=95=86=E5=93=81=E3=81=AE=E5=85=AC?= =?UTF-8?q?=E9=96=8B=E3=83=BB=E9=9D=9E=E5=85=AC=E9=96=8B=E3=82=92=E5=88=B6?= =?UTF-8?q?=E5=BE=A1=E3=81=99=E3=82=8B=E3=83=97=E3=83=AD=E3=82=BB=E3=83=83?= =?UTF-8?q?=E3=82=B5=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/ItemInterface.php | 2 + .../Processor/DisplayStatusValidator.php | 26 ++++++ .../ServiceProvider/EccubeServiceProvider.php | 3 + .../Processor/DisplayStatusValidatorTest.php | 81 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php diff --git a/src/Eccube/Entity/ItemInterface.php b/src/Eccube/Entity/ItemInterface.php index c03a21129ca..896787d2e60 100644 --- a/src/Eccube/Entity/ItemInterface.php +++ b/src/Eccube/Entity/ItemInterface.php @@ -48,4 +48,6 @@ public function getProductClass(); public function getPrice(); public function getQuantity(); + + public function setQuantity($quantity); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php new file mode 100644 index 00000000000..d12ee5426ae --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php @@ -0,0 +1,26 @@ +getProductClass(); + if (!$ProductClass->isEnable()) { + throw new ItemValidateException(); + } + } + + protected function handle(ItemInterface $item) + { + if ($item instanceof CartItem) { + $item->setQuantity(0); + } + } +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index e7cf358b732..5647aea0200 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -27,6 +27,7 @@ use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; +use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\StockValidator; use Eccube\Service\PurchaseFlow\PurchaseFlow; @@ -530,6 +531,7 @@ public function register(Container $app) $app['eccube.purchase.flow.cart'] = function () use ($app) { $flow = new PurchaseFlow(); $flow->addItemProcessor(new StockValidator()); + $flow->addItemProcessor(new DisplayStatusValidator()); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); return $flow; }; @@ -537,6 +539,7 @@ public function register(Container $app) $app['eccube.purchase.flow.shopping'] = function () use ($app) { $flow = new PurchaseFlow(); $flow->addItemProcessor(new StockValidator()); + $flow->addItemProcessor(new DisplayStatusValidator()); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); $flow->addItemHolderProcessor(new DeliveryFeeProcessor($app)); return $flow; diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php new file mode 100644 index 00000000000..9fab7d351c0 --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php @@ -0,0 +1,81 @@ +Product = $this->createProduct('テスト商品', 1); + $this->ProductClass = $this->Product->getProductClasses()[0]; + $this->validator = new DisplayStatusValidator(); + $this->cartItem = new CartItem(); + $this->cartItem->setQuantity(10); + $this->cartItem->setObject($this->ProductClass); + } + + public function testInstance() + { + self::assertInstanceOf(DisplayStatusValidator::class, $this->validator); + } + + /** + * 公開商品の場合はなにもしない + */ + public function testDisplayStatusWithShow() + { + /** @var Application $app */ + $app = $this->app; + $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_SHOW); + $this->Product->setStatus($Disp); + + $this->validator->process($this->cartItem); + + self::assertEquals(10, $this->cartItem->getQuantity()); + } + + /** + * 非公開商品の場合は明細の個数を0に設定する + */ + public function testDisplayStatusWithClosed() + { + /** @var Application $app */ + $app = $this->app; + $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_HIDE); + $this->Product->setStatus($Disp); + + $this->validator->process($this->cartItem); + + self::assertEquals(0, $this->cartItem->getQuantity()); + } +} From e75d01d4e86a49f33ac5694f8e21ae0fb8d92cd6 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 14:44:50 +0900 Subject: [PATCH 17/75] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=E5=80=8B=E6=95=B0=E3=81=AE=E5=8A=A0=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 101 +++++++++++------------ 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 32d65ca7478..9a6a3f685be 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -26,6 +26,7 @@ use Eccube\Application; use Eccube\Entity\CartItem; +use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Exception\CartException; @@ -112,78 +113,64 @@ public function up(Application $app, Request $request, $productClassId) { $this->isTokenValid($app); + log_info('カート加算処理開始', array('product_class_id' => $productClassId)); + + /** @var ProductClass $ProductClass */ + $ProductClass = $app['eccube.repository.product_class']->find($productClassId); + + if (is_null($ProductClass)) { + return $app->redirect($app->url('cart')); + } + // FRONT_CART_UP_INITIALIZE $event = new EventArgs( array( - 'productClassId' => $productClassId, + 'ProductClass' => $ProductClass ), $request ); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_INITIALIZE, $event); - try { - - log_info('カート加算処理開始', array('product_class_id' => $productClassId)); + $Cart = $app['eccube.service.cart']->getCart(); - $productClassId = $event->getArgument('productClassId'); + $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - /** @var ProductClass $ProductClass */ - $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - $Cart = $app['eccube.service.cart']->getCart(); + if ($Exists) { + $Exists->setQuantity($Exists->getQuantity() + 1); + } else { $CartItem = new CartItem(); $CartItem - ->setClassName('Eccube\Entity\ProductClass') + ->setClassName(ProductClass::class) ->setClassId($productClassId) + ->setObject($ProductClass) ->setPrice($ProductClass->getPrice02IncTax()) - ->setQuantity(6); - $Cart->setCartItem($CartItem); - $app['eccube.purchase.flow.cart']->execute($Cart); - - $errors = $Cart->getErrors(); - if (!empty($errors)) { - foreach($errors as $error) { - $app->addRequestError($error); - } - } else { - $app['eccube.service.cart']->save(); - } - //$app['eccube.service.cart']->upProductQuantity($productClassId)->save(); - - // FRONT_CART_UP_COMPLETE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_COMPLETE, $event); - - if ($event->hasResponse()) { - return $event->getResponse(); - } - - log_info('カート加算処理完了', array('product_class_id' => $productClassId)); + ->setQuantity(1); + $Cart->addItem($CartItem); + } - } catch (CartException $e) { + $app['eccube.purchase.flow.cart']->execute($Cart); - log_info('カート加算エラー', array($e->getMessage())); + // FRONT_CART_UP_COMPLETE + $event = new EventArgs( + array( + 'productClassId' => $productClassId, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_COMPLETE, $event); - // FRONT_CART_UP_EXCEPTION - $event = new EventArgs( - array( - 'exception' => $e, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_EXCEPTION, $event); + $errors = $Cart->getErrors(); - if ($event->hasResponse()) { - return $event->getResponse(); + if (empty($errors)) { + $app['eccube.service.cart']->save(); + } else { + foreach($errors as $error) { + $app->addRequestError($error); } - - $app->addRequestError($e->getMessage()); } + log_info('カート加算処理終了', array('product_class_id' => $productClassId)); + return $app->redirect($app->url('cart')); } @@ -265,6 +252,18 @@ public function remove(Application $app, Request $request, $productClassId) { $this->isTokenValid($app); + $Cart = Cart::restore(); + $Cart->remove($productClassId); + $Regi->execute($Cart); + + if ($Regi->hasError()) { + $errors = $Regi->getErrors(); + foreach ($errors as $error) { + $app->addRequestError($error); + } + } + + log_info('カート削除処理開始', array('product_class_id' => $productClassId)); // FRONT_CART_REMOVE_INITIALIZE From cb87b3282ecc2c78ecffba434988ea31fa6eef3e Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 16:55:28 +0900 Subject: [PATCH 18/75] =?UTF-8?q?=E9=80=81=E6=96=99=E7=84=A1=E6=96=99?= =?UTF-8?q?=E3=82=92=E5=88=B6=E5=BE=A1=E3=81=99=E3=82=8B=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=BB=E3=83=83=E3=82=B5=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 25 ---- src/Eccube/Entity/Cart.php | 10 ++ src/Eccube/Entity/ItemHolderInterface.php | 7 + src/Eccube/Entity/Order.php | 10 ++ .../Processor/DeliveryFeeFreeProcessor.php | 88 +++++++++++++ .../DeliveryFeeFreeProcessorTest.php | 122 ++++++++++++++++++ 6 files changed, 237 insertions(+), 25 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 9a6a3f685be..5a83b0cbca4 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -54,31 +54,6 @@ public function index(Application $app, Request $request) ); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_INDEX_INITIALIZE, $event); - /* @var $BaseInfo \Eccube\Entity\BaseInfo */ - /* @var $Cart \Eccube\Entity\Cart */ - $BaseInfo = $app['eccube.repository.base_info']->get(); - - $isDeliveryFree = false; - $least = 0; - $quantity = 0; - if ($BaseInfo->getDeliveryFreeAmount()) { - if ($BaseInfo->getDeliveryFreeAmount() <= $Cart->getTotalPrice()) { - // 送料無料(金額)を超えている - $isDeliveryFree = true; - } else { - $least = $BaseInfo->getDeliveryFreeAmount() - $Cart->getTotalPrice(); - } - } - - if ($BaseInfo->getDeliveryFreeQuantity()) { - if ($BaseInfo->getDeliveryFreeQuantity() <= $Cart->getTotalQuantity()) { - // 送料無料(個数)を超えている - $isDeliveryFree = true; - } else { - $quantity = $BaseInfo->getDeliveryFreeQuantity() - $Cart->getTotalQuantity(); - } - } - // FRONT_CART_INDEX_COMPLETE $event = new EventArgs( array(), diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 738ae913701..1881562e76e 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -296,4 +296,14 @@ public function addItem(ItemInterface $item) { $this->CartItems->add($item); } + + /** + * 個数の合計を返します。 + * + * @return mixed + */ + public function getQuantity() + { + return $this->getTotalQuantity(); + } } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index 1a167de77f3..a0def3e9ada 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -35,6 +35,13 @@ public function getTotal(); */ public function setTotal($total); + /** + * 個数の合計を返します。 + * + * @return mixed + */ + public function getQuantity(); + /** * @param ItemInterface $item */ diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index c4aa28d3257..d26a337b359 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1896,4 +1896,14 @@ public function addItem(ItemInterface $item) { $this->ShipmentItems->add($item); } + + public function getQuantity() + { + $quantity = 0; + foreach($this->getItems() as $item) { + $quantity += $item->getQuantity(); + } + + return $quantity; + } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php new file mode 100644 index 00000000000..13f4044cb1e --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php @@ -0,0 +1,88 @@ +app = $app; + } + + /** + * @param ItemHolderInterface $itemHolder + * @return ProcessResult + */ + public function process(ItemHolderInterface $itemHolder) + { + /* @var $BaseInfo \Eccube\Entity\BaseInfo */ + $BaseInfo = $this->app['eccube.repository.base_info']->get(); + + $isDeliveryFree = false; + + if ($BaseInfo->getDeliveryFreeAmount()) { + if ($BaseInfo->getDeliveryFreeAmount() <= $itemHolder->getTotal()) { + // 送料無料(金額)を超えている + $isDeliveryFree = true; + } + } + + if ($BaseInfo->getDeliveryFreeQuantity()) { + if ($BaseInfo->getDeliveryFreeQuantity() <= $itemHolder->getQuantity()) { + // 送料無料(個数)を超えている + $isDeliveryFree = true; + } + } + + // 送料無料条件に合致した場合は、送料明細の個数を0に設定 + if ($isDeliveryFree) { + $items = $itemHolder->getItems(); + foreach ($items as $item) { + if ($item->isDeliveryFee()) { + $item->setQuantity(0); + } + } + } + + return ProcessResult::success(); + } +} diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php new file mode 100644 index 00000000000..e46db55a183 --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php @@ -0,0 +1,122 @@ +processor = new DeliveryFeeFreeProcessor($this->app); + $this->Order = $this->createOrder($this->createCustomer()); + } + + public function testNewInstance() + { + self::assertInstanceOf(DeliveryFeeFreeProcessor::class, $this->processor); + } + + /** + * 送料無料条件に合致しない場合 + */ + public function testProcess() + { + $result = $this->processor->process($this->Order); + self::assertInstanceOf(ProcessResult::class, $result); + self::assertFalse($result->isError()); + + $items = $this->getDeliveryFeeItems($this->Order); + foreach ($items as $item) { + self::assertEquals(1, $item->getQuantity()); + } + } + + /** + * 送料無料条件(金額)に合致する場合, 送料明細の個数は0になる + */ + public function testProcessWithAmount() + { + /** @var BaseInfo $BaseInfo */ + $BaseInfo = $this->app['eccube.repository.base_info']->get(); + $BaseInfo->setDeliveryFreeAmount(1); // 1円以上で送料無料 + + $result = $this->processor->process($this->Order); + self::assertInstanceOf(ProcessResult::class, $result); + self::assertFalse($result->isError()); + + $items = $this->getDeliveryFeeItems($this->Order); + foreach ($items as $item) { + self::assertEquals(0, $item->getQuantity()); + } + } + + /** + * 送料無料条件(個数)に合致する場合, 送料明細の個数は0になる + */ + public function testProcessWithQuantity() + { + /** @var BaseInfo $BaseInfo */ + $BaseInfo = $this->app['eccube.repository.base_info']->get(); + $BaseInfo->setDeliveryFreeQuantity(1); // 1個以上で送料無料 + + $result = $this->processor->process($this->Order); + self::assertInstanceOf(ProcessResult::class, $result); + self::assertFalse($result->isError()); + + $items = $this->getDeliveryFeeItems($this->Order); + foreach ($items as $item) { + self::assertEquals(0, $item->getQuantity()); + } + } + + private function getDeliveryFeeItems(Order $Order) + { + $deliveryFeeItems = []; + foreach ($Order->getShipmentItems() as $item) { + if ($item->isDeliveryFee()) { + $deliveryFeeItems[] = $item; + } + } + + return $deliveryFeeItems; + } +} From 2fcccfd6740fd321f55f8e20c032d2898b340e41 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 17:42:59 +0900 Subject: [PATCH 19/75] =?UTF-8?q?=E8=B2=A9=E5=A3=B2=E5=88=B6=E9=99=90?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E3=83=97=E3=83=AD=E3=82=BB=E3=83=83=E3=82=B5?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/SaleLimitValidator.php | 28 +++++++++++++++++++ .../ServiceProvider/EccubeServiceProvider.php | 8 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php new file mode 100644 index 00000000000..5f89a832f9b --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -0,0 +1,28 @@ +getProductClass()->getSaleLimit(); + $quantity = $item->getQuantity(); + if ($limit < $quantity) { + throw new ItemValidateException('販売制限数!'); + } + } + + protected function handle(ItemInterface $item) + { + $limit = $item->getProductClass()->getSaleLimit(); + $item->setQuantity($limit); + } +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 5647aea0200..b10171978c3 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -26,9 +26,11 @@ use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; +use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; +use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; use Eccube\Service\PurchaseFlow\Processor\StockValidator; use Eccube\Service\PurchaseFlow\PurchaseFlow; use Pimple\Container; @@ -530,9 +532,13 @@ public function register(Container $app) $app['eccube.purchase.flow.cart'] = function () use ($app) { $flow = new PurchaseFlow(); - $flow->addItemProcessor(new StockValidator()); $flow->addItemProcessor(new DisplayStatusValidator()); + $flow->addItemProcessor(new StockValidator()); + $flow->addItemProcessor(new SaleLimitValidator()); + $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + $flow->addItemHolderProcessor(new DeliveryFeeFreeProcessor($app)); + return $flow; }; From b1b38fe8c45a2ef545dbea4d2488f9683fb33f33 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 17:43:29 +0900 Subject: [PATCH 20/75] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9=E3=81=AE=E3=81=A4?= =?UTF-8?q?=E3=81=AA=E3=81=8E=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 178 +++++++---------------- 1 file changed, 50 insertions(+), 128 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 5a83b0cbca4..1bedb14e006 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -25,11 +25,9 @@ namespace Eccube\Controller; use Eccube\Application; -use Eccube\Entity\CartItem; use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; -use Eccube\Exception\CartException; use Symfony\Component\HttpFoundation\Request; class CartController extends AbstractController @@ -46,25 +44,17 @@ public function index(Application $app, Request $request) // カートの集計結果を取得 $Cart = $app['eccube.service.cart']->getCart(); $app['eccube.purchase.flow.cart']->execute($Cart); + $app['eccube.service.cart']->save(); - // FRONT_CART_INDEX_INITIALIZE - $event = new EventArgs( - array(), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_INDEX_INITIALIZE, $event); - - // FRONT_CART_INDEX_COMPLETE - $event = new EventArgs( - array(), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_INDEX_COMPLETE, $event); - - if ($event->hasResponse()) { - return $event->getResponse(); + foreach ($Cart->getErrors() as $error) { + $app->addRequestError($error); } + // TODO purchaseFlow/itemHolderから取得できるように + $least = 0; + $quantity = 0; + $isDeliveryFree = false; + return $app->render( 'Cart/index.twig', array( @@ -97,51 +87,18 @@ public function up(Application $app, Request $request, $productClassId) return $app->redirect($app->url('cart')); } - // FRONT_CART_UP_INITIALIZE - $event = new EventArgs( - array( - 'ProductClass' => $ProductClass - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_INITIALIZE, $event); - $Cart = $app['eccube.service.cart']->getCart(); - $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); if ($Exists) { $Exists->setQuantity($Exists->getQuantity() + 1); - } else { - $CartItem = new CartItem(); - $CartItem - ->setClassName(ProductClass::class) - ->setClassId($productClassId) - ->setObject($ProductClass) - ->setPrice($ProductClass->getPrice02IncTax()) - ->setQuantity(1); - $Cart->addItem($CartItem); } $app['eccube.purchase.flow.cart']->execute($Cart); + $app['eccube.service.cart']->save(); - // FRONT_CART_UP_COMPLETE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_COMPLETE, $event); - - $errors = $Cart->getErrors(); - - if (empty($errors)) { - $app['eccube.service.cart']->save(); - } else { - foreach($errors as $error) { - $app->addRequestError($error); - } + foreach ($Cart->getErrors() as $error) { + $app->addRequestError($error); } log_info('カート加算処理終了', array('product_class_id' => $productClassId)); @@ -162,56 +119,33 @@ public function down(Application $app, Request $request, $productClassId) { $this->isTokenValid($app); - // FRONT_CART_DOWN_INITIALIZE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_INITIALIZE, $event); - - try { - - log_info('カート減算処理開始', array('product_class_id' => $productClassId)); - - $productClassId = $event->getArgument('productClassId'); - $app['eccube.service.cart']->downProductQuantity($productClassId)->save(); + log_info('カート減算処理開始', array('product_class_id' => $productClassId)); - // FRONT_CART_UP_COMPLETE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_COMPLETE, $event); - - if ($event->hasResponse()) { - return $event->getResponse(); - } + /** @var ProductClass $ProductClass */ + $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - log_info('カート減算処理完了', array('product_class_id' => $productClassId)); + if (is_null($ProductClass)) { + return $app->redirect($app->url('cart')); + } - } catch (CartException $e) { - log_info('カート減算エラー', array($e->getMessage())); + $Cart = $app['eccube.service.cart']->getCart(); + $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - // FRONT_CART_DOWN_EXCEPTION - $event = new EventArgs( - array( - 'exception' => $e, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_EXCEPTION, $event); + if ($Exists) { + // 個数の減算 + // 個数が0以下になる場合は、PurchaseFlowで削除されるため、ここではハンドリングしない. + $Exists->setQuantity($Exists->getQuantity() - 1); + } - if ($event->hasResponse()) { - return $event->getResponse(); - } + $app['eccube.purchase.flow.cart']->execute($Cart); + $app['eccube.service.cart']->save(); - $app->addRequestError($e->getMessage()); + foreach ($Cart->getErrors() as $error) { + $app->addRequestError($error); } + log_info('カート減算処理完了', array('product_class_id' => $productClassId)); + return $app->redirect($app->url('cart')); } @@ -227,47 +161,35 @@ public function remove(Application $app, Request $request, $productClassId) { $this->isTokenValid($app); - $Cart = Cart::restore(); - $Cart->remove($productClassId); - $Regi->execute($Cart); - - if ($Regi->hasError()) { - $errors = $Regi->getErrors(); - foreach ($errors as $error) { - $app->addRequestError($error); - } - } - + $this->isTokenValid($app); log_info('カート削除処理開始', array('product_class_id' => $productClassId)); - // FRONT_CART_REMOVE_INITIALIZE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_REMOVE_INITIALIZE, $event); + /** @var ProductClass $ProductClass */ + $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - $productClassId = $event->getArgument('productClassId'); - $app['eccube.service.cart']->removeProduct($productClassId)->save(); + if (is_null($ProductClass)) { + return $app->redirect($app->url('cart')); + } - log_info('カート削除処理完了', array('product_class_id' => $productClassId)); + $Cart = $app['eccube.service.cart']->getCart(); + $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - // FRONT_CART_REMOVE_COMPLETE - $event = new EventArgs( - array( - 'productClassId' => $productClassId, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_REMOVE_COMPLETE, $event); + if ($Exists) { + // 明細の削除 + // PurchaseFlowに削除させるため、0を設定. + $Exists->setQuantity(0); + } - if ($event->hasResponse()) { - return $event->getResponse(); + $app['eccube.purchase.flow.cart']->execute($Cart); + $app['eccube.service.cart']->save(); + + foreach ($Cart->getErrors() as $error) { + $app->addRequestError($error); } + log_info('カート削除処理開始', array('product_class_id' => $productClassId)); + return $app->redirect($app->url('cart')); } From 98c3194d973dd38e517cca21daee8220930d4347 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 17:44:02 +0900 Subject: [PATCH 21/75] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C?= =?UTF-8?q?=E3=82=BB=E3=83=83=E3=82=B7=E3=83=A7=E3=83=B3=E4=B8=AD=E3=81=AB?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E3=81=95=E3=82=8C=E7=B6=9A=E3=81=91=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81=E3=82=AF=E3=83=AA=E3=82=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 1881562e76e..b4e96f881d1 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -59,6 +59,11 @@ class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, I */ private $errors = []; + public function __wakeup() + { + $this->errors = []; + } + public function __construct() { $this->CartItems = new \Doctrine\Common\Collections\ArrayCollection(); From d6e96d5fe27b4502b7fea0cb62a7b18de16ee53b Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 17:44:42 +0900 Subject: [PATCH 22/75] =?UTF-8?q?id=E3=81=8C=E6=96=87=E5=AD=97=E5=88=97?= =?UTF-8?q?=E3=81=A7=E7=99=BB=E9=8C=B2=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=8C=E3=81=82=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index b4e96f881d1..3e6fbe6721c 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -149,7 +149,7 @@ public function addCartItem(CartItem $CartItem) public function getCartItemByIdentifier($class_name, $class_id) { foreach ($this->CartItems as $CartItem) { - if ($CartItem->getClassName() === $class_name && $CartItem->getClassId() === $class_id) { + if ($CartItem->getClassName() === $class_name && $CartItem->getClassId() == $class_id) { return $CartItem; } } @@ -160,7 +160,7 @@ public function getCartItemByIdentifier($class_name, $class_id) public function removeCartItemByIdentifier($class_name, $class_id) { foreach ($this->CartItems as $CartItem) { - if ($CartItem->getClassName() === $class_name && $CartItem->getClassId() === $class_id) { + if ($CartItem->getClassName() === $class_name && $CartItem->getClassId() == $class_id) { $this->CartItems->removeElement($CartItem); } } From 33abbc1f8757e7974a1ceb4ee715c8c731b76a4a Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 6 Jul 2017 17:45:16 +0900 Subject: [PATCH 23/75] =?UTF-8?q?CartService=E3=81=AE=E5=9C=A8=E5=BA=AB?= =?UTF-8?q?=E6=95=B0=E3=80=81=E8=B2=A9=E5=A3=B2=E5=88=B6=E9=99=90=E6=95=B0?= =?UTF-8?q?=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E7=84=A1=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CartService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Eccube/Service/CartService.php b/src/Eccube/Service/CartService.php index e474852d481..8bac519f07f 100644 --- a/src/Eccube/Service/CartService.php +++ b/src/Eccube/Service/CartService.php @@ -652,6 +652,7 @@ private function isProductDisplay(ProductClass $ProductClass) */ private function setProductLimit(ProductClass $ProductClass, $productName, $quantity) { + return; /** * 実際の在庫は ProductClass::ProductStock だが、購入時にロックがかかるため、 From 5baf32ed3aa3e3b35311c134bf647368bd6d0bad Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 6 Jul 2017 17:21:09 +0900 Subject: [PATCH 24/75] =?UTF-8?q?=E9=9B=86=E8=A8=88=E3=83=AD=E3=82=B8?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 43 ++++++++++++ src/Eccube/Entity/ItemHolderInterface.php | 32 ++++++++- .../Service/PurchaseFlow/PurchaseFlow.php | 65 ++++++++++++++++++- 3 files changed, 138 insertions(+), 2 deletions(-) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 3e6fbe6721c..3317b9614ba 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -49,6 +49,11 @@ class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, I */ private $total_price; + /** + * @var integer + */ + private $delivery_fee_total; + /** * @var array */ @@ -311,4 +316,42 @@ public function getQuantity() { return $this->getTotalQuantity(); } + + /** + * {@inheritdoc} + */ + public function setDeliveryFeeTotal($total) { + $this->delivery_fee_total = $total; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getDeliveryFeeTotal() + { + return $this->delivery_fee_total; + } + + /** + * {@inheritdoc} + */ + public function setDiscount($total) { + // TODO quiet + } + + /** + * {@inheritdoc} + */ + public function setCharge($total) { + // TODO quiet + } + + /** + * {@inheritdoc} + */ + public function setTax($total) { + // TODO quiet + } } diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index a0def3e9ada..d801bdbd6e6 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -42,8 +42,38 @@ public function setTotal($total); */ public function getQuantity(); + /** + * 送料合計を設定します。 + * @param $total|int + */ + public function setDeliveryFeeTotal($total); + + /** + * 送料合計を返します。 + * @return int + */ + public function getDeliveryFeeTotal(); + + /** + * 値引き合計を設定します。 + * @param $total|int + */ + public function setDiscount($total); + + /** + * 手数料合計を設定します。 + * @param $total|int + */ + public function setCharge($total); + + /** + * 税額合計を設定します。 + * @param $total|int + */ + public function setTax($total); + /** * @param ItemInterface $item */ public function addItem(ItemInterface $item); -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index f6ce57a0a7a..865d87fd199 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -21,6 +21,10 @@ class PurchaseFlow public function execute(ItemHolderInterface $itemHolder) { + $this->calculateDeliveryFeeTotal($itemHolder); + $this->calculateCharge($itemHolder); + $this->calculateDiscount($itemHolder); + $this->calculateTax($itemHolder); $this->calculateTotal($itemHolder); foreach ($itemHolder->getItems() as $item) { @@ -54,12 +58,71 @@ public function addItemProcessor(ItemProcessor $prosessor) /** * @param ItemHolderInterface $itemHolder */ - private function calculateTotal(ItemHolderInterface $itemHolder) + protected function calculateTotal(ItemHolderInterface $itemHolder) { + // TODO 後方互換のため discount は減算する必要がある? + // Order::getTotalPrice() の依存をどうにかしなければ $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { $sum += $item->getPrice() * $item->getQuantity(); return $sum; }, 0); $itemHolder->setTotal($total); } + + /** + * @param ItemHolderInterface $itemHolder + */ + protected function calculateDeliveryFeeTotal(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems()->filter( + function (ItemInterface $item) { + return $item->isDeliveryFee(); + })->toArray(), function ($sum, ItemInterface $item) { + $sum += $item->getPrice() * $item->getQuantity(); + return $sum; + }, 0); + $itemHolder->setDeliveryFeeTotal($total); + } + + /** + * @param ItemHolderInterface $itemHolder + */ + protected function calculateDiscount(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems()->filter( + function (ItemInterface $item) { + return $item->isDiscount(); + })->toArray(), function ($sum, ItemInterface $item) { + $sum += $item->getPrice() * $item->getQuantity(); + return $sum; + }, 0); + $itemHolder->setDiscount($total); + } + + /** + * @param ItemHolderInterface $itemHolder + */ + protected function calculateCharge(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems()->filter( + function (ItemInterface $item) { + return $item->isCharge(); + })->toArray(), function ($sum, ItemInterface $item) { + $sum += $item->getPrice() * $item->getQuantity(); + return $sum; + }, 0); + $itemHolder->setCharge($total); + } + + /** + * @param ItemHolderInterface $itemHolder + */ + protected function calculateTax(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { + $sum += ($item->getPriceIncTax() - $item->getPrice()) * $item->getQuantity(); + return $sum; + }, 0); + $itemHolder->setTax($total); + } } From 326b183b455959ea43c808c82917bb0f9e94dcd4 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 6 Jul 2017 18:29:55 +0900 Subject: [PATCH 25/75] =?UTF-8?q?Order::discount=20=E3=81=AF=E6=AD=A3?= =?UTF-8?q?=E3=81=AE=E6=95=B4=E6=95=B0,=20Discount=20=E3=81=AA=20ShipmentI?= =?UTF-8?q?tem=20=E3=81=AF=E8=B2=A0=E3=81=AE=E6=95=B4=E6=95=B0=E3=82=92?= =?UTF-8?q?=E7=99=BB=E9=8C=B2=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Form/Type/Admin/OrderType.php | 8 -------- .../Service/PurchaseFlow/PurchaseFlow.php | 18 +++++++++++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index cf0641502ce..df30668a747 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -342,14 +342,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $Order->setPaymentMethod($Payment->getMethod()); } }); - // TODO 手数料, 値引きの集計は CalculateService で - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { - $Order = $event->getData(); - $Order->setDiscount($Order->calculateDiscountTotal()); - // $Order->setCharge($Order->calculateChargeTotal()); - // $Order->setDeliveryFeeTotal($Order->calculateDeliveryFeeTotal()); - $event->setData($Order); - }); // 会員受注の場合、会員の性別/職業/誕生日をエンティティにコピーする $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $Order = $event->getData(); diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 865d87fd199..5faa8585cce 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -60,13 +60,16 @@ public function addItemProcessor(ItemProcessor $prosessor) */ protected function calculateTotal(ItemHolderInterface $itemHolder) { - // TODO 後方互換のため discount は減算する必要がある? - // Order::getTotalPrice() の依存をどうにかしなければ $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPrice() * $item->getQuantity(); + $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); $itemHolder->setTotal($total); + // TODO + if ($itemHolder instanceof \Eccube\Entity\Order) { + // Order には PaymentTotal もセットする + $itemHolder->setPaymentTotal($total); + } } /** @@ -78,7 +81,7 @@ protected function calculateDeliveryFeeTotal(ItemHolderInterface $itemHolder) function (ItemInterface $item) { return $item->isDeliveryFee(); })->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPrice() * $item->getQuantity(); + $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); $itemHolder->setDeliveryFeeTotal($total); @@ -93,10 +96,11 @@ protected function calculateDiscount(ItemHolderInterface $itemHolder) function (ItemInterface $item) { return $item->isDiscount(); })->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPrice() * $item->getQuantity(); + $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); - $itemHolder->setDiscount($total); + // TODO 後方互換のため discount には正の整数を代入する + $itemHolder->setDiscount($total * -1); } /** @@ -108,7 +112,7 @@ protected function calculateCharge(ItemHolderInterface $itemHolder) function (ItemInterface $item) { return $item->isCharge(); })->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPrice() * $item->getQuantity(); + $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); $itemHolder->setCharge($total); From f63234ad45dab5721f1eba523709117f5588ec7d Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 7 Jul 2017 10:31:10 +0900 Subject: [PATCH 26/75] =?UTF-8?q?Order=20=E3=81=AE=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AF=20SubTotal=20=E3=82=92=E9=9B=86=E8=A8=88=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/PurchaseFlow/PurchaseFlow.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 5faa8585cce..12b7514b98b 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -24,6 +24,7 @@ public function execute(ItemHolderInterface $itemHolder) { $this->calculateDeliveryFeeTotal($itemHolder); $this->calculateCharge($itemHolder); $this->calculateDiscount($itemHolder); + $this->calculateSubTotal($itemHolder); // Order の場合のみ $this->calculateTax($itemHolder); $this->calculateTotal($itemHolder); @@ -72,6 +73,21 @@ protected function calculateTotal(ItemHolderInterface $itemHolder) } } + protected function calculateSubTotal(ItemHolderInterface $itemHolder) + { + $total = array_reduce($itemHolder->getItems()->filter( + function (ItemInterface $item) { + return $item->isProduct(); + })->toArray(), function ($sum, ItemInterface $item) { + $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; + }, 0); + // TODO + if ($itemHolder instanceof \Eccube\Entity\Order) { + // Order の場合は SubTotal をセットする + $itemHolder->setSubTotal($total); + } + } /** * @param ItemHolderInterface $itemHolder */ From 8f8a46dc783794d7bb0e6121988fad80243b9880 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 7 Jul 2017 16:13:45 +0900 Subject: [PATCH 27/75] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 150 +++++++----------- .../FrontControllerProvider.php | 3 - src/Eccube/Entity/CartItem.php | 6 + .../Resource/template/default/Cart/index.twig | 6 +- 4 files changed, 64 insertions(+), 101 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 1bedb14e006..2daa10473e2 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -28,10 +28,27 @@ use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; class CartController extends AbstractController { + /** + * 商品追加用コントローラ(デバッグ用) + * + * @Route("/cart/test") + * @param Application $app + */ + public function addTestProduct(Application $app) + { + $ProductClass = $app['eccube.repository.product_class']->find(10); + $app['eccube.service.cart']->setProductQuantity($ProductClass, 1); + $app['eccube.service.cart']->save(); + + return $app->redirect($app->url('cart')); + } + /** * カート画面. * @@ -67,118 +84,61 @@ public function index(Application $app, Request $request) } /** - * カートに入っている商品の個数を1増やす. - * - * @param Application $app - * @param Request $request - * @param $productClassId - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function up(Application $app, Request $request, $productClassId) - { - $this->isTokenValid($app); - - log_info('カート加算処理開始', array('product_class_id' => $productClassId)); - - /** @var ProductClass $ProductClass */ - $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - - if (is_null($ProductClass)) { - return $app->redirect($app->url('cart')); - } - - $Cart = $app['eccube.service.cart']->getCart(); - $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - - if ($Exists) { - $Exists->setQuantity($Exists->getQuantity() + 1); - } - - $app['eccube.purchase.flow.cart']->execute($Cart); - $app['eccube.service.cart']->save(); - - foreach ($Cart->getErrors() as $error) { - $app->addRequestError($error); - } - - log_info('カート加算処理終了', array('product_class_id' => $productClassId)); - - return $app->redirect($app->url('cart')); - } - - /** - * カートに入っている商品の個数を1減らす. - * マイナスになる場合は, 商品をカートから削除する. + * カート明細の加算/減算/削除を行う. * - * @param Application $app - * @param Request $request - * @param $productClassId - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function down(Application $app, Request $request, $productClassId) - { - $this->isTokenValid($app); - - log_info('カート減算処理開始', array('product_class_id' => $productClassId)); - - /** @var ProductClass $ProductClass */ - $ProductClass = $app['eccube.repository.product_class']->find($productClassId); - - if (is_null($ProductClass)) { - return $app->redirect($app->url('cart')); - } - - $Cart = $app['eccube.service.cart']->getCart(); - $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - - if ($Exists) { - // 個数の減算 - // 個数が0以下になる場合は、PurchaseFlowで削除されるため、ここではハンドリングしない. - $Exists->setQuantity($Exists->getQuantity() - 1); - } - - $app['eccube.purchase.flow.cart']->execute($Cart); - $app['eccube.service.cart']->save(); - - foreach ($Cart->getErrors() as $error) { - $app->addRequestError($error); - } - - log_info('カート減算処理完了', array('product_class_id' => $productClassId)); - - return $app->redirect($app->url('cart')); - } - - /** - * カートに入っている商品を削除する. + * - 加算 + * - 明細の個数を1増やす + * - 減算 + * - 明細の個数を1減らす + * - 個数が0になる場合は、明細を削除する + * - 削除 + * - 明細を削除する * + * @Method("PUT") + * @Route( + * path="/cart/{operation}/{productClassId}", + * name="cart_handle_item", + * requirements={ + * "operation": "up|down|remove", + * "productClassId": "\d+" + * } + * ) * @param Application $app * @param Request $request + * @param $operation * @param $productClassId - * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response + * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function remove(Application $app, Request $request, $productClassId) + public function handleCartItem(Application $app, Request $request, $operation, $productClassId) { - $this->isTokenValid($app); + log_info('カート明細操作開始', ['operation' => $operation, 'product_class_id' => $productClassId]); $this->isTokenValid($app); - log_info('カート削除処理開始', array('product_class_id' => $productClassId)); - /** @var ProductClass $ProductClass */ $ProductClass = $app['eccube.repository.product_class']->find($productClassId); if (is_null($ProductClass)) { + log_info('商品が存在しないため、カート画面へredirect', ['operation' => $operation, 'product_class_id' => $productClassId]); + return $app->redirect($app->url('cart')); } $Cart = $app['eccube.service.cart']->getCart(); - $Exists = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - - if ($Exists) { - // 明細の削除 - // PurchaseFlowに削除させるため、0を設定. - $Exists->setQuantity(0); + $CartItem = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); + + if ($CartItem) { + switch ($operation) { + case 'up': + $CartItem->setQuantity($CartItem->getQuantity() + 1); + break; + case 'down': + $CartItem->setQuantity($CartItem->getQuantity() - 1); + break; + case 'remove': + $Cart->getItems()->removeElement($CartItem); + break; + } } $app['eccube.purchase.flow.cart']->execute($Cart); @@ -188,7 +148,7 @@ public function remove(Application $app, Request $request, $productClassId) $app->addRequestError($error); } - log_info('カート削除処理開始', array('product_class_id' => $productClassId)); + log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]); return $app->redirect($app->url('cart')); } diff --git a/src/Eccube/ControllerProvider/FrontControllerProvider.php b/src/Eccube/ControllerProvider/FrontControllerProvider.php index 94977e204f8..52dde5db283 100644 --- a/src/Eccube/ControllerProvider/FrontControllerProvider.php +++ b/src/Eccube/ControllerProvider/FrontControllerProvider.php @@ -48,9 +48,6 @@ public function connect(Application $app) // cart $c->match('/cart', '\Eccube\Controller\CartController::index')->bind('cart'); - $c->put('/cart/up/{productClassId}', '\Eccube\Controller\CartController::up')->bind('cart_up')->assert('productClassId', '\d+'); - $c->put('/cart/down/{productClassId}', '\Eccube\Controller\CartController::down')->bind('cart_down')->assert('productClassId', '\d+'); - $c->put('/cart/remove/{productClassId}', '\Eccube\Controller\CartController::remove')->bind('cart_remove')->assert('productClassId', '\d+'); $c->match('/cart/buystep', '\Eccube\Controller\CartController::buystep')->bind('cart_buystep'); // contact diff --git a/src/Eccube/Entity/CartItem.php b/src/Eccube/Entity/CartItem.php index d80904c0dc0..8ae0462fcd6 100644 --- a/src/Eccube/Entity/CartItem.php +++ b/src/Eccube/Entity/CartItem.php @@ -209,4 +209,10 @@ public function getProductClass() { return $this->getObject(); } + + public function getPriceIncTax() + { + // TODO ItemInterfaceに追加, Cart::priceは税込み金額が入っているので,フィールドを分ける必要がある + return $this->price; + } } diff --git a/src/Eccube/Resource/template/default/Cart/index.twig b/src/Eccube/Resource/template/default/Cart/index.twig index 731c068fae4..034b9b70736 100644 --- a/src/Eccube/Resource/template/default/Cart/index.twig +++ b/src/Eccube/Resource/template/default/Cart/index.twig @@ -116,7 +116,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -147,13 +147,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  • {% if CartItem.quantity > 1 %} - + {% else %} {% endif %}
  • - +
From a2f07a425444522f1ca2493e56cc042129cf6889 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 7 Jul 2017 17:54:56 +0900 Subject: [PATCH 28/75] =?UTF-8?q?=E9=85=8D=E9=80=81=E6=A5=AD=E8=80=85?= =?UTF-8?q?=E3=81=AE=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E7=94=A8=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=82=BB=E3=83=83=E3=82=B5=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/DeliverySettingValidator.php | 43 +++++++++++ .../ServiceProvider/EccubeServiceProvider.php | 2 + .../DeliverySettingValidatorTest.php | 73 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php new file mode 100644 index 00000000000..d65c604be0f --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php @@ -0,0 +1,43 @@ +deliveryRepository = $deliveryRepository; + } + + protected function validate(ItemInterface $item) + { + if (!$item->isProduct()) { + return; + } + + $ProductType = $item->getProductClass()->getProductType(); + $Deliveries = $this->deliveryRepository->findBy(['ProductType' => $ProductType]); + + if (empty($Deliveries)) { + throw new ItemValidateException('配送準備ができていないエラー'); + } + } + + protected function handle(ItemInterface $item) + { + $item->setQuantity(0); + } +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index b10171978c3..883847f480c 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -28,6 +28,7 @@ use Eccube\Service\OrderHelper; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; +use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; @@ -535,6 +536,7 @@ public function register(Container $app) $flow->addItemProcessor(new DisplayStatusValidator()); $flow->addItemProcessor(new StockValidator()); $flow->addItemProcessor(new SaleLimitValidator()); + $flow->addItemProcessor(new DeliverySettingValidator($app['eccube.repository.delivery'])); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); $flow->addItemHolderProcessor(new DeliveryFeeFreeProcessor($app)); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php new file mode 100644 index 00000000000..48b10267e48 --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php @@ -0,0 +1,73 @@ +Product = $this->createProduct('テスト商品', 1); + $this->ProductClass = $this->Product->getProductClasses()[0]; + $this->validator = new DeliverySettingValidator($this->app['eccube.repository.delivery']); + $this->cartItem = new CartItem(); + $this->cartItem->setObject($this->ProductClass); + } + + public function testInstance() + { + self::assertInstanceOf(DeliverySettingValidator::class, $this->validator); + } + + /** + * 配送業者が適切に設定されていれば何もしない + */ + public function testDeliverySettingIsValid() + { + $result = $this->validator->process($this->cartItem); + + self::assertFalse($result->isError()); + } + + /** + * 配送業者が設定できていない商品の場合は明細の個数を0に設定する + */ + public function testDisplayStatusWithClosed() + { + $ProductType = new ProductType(); + $ProductType->setId(10000); + $this->ProductClass->setProductType($ProductType); + + $this->validator->process($this->cartItem); + + self::assertEquals(0, $this->cartItem->getQuantity()); + } +} From fd8e4660182377d4c5d360e638d656c2409441ff Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 7 Jul 2017 17:55:14 +0900 Subject: [PATCH 29/75] =?UTF-8?q?=E6=98=8E=E7=B4=B0=E7=A8=AE=E5=88=A5?= =?UTF-8?q?=E3=82=92=E5=88=A4=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/Processor/SaleLimitValidator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 5f89a832f9b..84938bceaff 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -13,6 +13,9 @@ class SaleLimitValidator extends ValidatableItemProcessor { protected function validate(ItemInterface $item) { + if (!$item->isProduct()) { + return; + } $limit = $item->getProductClass()->getSaleLimit(); $quantity = $item->getQuantity(); if ($limit < $quantity) { From e213dbbac3fe1e754df534395101837432b2b8dc Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 7 Jul 2017 17:55:29 +0900 Subject: [PATCH 30/75] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E5=90=8D?= =?UTF-8?q?=E3=81=AE=E8=AA=A4=E3=82=8A=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseFlow/Processor/DisplayStatusValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php index 9fab7d351c0..37cbf776805 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php @@ -10,7 +10,7 @@ use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; use Eccube\Tests\EccubeTestCase; -class StockValidatorTest extends EccubeTestCase +class DisplayStatusValidatorTest extends EccubeTestCase { /** * @var DisplayStatusValidator From 76cf6f2ef8e8a6772afd123f4744169feb3054bc Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Mon, 10 Jul 2017 11:21:19 +0900 Subject: [PATCH 31/75] =?UTF-8?q?=E5=89=8A=E9=99=A4=E6=B8=88=E5=95=86?= =?UTF-8?q?=E5=93=81=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/DeletedProductValidator.php | 27 +++++++ .../ServiceProvider/EccubeServiceProvider.php | 2 + .../Processor/DeletedProductValidatorTest.php | 71 +++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php new file mode 100644 index 00000000000..c63f1a0fcdd --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php @@ -0,0 +1,27 @@ +getProductClass(); + $Product = $ProductClass->getProduct(); + if ($Product->getDelFlg()) { + throw new ItemValidateException(); + } + } + + protected function handle(ItemInterface $item) + { + if ($item instanceof CartItem) { + $item->setQuantity(0); + } + } +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 883847f480c..fd10436c737 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -26,6 +26,7 @@ use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; +use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; @@ -533,6 +534,7 @@ public function register(Container $app) $app['eccube.purchase.flow.cart'] = function () use ($app) { $flow = new PurchaseFlow(); + $flow->addItemProcessor(new DeletedProductValidator()); $flow->addItemProcessor(new DisplayStatusValidator()); $flow->addItemProcessor(new StockValidator()); $flow->addItemProcessor(new SaleLimitValidator()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php new file mode 100644 index 00000000000..e451c6ab77c --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php @@ -0,0 +1,71 @@ +Product = $this->createProduct('テスト商品', 1); + $this->ProductClass = $this->Product->getProductClasses()[0]; + $this->validator = new DeletedProductValidator(); + $this->cartItem = new CartItem(); + $this->cartItem->setObject($this->ProductClass); + } + + public function testInstance() + { + self::assertInstanceOf(DeletedProductValidator::class, $this->validator); + } + + /** + * 削除フラグ(スタータス)が立っていなければ何もしない + */ + public function testProductIsValid() + { + $result = $this->validator->process($this->cartItem); + + self::assertFalse($result->isError()); + } + + /** + * 削除済商品の場合は明細の個数を0に設定する + */ + public function testDisplayStatusWithClosed() + { + $this->Product->setDelFlg(1); + $result = $this->validator->process($this->cartItem); + + self::assertEquals(0, $this->cartItem->getQuantity()); + self::assertTrue($result->isError()); + } +} From 49db40ec489f9c81ecc72c147d87f51d3bfa5d05 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Thu, 6 Jul 2017 18:18:38 +0900 Subject: [PATCH 32/75] =?UTF-8?q?ShoppingController=E3=81=A8PurchaseFlow?= =?UTF-8?q?=E3=81=AE=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/ShoppingController.php | 100 ++++++++++-------- src/Eccube/Entity/Order.php | 9 +- .../Processor/DeliveryFeeProcessor.php | 29 +++-- .../PaymentTotalNegativeValidator.php | 42 ++++++++ src/Eccube/Service/ShoppingService.php | 17 +-- .../ServiceProvider/EccubeServiceProvider.php | 4 +- 6 files changed, 137 insertions(+), 64 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index c10583e3b15..d55162614f8 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -28,9 +28,9 @@ use Eccube\Common\Constant; use Eccube\Entity\Customer; use Eccube\Entity\CustomerAddress; +use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\Master\OrderItemType; -use Eccube\Entity\Master\TaxType; -use Eccube\Entity\Master\TaxDisplayType; +use Eccube\Entity\Order; use Eccube\Entity\ShipmentItem; use Eccube\Entity\Shipping; use Eccube\Event\EccubeEvents; @@ -43,9 +43,7 @@ use Eccube\Form\Type\ShippingMultipleType; use Eccube\Form\Type\Shopping\OrderType; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\HttpFoundation\Request; @@ -107,16 +105,17 @@ public function index(Application $app, Request $request) $app->forwardChain($app->path("shopping/calculateOrder")) ->forwardChain($app->path("shopping/createForm")); - // 受注のマイナスチェック - $response = $app->forward($app->path("shopping/checkToMinusPrice")); - if ($response->isRedirection() || $response->getContent()) { - return $response; + + /** @var Order $Order */ + $Order = $app['request_scope']->get('Order'); + + if (!empty($Order->getErrors())) { + return $app->redirect($app->url('shopping_error')); } - // 複数配送の場合、エラーメッセージを一度だけ表示 + // TODO 複数配送エラーどうする? + // // 複数配送の場合、エラーメッセージを一度だけ表示 $app->forward($app->path("shopping/handleMultipleErrors")); - - $Order = $app['request_scope']->get('Order'); $form = $app['request_scope']->get(OrderType::class); return [ @@ -282,6 +281,7 @@ public function shipping(Application $app, Request $request, $id) throw new NotFoundHttpException('選択されたお届け先住所が存在しない'); } + /** @var Order $Order */ $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); if (!$Order) { log_info('購入処理中の受注情報がないため購入エラー'); @@ -298,14 +298,17 @@ public function shipping(Application $app, Request $request, $id) log_info('お届先情報更新開始', array($Shipping->getId())); // お届け先情報を更新 - $Shipping - ->setFromCustomerAddress($CustomerAddress); + $Shipping->setFromCustomerAddress($CustomerAddress); // 配送料金の設定 $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); + // 合計金額の再計算 - $Order = $app['eccube.service.shopping']->getAmount($Order); + $this->executePurchaseFlow($app, $Order); + if (!empty($Order->getErrors())) { + return $app->redirect($app->url('shopping_error')); + } // 配送先を更新 $app['orm.em']->flush(); @@ -579,13 +582,6 @@ public function nonmember(Application $app, Request $request) return $app->redirect($app->url('shopping')); } - // カートチェック - if (count($cartService->getCart()->getCartItems()) <= 0) { - // カートが存在しない時はエラー - log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト'); - return $app->redirect($app->url('cart')); - } - $builder = $app['form.factory']->createBuilder(NonMemberType::class); $event = new EventArgs( @@ -645,6 +641,7 @@ public function nonmember(Application $app, Request $request) $Customer->addCustomerAddress($CustomerAddress); // 受注情報を取得 + /** @var Order $Order */ $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); // 初回アクセス(受注データがない)の場合は, 受注情報を作成 @@ -663,6 +660,14 @@ public function nonmember(Application $app, Request $request) } } + $this->executePurchaseFlow($app, $Order); + if (!empty($Order->getErrors())) { + foreach ($Order->getErrors() as $error) { + $app->addRequestError($error); + } + return $app->redirect($app->url('cart')); + } + // 非会員用セッションを作成 $nonMember = array(); $nonMember['customer'] = $Customer; @@ -929,6 +934,11 @@ public function shippingMultiple(Application $app, Request $request) // 合計金額の再計算 $Order = $app['eccube.service.shopping']->getAmount($Order); + $this->executePurchaseFlow($app, $Order); + if (!empty($Order->getErrors())) { + return $app->redirect($app->url('shopping_error')); + } + // 配送先を更新 $app['orm.em']->flush(); @@ -1174,6 +1184,7 @@ public function checkToCart(Application $app, Request $request) // カートが存在しない時はエラー return $app->redirect($app->url('cart')); } + return new Response(); } @@ -1244,7 +1255,8 @@ public function calculateOrder(Application $app, Request $request) $Order = $app['request_scope']->get('Order'); // 構築したOrderを集計する. - $app['eccube.service.calculate']($Order, $Order->getCustomer())->calculate(); + $this->executePurchaseFlow($app, $Order); + return new Response(); } @@ -1321,30 +1333,9 @@ public function redirectToChange(Application $app, Request $request) return new Response(); } - /** - * 受注合計のマイナスをチェックする - * - * @Route("/checkToMinusPrice", name="shopping/checkToMinusPrice") - * @param Application $app - * @param Request $request - * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response - */ - public function checkToMinusPrice(Application $app, Request $request) - { - $Order = $app['request_scope']->get('Order'); - if ($Order->getTotalPrice() < 0) { - // 合計金額がマイナスの場合、エラー - log_info('受注金額マイナスエラー', array($Order->getId())); - $message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice()))); - $app->addError($message); - - return $app->redirect($app->url('shopping_error')); - } - return new Response(); - } - /** * 複数配送時のエラーを表示する + * TODO ItemHolderProcessor化? * * @Route("/handleMultipleErrors", name="shopping/handleMultipleErrors") * @param Application $app @@ -1405,13 +1396,14 @@ public function existsOrder(Application $app, Request $request) */ public function completeOrder(Application $app, Request $request) { - $Order = $app['request_scope']->get('Order'); $form = $app['request_scope']->get(OrderType::class); - // requestのバインド後、Calculatorに再集計させる + // requestのバインド後、再集計 $app->forward($app->path("shopping/calculateOrder")); if ($form->isSubmitted() && $form->isValid()) { + + /** @var Order $Order */ $Order = $form->getData(); log_info('購入処理開始', array($Order->getId())); @@ -1430,7 +1422,13 @@ public function completeOrder(Application $app, Request $request) // 集計は,この1行でいけるはず // プラグインで Strategy をセットしたりする // 集計はステートレスな実装とし、再計算時に状態を考慮しなくても良いようにする - $app['eccube.service.calculate']($Order, $Order->getCustomer())->calculate(); +// $app['eccube.service.calculate']($Order, $Order->getCustomer())->calculate(); + $this->executePurchaseFlow($app, $Order); + if (!empty($Order->getErrors())) { + // TODO エラーメッセージ + throw new ShoppingException(); + } + // Order も引数で渡すのがベスト?? $paymentService = $app['eccube.service.payment']($Order->getPayment()->getServiceClass()); @@ -1542,4 +1540,12 @@ public function afterComplete(Application $app, Request $request) // 完了画面表示 return $app->redirect($app->url('shopping_complete')); } + + private function executePurchaseFlow(Application $app, ItemHolderInterface $itemHolder) + { + $app['eccube.purchase.flow.shopping']->execute($itemHolder); + foreach ($itemHolder->getErrors() as $error) { + $app->addRequestError($error); + } + } } diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index d26a337b359..3fe75c253e0 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -42,6 +42,11 @@ */ class Order extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface { + /** + * @var ItemValidateException[] + */ + private $errors = []; + /** * isMultiple * @@ -1878,7 +1883,7 @@ public function getOrderStatus() */ public function addError($error) { - // TODO: Implement addError() method. + $this->errors[] = $error; } /** @@ -1886,7 +1891,7 @@ public function addError($error) */ public function getErrors() { - // TODO: Implement getErrors() method. + return $this->errors; } /** diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php index b34cd9c97f4..bc33ddb81aa 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -57,15 +57,32 @@ public function __construct($app) */ public function process(ItemHolderInterface $itemHolder) { - /** - * @var ShipmentItem $ShipmentItem - */ - foreach ($itemHolder->getItems() as $ShipmentItem) { - if ($ShipmentItem->isDeliveryFee()) { - return; + if ($this->containsDeliveryFeeItem($itemHolder) == false) { + $this->addDeliveryFeeItem($itemHolder); + } + return ProcessResult::success(); + } + + /** + * @param ItemHolderInterface $itemHolder + * @return bool + */ + private function containsDeliveryFeeItem(ItemHolderInterface $itemHolder) + { + foreach ($itemHolder->getItems() as $item) { + if ($item->isDeliveryFee()) { + return true; } } + return false; + } + /** + * TODO 送料無料計算 + * @param ItemHolderInterface $itemHolder + */ + private function addDeliveryFeeItem(ItemHolderInterface $itemHolder) + { $DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE); // TODO $TaxInclude = $this->app['orm.em']->getRepository(TaxDisplayType::class)->find(TaxDisplayType::INCLUDED); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php new file mode 100644 index 00000000000..c59cacd87a8 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php @@ -0,0 +1,42 @@ +getTotal() < 0) { + throw new ItemValidateException('shopping.total.price'); + } + } +} \ No newline at end of file diff --git a/src/Eccube/Service/ShoppingService.php b/src/Eccube/Service/ShoppingService.php index 33a496ccad8..ba959c450c8 100644 --- a/src/Eccube/Service/ShoppingService.php +++ b/src/Eccube/Service/ShoppingService.php @@ -1173,14 +1173,15 @@ public function processPurchase(Order $Order) $em = $this->app['orm.em']; - // 合計金額の再計算 - $this->calculatePrice($Order); - - // 商品公開ステータスチェック、商品制限数チェック、在庫チェック - $check = $this->isOrderProduct($em, $Order); - if (!$check) { - throw new ShoppingException('front.shopping.stock.error'); - } + // TODO PurchaseFlowでやる +// // 合計金額の再計算 +// $this->calculatePrice($Order); +// +// // 商品公開ステータスチェック、商品制限数チェック、在庫チェック +// $check = $this->isOrderProduct($em, $Order); +// if (!$check) { +// throw new ShoppingException('front.shopping.stock.error'); +// } // 受注情報、配送情報を更新 $Order = $this->calculateDeliveryFee($Order); diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index fd10436c737..cb26dd25ad5 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -31,6 +31,7 @@ use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; +use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; use Eccube\Service\PurchaseFlow\Processor\StockValidator; @@ -542,7 +543,7 @@ public function register(Container $app) $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); $flow->addItemHolderProcessor(new DeliveryFeeFreeProcessor($app)); - + $flow->addItemHolderProcessor(new PaymentTotalNegativeValidator()); return $flow; }; @@ -552,6 +553,7 @@ public function register(Container $app) $flow->addItemProcessor(new DisplayStatusValidator()); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); $flow->addItemHolderProcessor(new DeliveryFeeProcessor($app)); + $flow->addItemHolderProcessor(new PaymentTotalNegativeValidator()); return $flow; }; From ed770dcb2abbc583af86bfdbbcdf6bbd267b4db4 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Mon, 10 Jul 2017 14:43:31 +0900 Subject: [PATCH 33/75] =?UTF-8?q?=E5=90=8C=E4=B8=80=E6=94=AF=E6=89=95?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=82=92=E6=A4=9C=E7=9F=A5=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=97=E3=83=AD=E3=82=BB=E3=83=83=E3=82=B5=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 14 ++ .../Processor/PaymentProcessor.php | 131 ++++++++++++++ .../ValidatableItemHolderProcessor.php | 4 +- .../ServiceProvider/EccubeServiceProvider.php | 2 + .../Processor/PaymentProcessorTest.php | 160 ++++++++++++++++++ 5 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 3317b9614ba..094409c20ae 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -59,6 +59,11 @@ class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, I */ private $Payments = array(); + /** + * @var ItemInterface + */ + private $lastAddedItem; + /** * @var ItemValidateException[] */ @@ -69,6 +74,14 @@ public function __wakeup() $this->errors = []; } + /** + * @return ItemInterface + */ + public function getLastAddedItem() + { + return $this->lastAddedItem; + } + public function __construct() { $this->CartItems = new \Doctrine\Common\Collections\ArrayCollection(); @@ -304,6 +317,7 @@ public function getErrors() */ public function addItem(ItemInterface $item) { + $this->lastAddedItem = $item; $this->CartItems->add($item); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php new file mode 100644 index 00000000000..37dc51e769c --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -0,0 +1,131 @@ +app = $app; + } + + protected function validate(ItemHolderInterface $itemHolder) + { + // 明細の個数が1以下の場合はOK + if (count($itemHolder->getItems()) <= 1) { + return; + } + // 最後に追加した明細がない場合はOK + $lastAddedItem = $itemHolder->getLastAddedItem(); + if (is_null($lastAddedItem)) { + return; + } + + $lastAddedItemDeliveries = $this->getDeliveries($lastAddedItem->getProductClass()->getProductType()); + $lastAddedItemPayments = $this->getPayments($lastAddedItemDeliveries); + + $paymentExists = false; + foreach ($itemHolder->getItems() as $item) { + if (false === $item->isProduct()) { + continue; + } + if ($item->getProductClass()->getId() === $lastAddedItem->getProductClass()->getId()) { + continue; + } + $Deliveries = $this->getDeliveries($item->getProductClass()->getProductType()); + $Payments = $this->getPayments($Deliveries); + foreach ($Payments as $Payment) { + foreach ($lastAddedItemPayments as $lastAddedItemPayment) { + if ($Payment->getId() === $lastAddedItemPayment->getId()) { + $paymentExists = true; + break; + } + } + } + } + + if (false === $paymentExists) { + throw new ItemValidateException(); + } + } + + public function handle(ItemHolderInterface $itemHolder) + { + if ($itemHolder instanceof Cart) { + $lastAddedItem = $itemHolder->getLastAddedItem(); + $itemHolder->removeCartItemByIdentifier( + ProductClass::class, + $lastAddedItem->getProductClass()->getId() + ); + } + } + + private function getDeliveries(ProductType $ProductType) + { + $Deliveries = $this->app['orm.em']->getRepository(Delivery::class) + ->findBy( + [ + 'ProductType' => $ProductType, + ] + ); + + return $Deliveries; + } + + private function getPayments($Deliveries) + { + $Payments = new ArrayCollection(); + foreach ($Deliveries as $Delivery) { + $PaymentOptions = $Delivery->getPaymentOptions(); + foreach ($PaymentOptions as $PaymentOption) { + $Payments->add($PaymentOption->getPayment()); + } + } + + return $Payments; + } +} diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php index f64018a984f..23a5a2bac4b 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php @@ -22,7 +22,7 @@ public final function process(ItemHolderInterface $itemHolder) } } - protected abstract function validate(ItemHolderInterface $item); + protected abstract function validate(ItemHolderInterface $itemHolder); - protected function handle(ItemHolderInterface $item) {} + protected function handle(ItemHolderInterface $itemHolder) {} } diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index cb26dd25ad5..65375e6b5bc 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -32,6 +32,7 @@ use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator; +use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; use Eccube\Service\PurchaseFlow\Processor\StockValidator; @@ -541,6 +542,7 @@ public function register(Container $app) $flow->addItemProcessor(new SaleLimitValidator()); $flow->addItemProcessor(new DeliverySettingValidator($app['eccube.repository.delivery'])); + $flow->addItemHolderProcessor(new PaymentProcessor($app)); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); $flow->addItemHolderProcessor(new DeliveryFeeFreeProcessor($app)); $flow->addItemHolderProcessor(new PaymentTotalNegativeValidator()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php new file mode 100644 index 00000000000..63b177ef047 --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php @@ -0,0 +1,160 @@ +setId(1000); + $ProductType->setName('テスト種別'); + $ProductType->setRank(1000); + $this->app['orm.em']->persist($ProductType); + $this->app['orm.em']->flush($ProductType); + + $Delivery = new Delivery(); + $Delivery->setName('テスト配送'); + $Delivery->setProductType($ProductType); + $Delivery->setDelFlg(0); + $this->app['orm.em']->persist($Delivery); + $this->app['orm.em']->flush($Delivery); + + $Payment = new Payment(); + $Payment->setMethod('テスト支払'); + $this->app['orm.em']->persist($Payment); + $this->app['orm.em']->flush($Payment); + + $PaymentOption = new PaymentOption(); + $PaymentOption->setDeliveryId($Delivery->getId()); + $PaymentOption->setDelivery($Delivery); + $PaymentOption->setPaymentId($Payment->getId()); + $PaymentOption->setPayment($Payment); + $this->app['orm.em']->persist($PaymentOption); + $this->app['orm.em']->flush($PaymentOption); + + $this->Product = $this->createProduct('テスト商品', 3); + $this->ProductClass1 = $this->Product->getProductClasses()[0]; + $this->ProductClass2 = $this->Product->getProductClasses()[1]; + $this->ProductClass3 = $this->Product->getProductClasses()[2]; + $this->ProductClass3->setProductType($ProductType); + + $this->validator = new PaymentProcessor($this->app); + } + + public function testInstance() + { + self::assertInstanceOf(PaymentProcessor::class, $this->validator); + } + + public function testCartNoItems() + { + $cart = new Cart(); + $result = $this->validator->process($cart); + + self::assertFalse($result->isError()); + } + + public function testCartOneItem() + { + $cart = new Cart(); + $item = new CartItem(); + $item->setObject($this->ProductClass1); + $cart->addItem($item); + + $result = $this->validator->process($cart); + + self::assertFalse($result->isError()); + } + + public function testCartValidItems() + { + $cart = new Cart(); + $item1 = new CartItem(); + $item1->setObject($this->ProductClass1); + $cart->addItem($item1); + + $item2 = new CartItem(); + $item2->setObject($this->ProductClass2); + $cart->addItem($item2); + + $result = $this->validator->process($cart); + + self::assertFalse($result->isError()); + } + + public function testCartInValidItems() + { + $cart = new Cart(); + $item1 = new CartItem(); + $item1->setClassName(ProductClass::class); + $item1->setClassId($this->ProductClass1->getId()); + $item1->setObject($this->ProductClass1); + $cart->addItem($item1); + + $item2 = new CartItem(); + $item1->setClassName(ProductClass::class); + $item1->setClassId($this->ProductClass2->getId()); + $item2->setObject($this->ProductClass2); + $cart->addItem($item2); + + $item3 = new CartItem(); + $item1->setClassName(ProductClass::class); + $item1->setClassId($this->ProductClass3->getId()); + $item3->setObject($this->ProductClass3); + $cart->addItem($item3); + + $result = $this->validator->process($cart); + + self::assertTrue($result->isError()); + self::assertCount(2, $cart->getItems()); + } +} From 756ebc229b42816aff4a426305dae116d0ad5e00 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Mon, 10 Jul 2017 14:46:47 +0900 Subject: [PATCH 34/75] =?UTF-8?q?=E5=90=84=E5=90=88=E8=A8=88=E9=87=91?= =?UTF-8?q?=E9=A1=8D=E3=81=AE=E8=A8=88=E7=AE=97=E3=82=92PurchaseFlow?= =?UTF-8?q?=E3=81=A7=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/ShoppingController.php | 20 ++++++++------------ src/Eccube/Service/ShoppingService.php | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index d55162614f8..be6bf154e3f 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -113,8 +113,7 @@ public function index(Application $app, Request $request) return $app->redirect($app->url('shopping_error')); } - // TODO 複数配送エラーどうする? - // // 複数配送の場合、エラーメッセージを一度だけ表示 + // 複数配送の場合、エラーメッセージを一度だけ表示 $app->forward($app->path("shopping/handleMultipleErrors")); $form = $app['request_scope']->get(OrderType::class); @@ -363,6 +362,7 @@ public function shippingEdit(Application $app, Request $request, $id) return $response; } + /** @var Order $Order */ $Order = $app['request_scope']->get('Order'); $Shipping = $Order->findShipping($id); @@ -416,7 +416,10 @@ public function shippingEdit(Application $app, Request $request, $id) $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); // 合計金額の再計算 - $app['eccube.service.shopping']->getAmount($Order); + $this->executePurchaseFlow($app, $Order); + if (!empty($Order->getErrors())) { + return $app->redirect($app->url('shopping_error')); + } // 配送先を更新 $app['orm.em']->flush(); @@ -932,8 +935,6 @@ public function shippingMultiple(Application $app, Request $request) } // 合計金額の再計算 - $Order = $app['eccube.service.shopping']->getAmount($Order); - $this->executePurchaseFlow($app, $Order); if (!empty($Order->getErrors())) { return $app->redirect($app->url('shopping_error')); @@ -1416,19 +1417,14 @@ public function completeOrder(Application $app, Request $request) // FormTypeで更新されるため不要 //$app['eccube.service.shopping']->setFormData($Order, $data); - // 購入処理 - $app['eccube.service.shopping']->processPurchase($Order); // XXX フロント画面に依存してるので管理画面では使えない - - // 集計は,この1行でいけるはず - // プラグインで Strategy をセットしたりする - // 集計はステートレスな実装とし、再計算時に状態を考慮しなくても良いようにする -// $app['eccube.service.calculate']($Order, $Order->getCustomer())->calculate(); $this->executePurchaseFlow($app, $Order); if (!empty($Order->getErrors())) { // TODO エラーメッセージ throw new ShoppingException(); } + // 購入処理 + $app['eccube.service.shopping']->processPurchase($Order); // XXX フロント画面に依存してるので管理画面では使えない // Order も引数で渡すのがベスト?? $paymentService = $app['eccube.service.payment']($Order->getPayment()->getServiceClass()); diff --git a/src/Eccube/Service/ShoppingService.php b/src/Eccube/Service/ShoppingService.php index ba959c450c8..6d5064fe9fa 100644 --- a/src/Eccube/Service/ShoppingService.php +++ b/src/Eccube/Service/ShoppingService.php @@ -631,7 +631,7 @@ public function getProductDeliveryFee(Shipping $Shipping) /** * 住所などの情報が変更された時に金額の再計算を行う - * + * @deprecated PurchaseFlowで行う * @param Order $Order * @return Order */ From 7ac6f14d2b4a931812a576bb666f8fe58c188743 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Mon, 10 Jul 2017 17:17:17 +0900 Subject: [PATCH 35/75] =?UTF-8?q?ValidatableItemHolderProcessor=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=BF=E3=83=BC=E3=83=95=E3=82=A7=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/ProcessResult.php | 35 +++++++-- .../Service/PurchaseFlow/PurchaseFlow.php | 25 +++---- .../PurchaseFlow/PurchaseFlowResult.php | 75 +++++++++++++++++++ .../ValidatableItemHolderProcessor.php | 7 +- .../PurchaseFlow/ValidatableItemProcessor.php | 2 +- 5 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php diff --git a/src/Eccube/Service/PurchaseFlow/ProcessResult.php b/src/Eccube/Service/PurchaseFlow/ProcessResult.php index 0c8ad371a68..bcc645bc04f 100644 --- a/src/Eccube/Service/PurchaseFlow/ProcessResult.php +++ b/src/Eccube/Service/PurchaseFlow/ProcessResult.php @@ -5,32 +5,51 @@ class ProcessResult { - protected $error = false; + const ERROR = 'ERROR'; + const WARNING = 'WARNING'; + const SUCCESS = 'SUCCESS'; + + protected $type; protected $message; - private function __construct($error, $message = null) + private function __construct($type, $message = null) { - $this->error = $error; + $this->type = $type; $this->message = $message; } - public static function fail($message) + public static function warn($message) { - return new self(true, $message); + return new self(self::WARNING, $message); + } + + public static function error($message) + { + return new self(self::ERROR, $message); } public static function success() { - return new self(false); + return new self(self::SUCCESS); } public function isError() { - return $this->error; + return $this->type === self::ERROR; + } + + public function isWarning() + { + return $this->type === self::WARNING; + } + + public function isSuccess() + { + return $this->type === self::SUCCESS; } - public function getErrorMessage() + public function getMessage() { return $this->message; } diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 12b7514b98b..503c54b1aa3 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -12,12 +12,12 @@ class PurchaseFlow /** * @var ItemHolderProcessor[] */ - protected $itemHolderProsessors = []; + protected $itemHolderProcessors = []; /** * @var ItemProcessor[] */ - protected $itemProsessors = []; + protected $itemProcessors = []; public function execute(ItemHolderInterface $itemHolder) { @@ -28,32 +28,31 @@ public function execute(ItemHolderInterface $itemHolder) { $this->calculateTax($itemHolder); $this->calculateTotal($itemHolder); + $flowResult = new PurchaseFlowResult($itemHolder); + foreach ($itemHolder->getItems() as $item) { - foreach ($this->itemProsessors as $itemProsessor) { + foreach ($this->itemProcessors as $itemProsessor) { $result = $itemProsessor->process($item); - if ($result->isError()) { - $itemHolder->addError($result->getErrorMessage()); - } + $flowResult->addProcessResult($result); } } - foreach ($this->itemHolderProsessors as $holderProcessor) { + foreach ($this->itemHolderProcessors as $holderProcessor) { $result = $holderProcessor->process($itemHolder); - if ($result->isError()) { - $itemHolder->addError($result->getErrorMessage()); - } + $flowResult->addProcessResult($result); } - return $itemHolder; + + return $flowResult; } public function addItemHolderProcessor(ItemHolderProcessor $prosessor) { - $this->itemHolderProsessors[] = $prosessor; + $this->itemHolderProcessors[] = $prosessor; } public function addItemProcessor(ItemProcessor $prosessor) { - $this->itemProsessors[] = $prosessor; + $this->itemProcessors[] = $prosessor; } /** diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php new file mode 100644 index 00000000000..d916472f394 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php @@ -0,0 +1,75 @@ +itemHolder = $itemHolder; + } + + public function addProcessResult(ProcessResult $processResult) + { + $this->processResults[] = $processResult; + } + + public function getErrors() + { + return array_filter($this->processResults, function(ProcessResult $processResult) { + return $processResult->isError(); + }); + } + + public function getWarning() + { + return array_filter($this->processResults, function(ProcessResult $processResult) { + return $processResult->isWarning(); + }); + } + + public function hasError() + { + return !empty($this->getErrors()); + } + + public function hasWarning() + { + return !empty($this->getWarning()); + } +} \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php index 23a5a2bac4b..daf0ab1f9db 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php @@ -2,7 +2,6 @@ namespace Eccube\Service\PurchaseFlow; -use Eccube\Entity\Cart; use Eccube\Entity\ItemHolderInterface; abstract class ValidatableItemHolderProcessor implements ItemHolderProcessor @@ -14,11 +13,7 @@ public final function process(ItemHolderInterface $itemHolder) return ProcessResult::success(); } catch (ItemValidateException $e) { - if ($itemHolder instanceof Cart) { - $this->handle($itemHolder); - } - - return ProcessResult::fail($e->getMessage()); + return ProcessResult::error($e->getMessage()); } } diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index 922ebdfbdb9..d7f4c0ebfbb 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -44,7 +44,7 @@ public function process(ItemInterface $item) $this->handle($item); } - return ProcessResult::fail($e->getMessage()); + return ProcessResult::warn($e->getMessage()); } } From 2054d4f18ba404ca1885ff1822db17af739f4cdb Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Mon, 10 Jul 2017 17:51:49 +0900 Subject: [PATCH 36/75] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/PurchaseFlow.php | 6 +-- .../Processor/StockValidatorTest.php | 2 +- .../Service/PurchaseFlow/PurchaseFlowTest.php | 51 +++++++++++-------- .../ValidatableItemProcessorTest.php | 2 +- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 503c54b1aa3..d0f085331cb 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -127,9 +127,9 @@ protected function calculateCharge(ItemHolderInterface $itemHolder) function (ItemInterface $item) { return $item->isCharge(); })->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPriceIncTax() * $item->getQuantity(); - return $sum; - }, 0); + $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; + }, 0); $itemHolder->setCharge($total); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php index d116d50c521..7ced34da641 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php @@ -46,7 +46,7 @@ public function testValidStockFail() $result = $this->validator->process($this->cartItem); self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); - self::assertTrue($result->isError()); + self::assertTrue($result->isWarning()); } public function testValidStockOrder() diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php index 7ff0a0728eb..f0c45f34289 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php @@ -6,11 +6,14 @@ use Eccube\Entity\CartItem; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ItemInterface; +use Eccube\Entity\Order; +use Eccube\Entity\ShipmentItem; use Eccube\Service\PurchaseFlow\ItemHolderProcessor; use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ProcessResult; use Eccube\Service\PurchaseFlow\PurchaseFlow; +use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; use Eccube\Tests\EccubeTestCase; @@ -37,7 +40,9 @@ public function testExecute() $this->assertInstanceOf(PurchaseFlow::class, $this->flow); $itemHolder = new Cart(); - $this->assertEquals($itemHolder, $this->flow->execute($itemHolder)); + + $expected = new PurchaseFlowResult($itemHolder); + $this->assertEquals($expected, $this->flow->execute($itemHolder)); } public function testAddProcesser() @@ -54,7 +59,8 @@ public function testProcessItemProcessors() $this->flow->addItemProcessor(new PurchaseFlowTest_ItemProcessor()); $itemHolder = new Cart(); - self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + $expected = new PurchaseFlowResult($itemHolder); + self::assertEquals($expected, $this->flow->execute($itemHolder)); } public function testProcessItemHolderProcessor() @@ -62,7 +68,9 @@ public function testProcessItemHolderProcessor() $this->flow->addItemHolderProcessor(new PurchaseFlowTest_ItemHolderProcessor()); $itemHolder = new Cart(); - self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + $expected = new PurchaseFlowResult($itemHolder); + $expected->addProcessResult(ProcessResult::success()); + self::assertEquals($expected, $this->flow->execute($itemHolder)); } public function testProcessItemHolderProcessor_validationErrors() @@ -70,37 +78,38 @@ public function testProcessItemHolderProcessor_validationErrors() $this->flow->addItemHolderProcessor(new PurchaseFlowTest_FailItemHolderProcessor('error 1')); $itemHolder = new Cart(); - self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); - self::assertEquals(['error 1'], $itemHolder->getErrors()); + $expected = new PurchaseFlowResult($itemHolder); + $expected->addProcessResult(ProcessResult::error('error 1')); + self::assertEquals($expected, $this->flow->execute($itemHolder)); } public function testProcessItemProcessors_validationErrors() { $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); - $itemHolder = new Cart(); - $itemHolder->addCartItem(new CartItem()); - - self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); + $itemHolder = new Order(); + $itemHolder->addShipmentItem(new ShipmentItem()); - self::assertEquals([ - "error 1", "error 2" - ], $itemHolder->getErrors()); + $expected = new PurchaseFlowResult($itemHolder); + $expected->addProcessResult(ProcessResult::warn('error 1')); + $expected->addProcessResult(ProcessResult::warn('error 2')); + self::assertEquals($expected, $this->flow->execute($itemHolder)); } public function testProcessItemProcessors_validationErrors_with_multi_items() { $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); - $itemHolder = new Cart(); - $itemHolder->addCartItem(new CartItem()); - $itemHolder->addCartItem(new CartItem()); - - self::assertEquals($itemHolder, $this->flow->execute($itemHolder)); - - self::assertEquals([ - "error 1", "error 2", "error 1", "error 2" - ], $itemHolder->getErrors()); + $itemHolder = new Order(); + $itemHolder->addShipmentItem(new ShipmentItem()); + $itemHolder->addShipmentItem(new ShipmentItem()); + + $expected = new PurchaseFlowResult($itemHolder); + $expected->addProcessResult(ProcessResult::warn('error 1')); + $expected->addProcessResult(ProcessResult::warn('error 2')); + $expected->addProcessResult(ProcessResult::warn('error 1')); + $expected->addProcessResult(ProcessResult::warn('error 2')); + self::assertEquals($expected, $this->flow->execute($itemHolder)); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php index 40e6cff1533..1503794c1d7 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php @@ -75,7 +75,7 @@ public function testValidateOrderFail() $result = $validator->process($item); self::assertFalse($validator->handleCalled); - self::assertTrue($result->isError()); + self::assertTrue($result->isWarning()); } } From 5c9b7aac85bf73270c8241c020e9f94345755f41 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 11 Jul 2017 10:01:08 +0900 Subject: [PATCH 37/75] =?UTF-8?q?=E6=9C=80=E5=BE=8C=E3=81=AB=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=97=E3=81=9F=E6=98=8E=E7=B4=B0=E3=81=A7=E3=83=8F?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 14 ------ .../Processor/PaymentProcessor.php | 45 +++++++------------ .../Processor/PaymentProcessorTest.php | 7 ++- 3 files changed, 20 insertions(+), 46 deletions(-) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 094409c20ae..3317b9614ba 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -59,11 +59,6 @@ class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, I */ private $Payments = array(); - /** - * @var ItemInterface - */ - private $lastAddedItem; - /** * @var ItemValidateException[] */ @@ -74,14 +69,6 @@ public function __wakeup() $this->errors = []; } - /** - * @return ItemInterface - */ - public function getLastAddedItem() - { - return $this->lastAddedItem; - } - public function __construct() { $this->CartItems = new \Doctrine\Common\Collections\ArrayCollection(); @@ -317,7 +304,6 @@ public function getErrors() */ public function addItem(ItemInterface $item) { - $this->lastAddedItem = $item; $this->CartItems->add($item); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index 37dc51e769c..e036b57a7e7 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -59,48 +59,33 @@ protected function validate(ItemHolderInterface $itemHolder) if (count($itemHolder->getItems()) <= 1) { return; } - // 最後に追加した明細がない場合はOK - $lastAddedItem = $itemHolder->getLastAddedItem(); - if (is_null($lastAddedItem)) { - return; - } - $lastAddedItemDeliveries = $this->getDeliveries($lastAddedItem->getProductClass()->getProductType()); - $lastAddedItemPayments = $this->getPayments($lastAddedItemDeliveries); - - $paymentExists = false; + // a, ab, c + $i = 0; + $paymentIds = []; foreach ($itemHolder->getItems() as $item) { if (false === $item->isProduct()) { continue; } - if ($item->getProductClass()->getId() === $lastAddedItem->getProductClass()->getId()) { - continue; - } $Deliveries = $this->getDeliveries($item->getProductClass()->getProductType()); $Payments = $this->getPayments($Deliveries); + + $ids = []; foreach ($Payments as $Payment) { - foreach ($lastAddedItemPayments as $lastAddedItemPayment) { - if ($Payment->getId() === $lastAddedItemPayment->getId()) { - $paymentExists = true; - break; - } - } + $ids[] = $Payment->getId(); + } + if ($i === 0) { + $paymentIds = $ids; + $i++; + continue; } - } - if (false === $paymentExists) { - throw new ItemValidateException(); + $paymentIds = array_intersect($paymentIds, $ids); } - } - public function handle(ItemHolderInterface $itemHolder) - { - if ($itemHolder instanceof Cart) { - $lastAddedItem = $itemHolder->getLastAddedItem(); - $itemHolder->removeCartItemByIdentifier( - ProductClass::class, - $lastAddedItem->getProductClass()->getId() - ); + // 共通項がなければエラー + if (empty($paymentIds)) { + throw new ItemValidateException(); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php index 63b177ef047..0dc225ef610 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php @@ -70,6 +70,7 @@ public function setUp() $Payment = new Payment(); $Payment->setMethod('テスト支払'); + $Payment->setDelFlg(0); $this->app['orm.em']->persist($Payment); $this->app['orm.em']->flush($Payment); @@ -78,8 +79,10 @@ public function setUp() $PaymentOption->setDelivery($Delivery); $PaymentOption->setPaymentId($Payment->getId()); $PaymentOption->setPayment($Payment); + $Delivery->addPaymentOption($PaymentOption); + $Payment->addPaymentOption($PaymentOption); $this->app['orm.em']->persist($PaymentOption); - $this->app['orm.em']->flush($PaymentOption); + $this->app['orm.em']->flush(); $this->Product = $this->createProduct('テスト商品', 3); $this->ProductClass1 = $this->Product->getProductClasses()[0]; @@ -155,6 +158,6 @@ public function testCartInValidItems() $result = $this->validator->process($cart); self::assertTrue($result->isError()); - self::assertCount(2, $cart->getItems()); + self::assertCount(3, $cart->getItems()); } } From 0df71b9de676ce1f4130521b5eaaf5ee34bbe5aa Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 11 Jul 2017 10:01:27 +0900 Subject: [PATCH 38/75] =?UTF-8?q?purcaseFlow=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=81=AB=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 69 ++++++++++++++++++++---- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 2daa10473e2..6fe1944a9cf 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -25,6 +25,7 @@ namespace Eccube\Controller; use Eccube\Application; +use Eccube\Entity\CartItem; use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; @@ -42,8 +43,14 @@ class CartController extends AbstractController */ public function addTestProduct(Application $app) { - $ProductClass = $app['eccube.repository.product_class']->find(10); - $app['eccube.service.cart']->setProductQuantity($ProductClass, 1); + $CartItem = new CartItem(); + $CartItem + ->setClassName(ProductClass::class) + ->setClassId(10) + ->setPrice(1000) + ->setQuantity(1); + + $app['eccube.service.cart']->getCart()->addItem($CartItem); $app['eccube.service.cart']->save(); return $app->redirect($app->url('cart')); @@ -58,13 +65,25 @@ public function addTestProduct(Application $app) */ public function index(Application $app, Request $request) { - // カートの集計結果を取得 + // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); - $app['eccube.purchase.flow.cart']->execute($Cart); + $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + + // 復旧不可のエラーが発生した場合はカートをクリアして再描画 + if ($Result->hasError()) { + foreach ($Result->getErrors() as $error) { + $app->addRequestError($error); + } + $app['eccube.service.cart']->clear(); + $app['eccube.service.cart']->save(); + + return $app->redirect($app->url('cart')); + } + $app['eccube.service.cart']->save(); - foreach ($Cart->getErrors() as $error) { - $app->addRequestError($error); + foreach ($Result->getWarning() as $warning) { + $app->addRequestError($warning); } // TODO purchaseFlow/itemHolderから取得できるように @@ -124,9 +143,25 @@ public function handleCartItem(Application $app, Request $request, $operation, $ return $app->redirect($app->url('cart')); } + // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); + $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + + // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ + if ($Result->hasError()) { + foreach ($Result->getErrors() as $error) { + $app->addRequestError($error); + } + $app['eccube.service.cart']->clear(); + $app['eccube.service.cart']->save(); + + return $app->redirect($app->url('cart')); + } + + // 明細の取得 $CartItem = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); + // 明細が見つかった場合のみ増減・削除処理を行う if ($CartItem) { switch ($operation) { case 'up': @@ -139,13 +174,25 @@ public function handleCartItem(Application $app, Request $request, $operation, $ $Cart->getItems()->removeElement($CartItem); break; } - } - $app['eccube.purchase.flow.cart']->execute($Cart); - $app['eccube.service.cart']->save(); + $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + + // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ + if ($Result->hasError()) { + foreach ($Result->getErrors() as $error) { + $app->addRequestError($error); + } + $app['eccube.service.cart']->clear(); + $app['eccube.service.cart']->save(); - foreach ($Cart->getErrors() as $error) { - $app->addRequestError($error); + return $app->redirect($app->url('cart')); + } + + $app['eccube.service.cart']->save(); + + foreach ($Result->getWarning() as $warning) { + $app->addRequestError($warning); + } } log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]); From 751ed92cff07866488c919bd6deed43abb84387e Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 11 Jul 2017 11:20:08 +0900 Subject: [PATCH 39/75] =?UTF-8?q?CartService=E3=81=AE=E8=A6=8B=E7=9B=B4?= =?UTF-8?q?=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 65 +- src/Eccube/Service/CartService.php | 658 ++---------------- .../ServiceProvider/EccubeServiceProvider.php | 2 +- 3 files changed, 90 insertions(+), 635 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 6fe1944a9cf..d8b628e630c 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -25,7 +25,6 @@ namespace Eccube\Controller; use Eccube\Application; -use Eccube\Entity\CartItem; use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; @@ -43,14 +42,7 @@ class CartController extends AbstractController */ public function addTestProduct(Application $app) { - $CartItem = new CartItem(); - $CartItem - ->setClassName(ProductClass::class) - ->setClassId(10) - ->setPrice(1000) - ->setQuantity(1); - - $app['eccube.service.cart']->getCart()->addItem($CartItem); + $app['eccube.service.cart']->addProductClass(10, 2); $app['eccube.service.cart']->save(); return $app->redirect($app->url('cart')); @@ -158,41 +150,36 @@ public function handleCartItem(Application $app, Request $request, $operation, $ return $app->redirect($app->url('cart')); } - // 明細の取得 - $CartItem = $Cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - - // 明細が見つかった場合のみ増減・削除処理を行う - if ($CartItem) { - switch ($operation) { - case 'up': - $CartItem->setQuantity($CartItem->getQuantity() + 1); - break; - case 'down': - $CartItem->setQuantity($CartItem->getQuantity() - 1); - break; - case 'remove': - $Cart->getItems()->removeElement($CartItem); - break; - } - - $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + // 明細の増減・削除 + switch ($operation) { + case 'up': + $app['eccube.service.cart']->addProduct($ProductClass, 1); + break; + case 'down': + $app['eccube.service.cart']->addProduct($ProductClass, -1); + break; + case 'remove': + $app['eccube.service.cart']->removeProduct($ProductClass); + break; + } - // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ - if ($Result->hasError()) { - foreach ($Result->getErrors() as $error) { - $app->addRequestError($error); - } - $app['eccube.service.cart']->clear(); - $app['eccube.service.cart']->save(); + $Result = $app['eccube.purchase.flow.cart']->execute($Cart); - return $app->redirect($app->url('cart')); + // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ + if ($Result->hasError()) { + foreach ($Result->getErrors() as $error) { + $app->addRequestError($error); } - + $app['eccube.service.cart']->clear(); $app['eccube.service.cart']->save(); - foreach ($Result->getWarning() as $warning) { - $app->addRequestError($warning); - } + return $app->redirect($app->url('cart')); + } + + $app['eccube.service.cart']->save(); + + foreach ($Result->getWarning() as $warning) { + $app->addRequestError($warning); } log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]); diff --git a/src/Eccube/Service/CartService.php b/src/Eccube/Service/CartService.php index 8bac519f07f..4ebc50f5dbb 100644 --- a/src/Eccube/Service/CartService.php +++ b/src/Eccube/Service/CartService.php @@ -25,118 +25,103 @@ namespace Eccube\Service; use Doctrine\ORM\EntityManager; -use Eccube\Common\Constant; +use Eccube\Entity\Cart; use Eccube\Entity\CartItem; -use Eccube\Entity\Master\Disp; -use Eccube\Entity\Master\OrderItemType; +use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ProductClass; -use Eccube\Exception\CartException; use Symfony\Component\HttpFoundation\Session\Session; class CartService { - /** @var \Eccube\Application */ - public $app; - /** * @var Session */ - private $session; + protected $session; /** * @var EntityManager */ - private $entityManager; - - /** - * @var \Eccube\Entity\Cart - */ - private $cart; - - /** - * @var \Eccube\Entity\BaseInfo - */ - private $BaseInfo; - - /** - * @var array - */ - private $errors = array(); - - private $ProductType = null; - - /** - * @var array - */ - private $messages = array(); + protected $em; /** - * @var array + * @var ItemHolderInterface */ - private $error; + protected $cart; - public function __construct(\Eccube\Application $app) + public function __construct(Session $session, EntityManager $em) { - $this->app = $app; - $this->session = $app['session']; - $this->entityManager = $app['orm.em']; - - if ($this->session->has('cart')) { - $this->cart = $this->session->get('cart'); - } else { - $this->cart = new \Eccube\Entity\Cart(); - } - - $this->loadProductClassFromCart(); - - $this->BaseInfo = $app['eccube.repository.base_info']->get(); + $this->session = $session; + $this->cart = $session->get('cart', new Cart()); + $this->em = $em; } - /** - * カートに保存されている商品の ProductClass エンティティを読み込み、カートへ設定します。 - */ - protected function loadProductClassFromCart() + public function getCart() { - /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ - // $softDeleteFilter = $this->entityManager->getFilters()->getFilter('soft_delete'); - // $excludes = $softDeleteFilter->getExcludes(); - // $softDeleteFilter->setExcludes(array( - // 'Eccube\Entity\ProductClass', - // )); + // LoadProcessorに切り離してもよい? + $this->loadItems(); - // foreach ($this->cart->getCartItems() as $CartItem) { - // $this->loadProductClassFromCartItem($CartItem); - // } + return $this->cart; + } - // $softDeleteFilter->setExcludes($excludes); + protected function loadItems() + { + /** @var CartItem $item */ + foreach ($this->cart->getItems() as $item) { + $id = $item->getClassId(); + $class = $item->getClassName(); + $entity = $this->em->getRepository($class)->find($id); + $item->setObject($entity); + } } - /** - * CartItem に対応する ProductClass を設定します。 - * - * @param CartItem $CartItem - */ - protected function loadProductClassFromCartItem(CartItem $CartItem) + public function addProduct($ProductClass, $quantity) { - $ProductClass = $this - ->entityManager - ->getRepository($CartItem->getClassName()) - ->find($CartItem->getClassId()); + if (!$ProductClass instanceof ProductClass) { + $ProductClassId = $ProductClass; + $ProductClass = $this->em + ->getRepository(ProductClass::class) + ->find($ProductClassId); + if (is_null($ProductClass)) { + return false; + } + } - $CartItem->setObject($ProductClass); + /** @var Cart $cart */ + $cart = $this->cart; + $exists = $cart->getCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); - if (is_null($this->ProductType) && $ProductClass->getDelFlg() == Constant::DISABLED) { - $this->setCanAddProductType($ProductClass->getProductType()); + if ($exists) { + $exists->setQuantity($exists->getQuantity() + $quantity); + } else { + $item = new CartItem(); + $item->setQuantity($quantity); + $item->setPrice($ProductClass->getPrice01IncTax()); + $item->setClassId($ProductClass->getId()); + $item->setClassName(ProductClass::class); + $item->setObject($ProductClass); + $cart->addItem($item); } + + return true; } - public function setCanAddProductType(\Eccube\Entity\Master\ProductType $ProductType) + public function removeProduct($ProductClass) { - if (is_null($this->ProductType)) { - $this->ProductType = $ProductType; + if (!$ProductClass instanceof ProductClass) { + $ProductClassId = $ProductClass; + $ProductClass = $this->em + ->getRepository(ProductClass::class) + ->find($ProductClassId); + if (is_null($ProductClass)) { + return false; + } } - return $this; + /** @var Cart $cart */ + $cart = $this->cart; + $cart->removeCartItemByIdentifier(ProductClass::class, $ProductClass->getId()); + + return true; } public function save() @@ -197,521 +182,4 @@ public function clear() return $this; } - - public function getCanAddProductType() - { - return $this->ProductType; - } - - /** - * - * @param string $productClassId - * @param integer $quantity - * @return \Eccube\Service\CartService - */ - public function addProduct($productClassId, $quantity = 1) - { - $quantity += $this->getProductQuantity($productClassId); - $this->setProductQuantity($productClassId, $quantity); - - return $this; - } - - /** - * @param string $productClassId - * @return integer - */ - public function getProductQuantity($productClassId) - { - $CartItem = $this->cart->getCartItemByIdentifier('Eccube\Entity\ProductClass', (string)$productClassId); - if ($CartItem) { - return $CartItem->getQuantity(); - } else { - return 0; - } - } - - /** - * @param \Eccube\Entity\ProductClass|integer $ProductClass - * @param integer $quantity - * @return \Eccube\Service\CartService - * @throws CartException - */ - public function setProductQuantity($ProductClass, $quantity) - { - if (!$ProductClass instanceof ProductClass) { - $ProductClass = $this->entityManager - ->getRepository('Eccube\Entity\ProductClass') - ->find($ProductClass); - if (!$ProductClass) { - throw new CartException('cart.product.delete'); - } - } - - if (!$this->isProductDisplay($ProductClass)) { - throw new CartException('cart.product.not.status'); - } - - $productName = $this->getProductName($ProductClass); - - // 商品種別に紐づく配送業者を取得 - $deliveries = $this->app['eccube.repository.delivery']->getDeliveries($ProductClass->getProductType()); - - if (count($deliveries) == 0) { - // 商品種別が存在しなければエラー - $this->removeProduct($ProductClass->getId()); - $this->addError('cart.product.not.producttype', $productName); - throw new CartException('cart.product.not.producttype'); - } - - $this->setCanAddProductType($ProductClass->getProductType()); - - if ($this->BaseInfo->getOptionMultipleShipping() != Constant::ENABLED) { - if (!$this->canAddProduct($ProductClass->getId())) { - // 複数配送対応でなければ商品種別が異なればエラー - throw new CartException('cart.product.type.kind'); - } - } else { - // 複数配送の場合、同一支払方法がなければエラー - if (!$this->canAddProductPayment($ProductClass->getProductType())) { - throw new CartException('cart.product.payment.kind'); - } - } - - $tmp_subtotal = 0; - $tmp_quantity = 0; - foreach ($this->getCartObj()->getCartItems() as $cartitem) { - $pc = $cartitem->getObject(); - if ($pc->getId() != $ProductClass->getId()) { - // 追加された商品以外のtotal priceをセット - $tmp_subtotal += $cartitem->getTotalPrice(); - } - } - for ($i = 0; $i < $quantity; $i++) { - $tmp_subtotal += $ProductClass->getPrice02IncTax(); - if ($tmp_subtotal > $this->app['config']['max_total_fee']) { - $this->setError('cart.over.price_limit'); - break; - } - $tmp_quantity++; - } - if ($tmp_quantity == 0) { - // 数量が0の場合、エラー - throw new CartException('cart.over.price_limit'); - } - - // 制限数チェック(在庫不足の場合は、処理の中でカート内商品を削除している) - $quantity = $this->setProductLimit($ProductClass, $productName, $tmp_quantity); - - // 新しい数量でカート内商品を登録する - if (0 < $quantity) { - $CartItem = new CartItem(); - $CartItem - ->setClassName('Eccube\Entity\ProductClass') - ->setClassId((string)$ProductClass->getId()) - ->setPrice($ProductClass->getPrice02IncTax()) - ->setQuantity($quantity); - - $this->cart->setCartItem($CartItem); - } - - return $this; - } - - /** - * @param string $productClassId - * @return boolean - */ - public function canAddProduct($productClassId) - { - $ProductClass = $this - ->entityManager - ->getRepository('\Eccube\Entity\ProductClass') - ->find($productClassId); - - if (!$ProductClass) { - return false; - } - - $ProductType = $ProductClass->getProductType(); - - return $this->ProductType == $ProductType; - } - - /** - * @param \Eccube\Entity\Master\ProductType $ProductType - * @return bool - */ - public function canAddProductPayment(\Eccube\Entity\Master\ProductType $ProductType) - { - $deliveries = $this - ->entityManager - ->getRepository('\Eccube\Entity\Delivery') - ->findBy(array('ProductType' => $ProductType)); - - // 支払方法を取得 - $payments = $this->entityManager->getRepository('Eccube\Entity\Payment')->findAllowedPayments($deliveries); - - if ($this->getCart()->getTotalPrice() < 1) { - // カートになければ支払方法を全て設定 - $this->getCart()->setPayments($payments); - - return true; - } - - // カートに存在している支払方法と追加された商品の支払方法チェック - $arr = array(); - foreach ($payments as $payment) { - foreach ($this->getCart()->getPayments() as $p) { - if ($payment['id'] == $p['id']) { - $arr[] = $payment; - break; - } - } - } - - if (count($arr) > 0) { - $this->getCart()->setPayments($arr); - - return true; - } - - // 支払条件に一致しない - return false; - - } - - /** - * カートブロックに表示するカートを取得します。 - * ブロックに表示するカートはチェックを行わず、セットされているカートを返します。 - * - * @return \Eccube\Entity\Cart - */ - public function getCartObj() - { - - foreach ($this->cart->getCartItems() as $CartItem) { - - /** @var \Eccube\Entity\ProductClass $ProductClass */ - $ProductClass = $CartItem->getObject(); - if (!$ProductClass) { - $this->loadProductClassFromCartItem($CartItem); - - $ProductClass = $CartItem->getObject(); - } - - if ($ProductClass->getDelFlg()) { - // 商品情報が削除されていたらエラー - $this->setError('cart.product.delete'); - // カートから削除 - $this->removeProduct($ProductClass->getId()); - } - } - - return $this->cart; - - } - - /** - * カートを取得します。 - * - * @return \Eccube\Entity\Cart - */ - public function getCart() - { - foreach ($this->cart->getCartItems() as $CartItem) { - - /** @var \Eccube\Entity\ProductClass $ProductClass */ - $ProductClass = $CartItem->getObject(); - if (!$ProductClass) { - $this->loadProductClassFromCartItem($CartItem); - - $ProductClass = $CartItem->getObject(); - } - - if ($ProductClass->getDelFlg() == Constant::DISABLED) { - // 商品情報が有効 - - if (!$this->isProductDisplay($ProductClass)) { - $this->setError('cart.product.not.status'); - } else { - - $productName = $this->getProductName($ProductClass); - - // 制限数チェック(在庫不足の場合は、処理の中でカート内商品を削除している) - $quantity = $this->setProductLimit($ProductClass, $productName, $CartItem->getQuantity()); - - /// 個数が異なれば、新しい数量でカート内商品を更新する - if ((0 < $quantity) && ($CartItem->getQuantity() != $quantity)) { - // 個数が異なれば更新 - $CartItem->setQuantity($quantity); - $this->cart->setCartItem($CartItem); - } - } - - } else { - // 商品情報が削除されていたらエラー - $this->setError('cart.product.delete'); - // カートから削除 - $this->removeProduct($ProductClass->getId()); - } - } - - return $this->cart; - } - - /** - * @param string $productClassId - * @return \Eccube\Service\CartService - */ - public function removeProduct($productClassId) - { - $this->cart->removeCartItemByIdentifier('Eccube\Entity\ProductClass', (string)$productClassId); - - // 支払方法の再設定 - if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { - - // 複数配送対応 - $productTypes = array(); - foreach ($this->getCart()->getCartItems() as $item) { - /* @var $ProductClass \Eccube\Entity\ProductClass */ - $ProductClass = $item->getObject(); - $productTypes[] = $ProductClass->getProductType(); - } - - // 配送業者を取得 - $deliveries = $this->entityManager->getRepository('Eccube\Entity\Delivery')->getDeliveries($productTypes); - - // 支払方法を取得 - $payments = $this->entityManager->getRepository('Eccube\Entity\Payment')->findAllowedPayments($deliveries); - - $this->getCart()->setPayments($payments); - } - - return $this; - } - - /** - * @param string $error - * @param string $productName - * @return \Eccube\Service\CartService - */ - public function addError($error = null, $productName = null) - { - $this->errors[] = $error; - $this->session->getFlashBag()->add('eccube.front.request.error', $error); - if (!is_null($productName)) { - $this->session->getFlashBag()->add('eccube.front.request.product', $productName); - } - - return $this; - } - - /** - * @param string $productClassId - * @return \Eccube\Service\CartService - */ - public function upProductQuantity($productClassId) - { - $quantity = $this->getProductQuantity($productClassId) + 1; - $this->setProductQuantity($productClassId, $quantity); - - return $this; - } - - /** - * @param string $productClassId - * @return \Eccube\Service\CartService - */ - public function downProductQuantity($productClassId) - { - $quantity = $this->getProductQuantity($productClassId) - 1; - if ($quantity > 0) { - $this->setProductQuantity($productClassId, $quantity); - } - - return $this; - } - - /** - * @return array - */ - public function getProductTypes() - { - - $productTypes = array(); - foreach ($this->getCart()->getCartItems() as $item) { - /* @var $ProductClass \Eccube\Entity\ProductClass */ - $ProductClass = $item->getObject(); - $productTypes[] = $ProductClass->getProductType(); - } - - return array_unique($productTypes); - - } - - /** - * @return string[] - */ - public function getErrors() - { - return $this->errors; - } - - /** - * @return string[] - */ - public function getMessages() - { - return $this->messages; - } - - /** - * @param string $message - * @return \Eccube\Service\CartService - */ - public function setMessage($message) - { - $this->messages[] = $message; - - return $this; - } - - /** - * @return string - */ - public function getError() - { - return $this->error; - } - - /** - * @param string $error - * @return \Eccube\Service\CartService - */ - public function setError($error = null) - { - $this->error = $error; - $this->session->getFlashBag()->set('eccube.front.request.error', $error); - - return $this; - } - - /** - * 商品名を取得 - * - * @param ProductClass $ProductClass - * @return string - */ - private function getProductName(ProductClass $ProductClass) - { - - $productName = $ProductClass->getProduct()->getName(); - - if ($ProductClass->hasClassCategory1()) { - $productName .= " - ".$ProductClass->getClassCategory1()->getName(); - } - - if ($ProductClass->hasClassCategory2()) { - $productName .= " - ".$ProductClass->getClassCategory2()->getName(); - } - - return $productName; - } - - - /** - * 非公開商品の場合、カートから削除 - * - * @param ProductClass $ProductClass - * @return bool - */ - private function isProductDisplay(ProductClass $ProductClass) - { - - if ($ProductClass->getProduct()->getStatus()->getId() !== Disp::DISPLAY_SHOW) { - // 非公開の商品はカートから削除 - $this->removeProduct($ProductClass->getId()); - - return false; - } - - return true; - } - - - /** - * 在庫数と販売制限数のチェック - * 在庫数または販売制限数以上の個数が設定されていれば、それぞれの個数にセットし、 - * 在庫数と販売制限数ともに個数が超えていれば、少ない方を適用させてメッセージを表示する - * - * @param ProductClass $ProductClass - * @param $productName - * @param $quantity - * @return int チェック後に更新した個数 - */ - private function setProductLimit(ProductClass $ProductClass, $productName, $quantity) - { - return; - - /** - * 実際の在庫は ProductClass::ProductStock だが、購入時にロックがかかるため、 - * ここでは ProductClass::stock で在庫のチェックをする - */ - - // 在庫数(在庫無制限の場合、null) - $stock = $ProductClass->getStock(); - // 在庫無制限(在庫無制限の場合、1) - $stockUnlimited = $ProductClass->getStockUnlimited(); - - // 販売制限数(設定されていなければnull) - $saleLimit = $ProductClass->getSaleLimit(); - - if ($stockUnlimited) { - // 在庫無制限 - - if ($saleLimit && $saleLimit < $quantity) { - // 販売制限数を超えていれば販売制限数をセット - $this->addError('cart.over.sale_limit', $productName); - - return $saleLimit; - } - } else { - // 在庫制限あり - - if ($stock < 1) { - // 在庫がなければカートから削除 - $this->addError('cart.zero.stock', $productName); - $this->removeProduct($ProductClass->getId()); - - return 0; - } else { - // 在庫数チェックと販売制限数チェックどちらを適用するか設定 - $message = 'cart.over.stock'; - if ($saleLimit) { - if ($stock > $saleLimit) { - // 販売制限数チェック - $limit = $saleLimit; - $message = 'cart.over.sale_limit'; - } else { - // 在庫数チェック - $limit = $stock; - } - } else { - // 在庫数チェック - $limit = $stock; - } - - if ($limit < $quantity) { - // 在庫数、販売制限数を超えていれば購入可能数までをセット - $this->addError($message, $productName); - - return $limit; - } - } - } - - return $quantity; - } - } diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 65375e6b5bc..083d7c70361 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -63,7 +63,7 @@ public function register(Container $app) return $app['twig']; }; $app['eccube.service.cart'] = function () use ($app) { - return new \Eccube\Service\CartService($app); + return new \Eccube\Service\CartService($app['session'], $app['orm.em']); }; $app['eccube.service.order'] = function () use ($app) { return new \Eccube\Service\OrderService($app); From f5ad3a1868ab92a38eceb3bf3b30a7bc1e82e630 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Tue, 11 Jul 2017 09:16:20 +0900 Subject: [PATCH 40/75] =?UTF-8?q?PurchaseFlowResult=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/ShoppingController.php | 76 +++++++++----------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index be6bf154e3f..e07a9b34587 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -42,6 +42,7 @@ use Eccube\Form\Type\Front\ShoppingShippingType; use Eccube\Form\Type\ShippingMultipleType; use Eccube\Form\Type\Shopping\OrderType; +use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; @@ -85,7 +86,7 @@ class ShoppingController extends AbstractController * * @param Application $app * @param Request $request - * @return array + * @return mixed */ public function index(Application $app, Request $request) { @@ -101,16 +102,17 @@ public function index(Application $app, Request $request) return $response; } - // 単価集計し, フォームを生成する - $app->forwardChain($app->path("shopping/calculateOrder")) - ->forwardChain($app->path("shopping/createForm")); - - /** @var Order $Order */ $Order = $app['request_scope']->get('Order'); - if (!empty($Order->getErrors())) { - return $app->redirect($app->url('shopping_error')); + // 単価集計 + $flowResult = $this->executePurchaseFlow($app, $Order); + + // フォームを生成する + $app->forward($app->path("shopping/createForm")); + + if ($flowResult->hasWarning() || $flowResult->hasError()) { + return $app->redirect($app->url('cart')); } // 複数配送の場合、エラーメッセージを一度だけ表示 @@ -129,7 +131,7 @@ public function index(Application $app, Request $request) * * @param Application $app * @param Request $request - * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @return mixed */ public function redirectTo(Application $app, Request $request) { @@ -304,8 +306,8 @@ public function shipping(Application $app, Request $request, $id) // 合計金額の再計算 - $this->executePurchaseFlow($app, $Order); - if (!empty($Order->getErrors())) { + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { return $app->redirect($app->url('shopping_error')); } @@ -416,8 +418,8 @@ public function shippingEdit(Application $app, Request $request, $id) $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); // 合計金額の再計算 - $this->executePurchaseFlow($app, $Order); - if (!empty($Order->getErrors())) { + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { return $app->redirect($app->url('shopping_error')); } @@ -663,11 +665,8 @@ public function nonmember(Application $app, Request $request) } } - $this->executePurchaseFlow($app, $Order); - if (!empty($Order->getErrors())) { - foreach ($Order->getErrors() as $error) { - $app->addRequestError($error); - } + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { return $app->redirect($app->url('cart')); } @@ -935,8 +934,8 @@ public function shippingMultiple(Application $app, Request $request) } // 合計金額の再計算 - $this->executePurchaseFlow($app, $Order); - if (!empty($Order->getErrors())) { + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { return $app->redirect($app->url('shopping_error')); } @@ -1243,24 +1242,6 @@ public function initializeOrder(Application $app, Request $request) return new Response(); } - /** - * 受注の単価集計をする - * - * @Route("/calculateOrder", name="shopping/calculateOrder") - * @param Application $app - * @param Request $request - * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response - */ - public function calculateOrder(Application $app, Request $request) - { - $Order = $app['request_scope']->get('Order'); - - // 構築したOrderを集計する. - $this->executePurchaseFlow($app, $Order); - - return new Response(); - } - /** * フォームを作成し, イベントハンドラを設定する * @@ -1399,9 +1380,6 @@ public function completeOrder(Application $app, Request $request) { $form = $app['request_scope']->get(OrderType::class); - // requestのバインド後、再集計 - $app->forward($app->path("shopping/calculateOrder")); - if ($form->isSubmitted() && $form->isValid()) { /** @var Order $Order */ @@ -1417,8 +1395,8 @@ public function completeOrder(Application $app, Request $request) // FormTypeで更新されるため不要 //$app['eccube.service.shopping']->setFormData($Order, $data); - $this->executePurchaseFlow($app, $Order); - if (!empty($Order->getErrors())) { + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { // TODO エラーメッセージ throw new ShoppingException(); } @@ -1537,11 +1515,21 @@ public function afterComplete(Application $app, Request $request) return $app->redirect($app->url('shopping_complete')); } + /** + * @param Application $app + * @param ItemHolderInterface $itemHolder + * @return PurchaseFlowResult + */ private function executePurchaseFlow(Application $app, ItemHolderInterface $itemHolder) { - $app['eccube.purchase.flow.shopping']->execute($itemHolder); + /** @var PurchaseFlowResult $flowResult */ + $flowResult = $app['eccube.purchase.flow.shopping']->execute($itemHolder); + foreach ($flowResult->getWarning() as $warning) { + $app->addRequestError($warning); + } foreach ($itemHolder->getErrors() as $error) { $app->addRequestError($error); } + return $flowResult; } } From 9d0700a12b78957aaf2bd7992ca5d42dc5eb769e Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 11 Jul 2017 13:04:37 +0900 Subject: [PATCH 41/75] =?UTF-8?q?=E5=95=86=E5=93=81=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Block/CartController.php | 2 +- src/Eccube/Controller/ProductController.php | 25 +++++++++++++++---- .../Resource/template/default/Block/cart.twig | 2 +- .../template/default/Block/nav_sp.twig | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Eccube/Controller/Block/CartController.php b/src/Eccube/Controller/Block/CartController.php index 926a5456745..ec89764bf0b 100644 --- a/src/Eccube/Controller/Block/CartController.php +++ b/src/Eccube/Controller/Block/CartController.php @@ -31,7 +31,7 @@ class CartController public function index(Application $app) { /** @var $Cart \Eccube\Entity\Cart */ - $Cart = $app['eccube.service.cart']->getCartObj(); + $Cart = $app['eccube.service.cart']->getCart(); return $app->render('Block/cart.twig', array( 'Cart' => $Cart, )); diff --git a/src/Eccube/Controller/ProductController.php b/src/Eccube/Controller/ProductController.php index 1cc3a8c1944..24f29da9390 100644 --- a/src/Eccube/Controller/ProductController.php +++ b/src/Eccube/Controller/ProductController.php @@ -271,11 +271,26 @@ public function detail(Application $app, Request $request, $id) log_info('カート追加処理開始', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity'])); - try { - $app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity'])->save(); - } catch (CartException $e) { - log_info('カート追加エラー', array($e->getMessage())); - $app->addRequestError($e->getMessage()); + // カートを取得 + $Cart = $app['eccube.service.cart']->getCart(); + + // カートへ追加 + $app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity']); + + // 明細の正規化 + $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + + // 復旧不可のエラーが発生した場合はsaveしない. + if ($Result->hasError()) { + foreach ($Result->getErrors() as $error) { + $app->addRequestError($error); + } + } else { + foreach ($Result->getWarning() as $warning) { + $app->addRequestError($warning); + } + // エラーがなければsave + $app['eccube.service.cart']->save(); } log_info('カート追加処理完了', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity'])); diff --git a/src/Eccube/Resource/template/default/Block/cart.twig b/src/Eccube/Resource/template/default/Block/cart.twig index a1cbfbfc9c2..46a8572b0ae 100644 --- a/src/Eccube/Resource/template/default/Block/cart.twig +++ b/src/Eccube/Resource/template/default/Block/cart.twig @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #} -{% set Cart = app['eccube.service.cart'].getCartObj %} +{% set Cart = app['eccube.service.cart'].getCart %}
diff --git a/src/Eccube/Resource/template/default/Block/nav_sp.twig b/src/Eccube/Resource/template/default/Block/nav_sp.twig index 2e27ed70abb..363300fc613 100644 --- a/src/Eccube/Resource/template/default/Block/nav_sp.twig +++ b/src/Eccube/Resource/template/default/Block/nav_sp.twig @@ -1,4 +1,4 @@ -{% set Cart = app['eccube.service.cart'].getCartObj %} +{% set Cart = app['eccube.service.cart'].getCart %}
From c476907d00601b70a6a4761425b9abcb26e277dc Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 11 Jul 2017 15:34:43 +0900 Subject: [PATCH 42/75] =?UTF-8?q?EditController=20=E3=81=B8=E7=B5=84?= =?UTF-8?q?=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/Order/EditController.php | 16 +++- src/Eccube/Entity/Cart.php | 3 +- src/Eccube/Entity/Order.php | 9 +- .../Service/PurchaseFlow/ItemCollection.php | 96 +++++++++++++++++++ .../Processor/StockReduceProcessor.php | 67 +++++++++++++ .../Service/PurchaseFlow/PurchaseFlow.php | 50 +++++----- .../ServiceProvider/EccubeServiceProvider.php | 10 +- 7 files changed, 215 insertions(+), 36 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/ItemCollection.php create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index bd355efb15b..06ba2bb58cf 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -134,17 +134,23 @@ public function index(Application $app, Request $request, $id = null) // TODO 編集前のOrder情報が必要かもしれない // TODO 手数料, 値引きの集計は未実装 // $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); - $app['eccube.purchase.flow.order']->execute($TargetOrder); + if ('GET' === $request->getMethod()) { + $app['eccube.purchase.flow.order.get']->execute($TargetOrder); + } + // 登録ボタン押下 switch ($request->get('mode')) { case 'register': log_info('受注登録開始', array($TargetOrder->getId())); // TODO 在庫の有無や販売制限数のチェックなども行う必要があるため、完了処理もcaluclatorのように抽象化できないか検討する. - if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) { - log_info('受注登録入力チェックエラー', array($TargetOrder->getId())); - $form['charge']->addError(new FormError('合計金額の上限を超えております。')); - } elseif ($form->isValid()) { + if ($form->isValid()) { + $app['eccube.purchase.flow.order.post']->execute($TargetOrder); + // TODO hasError でチェックしたい + foreach ($TargetOrder->getErrors() as $error) { + $app->addError($error, 'admin'); + break 2; + } $BaseInfo = $app['eccube.repository.base_info']->get(); diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 3317b9614ba..68ded2798c2 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -24,6 +24,7 @@ namespace Eccube\Entity; +use Eccube\Service\PurchaseFlow\ItemCollection; use Eccube\Service\ItemValidateException; class Cart extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface @@ -196,7 +197,7 @@ public function getCartItems() */ public function getItems() { - return $this->getCartItems(); + return new ItemCollection($this->getCartItems()); } /** diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 3fe75c253e0..3c04c3c3f4c 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -27,6 +27,7 @@ use Eccube\Common\Constant; use Eccube\Service\Calculator\ShipmentItemCollection; use Eccube\Service\ItemValidateException; +use Eccube\Service\PurchaseFlow\ItemCollection; use Eccube\Util\EntityUtil; use Eccube\Entity\Master\OrderItemType; use Doctrine\ORM\Mapping as ORM; @@ -627,7 +628,7 @@ public function __construct(\Eccube\Entity\Master\OrderStatus $orderStatus = nul ->setDelFlg(Constant::DISABLED); $this->OrderDetails = new \Doctrine\Common\Collections\ArrayCollection(); - $this->ShipmentItems = new \Doctrine\Common\Collections\ArrayCollection(); + $this->ShipmentItems = new \Eccube\Service\Calculator\ShipmentItemCollection(); $this->MailHistories = new \Doctrine\Common\Collections\ArrayCollection(); } @@ -1565,10 +1566,12 @@ public function getShipmentItems() /** * Alias of getShipmentItems() + * + * @return ItemCollection */ public function getItems() { - return $this->getShipmentItems(); + return new ItemCollection($this->getShipmentItems()); } /** @@ -1911,4 +1914,6 @@ public function getQuantity() return $quantity; } + + protected $errors = []; } diff --git a/src/Eccube/Service/PurchaseFlow/ItemCollection.php b/src/Eccube/Service/PurchaseFlow/ItemCollection.php new file mode 100644 index 00000000000..fcd39546c29 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/ItemCollection.php @@ -0,0 +1,96 @@ +type = is_null($type) ? Order::class : $type; + + if ($Items instanceof Collection) { + $Items = $Items->toArray(); + } + parent::__construct($Items); + } + + public function reduce(\Closure $func, $initial = null) + { + return array_reduce($this->toArray(), $func, $initial); + } + + // 明細種別ごとに返すメソッド作る + public function getProductClasses() + { + return $this->filter( + function (ItemInterface $ShipmentItem) { + return $ShipmentItem->isProduct(); + }); + } + + public function getDeliveryFees() + { + return $this->filter( + function (ItemInterface $ShipmentItem) { + return $ShipmentItem->isDeliveryFee(); + }); + } + + public function getCharges() + { + return $this->filter( + function (ItemInterface $ShipmentItem) { + return $ShipmentItem->isCharge(); + }); + } + + public function getDiscounts() + { + return $this->filter( + function (ItemInterface $ShipmentItem) { + return $ShipmentItem->isDiscount(); + }); + } + + /** + * 同名の明細が存在するかどうか. + * + * TODO 暫定対応. 本来は明細種別でチェックする. + */ + public function hasProductByName($productName) + { + $ShipmentItems = $this->filter( + function (ItemInterface $ShipmentItem) use ($productName) { + /* @var ShipmentItem $ShipmentItem */ + return $ShipmentItem->getProductName() == $productName; + }); + return !$ShipmentItems->isEmpty(); + } + + /** + * 指定した受注明細区分の明細が存在するかどうか + * @param OrderItemType $OrderItemType 受注区分 + * @return boolean + */ + public function hasItemByOrderItemType($OrderItemType) + { + $filteredItems = $this->filter(function (ItemInterface $ShipmentItem) use ($OrderItemType) { + /* @var ShipmentItem $ShipmentItem */ + return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $OrderItemType->getId(); + }); + return !$filteredItems->isEmpty(); + } + + public function getType() + { + return $this->type; + } +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php new file mode 100644 index 00000000000..14671d20852 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php @@ -0,0 +1,67 @@ +app = $app; + } + + /** + * @param ItemHolderInterface $itemHolder + * @return ProcessResult + */ + public function process(ItemInterface $item) + { + if (!$item instanceof \Eccube\Entity\ShipmentItem) { + // ShipmentItem 以外の場合は何もしない + return ProcessResult::success(); + } + + // 在庫処理を実装 + // warning も作りたい + if (!$item->isProduct()) { + // FIXME 配送明細を考慮する必要がある + return ProcessResult::success(); + } + // 在庫が無制限かチェックし、制限ありなら在庫数をチェック + if ($item->getProductClass()->getStockUnlimited() == Constant::DISABLED) { + // 在庫チェックあり + // 在庫に対してロック(select ... for update)を実行 + $productStock = $this->app['orm.em']->getRepository('Eccube\Entity\ProductStock')->find( + $item->getProductClass()->getProductStock()->getId(), LockMode::PESSIMISTIC_WRITE + ); + // 購入数量と在庫数をチェックして在庫がなければエラー + if ($productStock->getStock() < 1) { + return ProcessResult::fail('在庫エラー'); + } elseif ($item->getQuantity() > $productStock->getStock()) { + return ProcessResult::fail('在庫エラー'); + } + } + return ProcessResult::success(); + } +} diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index d0f085331cb..85e21056a6c 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -2,7 +2,6 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ItemInterface; @@ -19,8 +18,8 @@ class PurchaseFlow */ protected $itemProcessors = []; - public function execute(ItemHolderInterface $itemHolder) { - + public function execute(ItemHolderInterface $itemHolder) + { $this->calculateDeliveryFeeTotal($itemHolder); $this->calculateCharge($itemHolder); $this->calculateDiscount($itemHolder); @@ -60,7 +59,7 @@ public function addItemProcessor(ItemProcessor $prosessor) */ protected function calculateTotal(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { + $total = $itemHolder->getItems()->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); @@ -74,10 +73,9 @@ protected function calculateTotal(ItemHolderInterface $itemHolder) protected function calculateSubTotal(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->filter( - function (ItemInterface $item) { - return $item->isProduct(); - })->toArray(), function ($sum, ItemInterface $item) { + $total = $itemHolder->getItems() + ->getProductClasses() + ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); @@ -92,10 +90,9 @@ function (ItemInterface $item) { */ protected function calculateDeliveryFeeTotal(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->filter( - function (ItemInterface $item) { - return $item->isDeliveryFee(); - })->toArray(), function ($sum, ItemInterface $item) { + $total = $itemHolder->getItems() + ->getDeliveryFees() + ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); @@ -107,10 +104,9 @@ function (ItemInterface $item) { */ protected function calculateDiscount(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->filter( - function (ItemInterface $item) { - return $item->isDiscount(); - })->toArray(), function ($sum, ItemInterface $item) { + $total = $itemHolder->getItems() + ->getDiscounts() + ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); return $sum; }, 0); @@ -123,13 +119,12 @@ function (ItemInterface $item) { */ protected function calculateCharge(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->filter( - function (ItemInterface $item) { - return $item->isCharge(); - })->toArray(), function ($sum, ItemInterface $item) { - $sum += $item->getPriceIncTax() * $item->getQuantity(); - return $sum; - }, 0); + $total = $itemHolder->getItems() + ->getCharges() + ->reduce(function ($sum, ItemInterface $item) { + $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; + }, 0); $itemHolder->setCharge($total); } @@ -138,10 +133,11 @@ function (ItemInterface $item) { */ protected function calculateTax(ItemHolderInterface $itemHolder) { - $total = array_reduce($itemHolder->getItems()->toArray(), function ($sum, ItemInterface $item) { - $sum += ($item->getPriceIncTax() - $item->getPrice()) * $item->getQuantity(); - return $sum; - }, 0); + $total = $itemHolder->getItems() + ->reduce(function ($sum, ItemInterface $item) { + $sum += ($item->getPriceIncTax() - $item->getPrice()) * $item->getQuantity(); + return $sum; + }, 0); $itemHolder->setTax($total); } } diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 083d7c70361..b68a37a13c4 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -35,6 +35,7 @@ use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; +use Eccube\Service\PurchaseFlow\Processor\StockReduceProcessor; use Eccube\Service\PurchaseFlow\Processor\StockValidator; use Eccube\Service\PurchaseFlow\PurchaseFlow; use Pimple\Container; @@ -559,10 +560,17 @@ public function register(Container $app) return $flow; }; - $app['eccube.purchase.flow.order'] = function () use ($app) { + $app['eccube.purchase.flow.order.get'] = function () use ($app) { + $flow = new PurchaseFlow(); + $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + return $flow; + }; + + $app['eccube.purchase.flow.order.post'] = function () use ($app) { $flow = new PurchaseFlow(); $flow->addItemProcessor(new StockValidator()); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + $flow->addItemProcessor(new StockReduceProcessor($app)); // 参考実装 return $flow; }; } From 549b8f91eae473543a3191467b19735f208d24f3 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 12 Jul 2017 09:26:06 +0900 Subject: [PATCH 43/75] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Order.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 3c04c3c3f4c..970fc55e345 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1914,6 +1914,4 @@ public function getQuantity() return $quantity; } - - protected $errors = []; } From d90a469ee723f06e63a3070bd9e16da3ac8bc39f Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 12 Jul 2017 09:31:30 +0900 Subject: [PATCH 44/75] =?UTF-8?q?PurchaseFlow=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 14 +++++++++----- src/Eccube/Controller/ShoppingController.php | 6 +++--- src/Eccube/Entity/Order.php | 2 +- .../PurchaseFlow/ItemValidateException.php | 15 +++++++++++++++ .../Service/PurchaseFlow/ProcessResult.php | 16 +++++++++------- .../Processor/DeletedProductValidator.php | 2 +- .../Processor/DeliverySettingValidator.php | 2 +- .../Processor/DisplayStatusValidator.php | 2 +- .../Processor/PaymentTotalLimitValidator.php | 2 +- .../Processor/SaleLimitValidator.php | 2 +- .../PurchaseFlow/Processor/StockValidator.php | 5 ++++- .../Service/PurchaseFlow/PurchaseFlowResult.php | 6 ++++++ .../PurchaseFlow/ValidatableItemProcessor.php | 2 +- 13 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index d8b628e630c..27a35ca1c77 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -28,6 +28,7 @@ use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; +use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; @@ -59,12 +60,13 @@ public function index(Application $app, Request $request) { // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); + /** @var PurchaseFlowResult $Result */ $Result = $app['eccube.purchase.flow.cart']->execute($Cart); // 復旧不可のエラーが発生した場合はカートをクリアして再描画 if ($Result->hasError()) { foreach ($Result->getErrors() as $error) { - $app->addRequestError($error); + $app->addRequestError($error->getMessage()); } $app['eccube.service.cart']->clear(); $app['eccube.service.cart']->save(); @@ -75,7 +77,7 @@ public function index(Application $app, Request $request) $app['eccube.service.cart']->save(); foreach ($Result->getWarning() as $warning) { - $app->addRequestError($warning); + $app->addRequestError($warning->getMessage()); } // TODO purchaseFlow/itemHolderから取得できるように @@ -137,12 +139,13 @@ public function handleCartItem(Application $app, Request $request, $operation, $ // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); + /** @var PurchaseFlowResult $Result */ $Result = $app['eccube.purchase.flow.cart']->execute($Cart); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ if ($Result->hasError()) { foreach ($Result->getErrors() as $error) { - $app->addRequestError($error); + $app->addRequestError($error->getMessage()); } $app['eccube.service.cart']->clear(); $app['eccube.service.cart']->save(); @@ -163,12 +166,13 @@ public function handleCartItem(Application $app, Request $request, $operation, $ break; } + /** @var PurchaseFlowResult $Result */ $Result = $app['eccube.purchase.flow.cart']->execute($Cart); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ if ($Result->hasError()) { foreach ($Result->getErrors() as $error) { - $app->addRequestError($error); + $app->addRequestError($error->getMessage()); } $app['eccube.service.cart']->clear(); $app['eccube.service.cart']->save(); @@ -179,7 +183,7 @@ public function handleCartItem(Application $app, Request $request, $operation, $ $app['eccube.service.cart']->save(); foreach ($Result->getWarning() as $warning) { - $app->addRequestError($warning); + $app->addRequestError($warning->getMessage()); } log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]); diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index e07a9b34587..b8a9408e17e 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -1525,10 +1525,10 @@ private function executePurchaseFlow(Application $app, ItemHolderInterface $item /** @var PurchaseFlowResult $flowResult */ $flowResult = $app['eccube.purchase.flow.shopping']->execute($itemHolder); foreach ($flowResult->getWarning() as $warning) { - $app->addRequestError($warning); + $app->addRequestError($warning->getMessage()); } - foreach ($itemHolder->getErrors() as $error) { - $app->addRequestError($error); + foreach ($flowResult->getErrors() as $error) { + $app->addRequestError($error->getMessage()); } return $flowResult; } diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 970fc55e345..088d6da809c 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -628,7 +628,7 @@ public function __construct(\Eccube\Entity\Master\OrderStatus $orderStatus = nul ->setDelFlg(Constant::DISABLED); $this->OrderDetails = new \Doctrine\Common\Collections\ArrayCollection(); - $this->ShipmentItems = new \Eccube\Service\Calculator\ShipmentItemCollection(); + $this->ShipmentItems = new \Eccube\Service\Calculator\ShipmentItemCollection([]); $this->MailHistories = new \Doctrine\Common\Collections\ArrayCollection(); } diff --git a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php index 3da49ee5ce5..d9ef9622297 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php +++ b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php @@ -27,4 +27,19 @@ class ItemValidateException extends \Exception { + private $messageArgs = []; + + function __construct($message = null, $messageArgs = []) + { + parent::__construct($message); + $this->messageArgs = $messageArgs; + } + + /** + * @return array + */ + public function getMessageArgs(): array + { + return $this->messageArgs; + } } \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/ProcessResult.php b/src/Eccube/Service/PurchaseFlow/ProcessResult.php index bcc645bc04f..1ca4a67307e 100644 --- a/src/Eccube/Service/PurchaseFlow/ProcessResult.php +++ b/src/Eccube/Service/PurchaseFlow/ProcessResult.php @@ -3,6 +3,8 @@ namespace Eccube\Service\PurchaseFlow; +use Eccube\Application; + class ProcessResult { @@ -13,25 +15,25 @@ class ProcessResult protected $type; protected $message; - private function __construct($type, $message = null) + private function __construct($type, $message = null, $messageArgs) { $this->type = $type; - $this->message = $message; + $this->message = Application::getInstance()->trans($message, $messageArgs); } - public static function warn($message) + public static function warn($message, $messageArgs = []) { - return new self(self::WARNING, $message); + return new self(self::WARNING, $message, $messageArgs); } - public static function error($message) + public static function error($message, $messageArgs = []) { - return new self(self::ERROR, $message); + return new self(self::ERROR, $message, $messageArgs); } public static function success() { - return new self(self::SUCCESS); + return new self(self::SUCCESS, null, []); } public function isError() diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php index c63f1a0fcdd..6a5ec89284c 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php @@ -14,7 +14,7 @@ protected function validate(ItemInterface $item) $ProductClass = $item->getProductClass(); $Product = $ProductClass->getProduct(); if ($Product->getDelFlg()) { - throw new ItemValidateException(); + throw new ItemValidateException('cart.product.delete'); } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php index d65c604be0f..0e69062e520 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php @@ -32,7 +32,7 @@ protected function validate(ItemInterface $item) $Deliveries = $this->deliveryRepository->findBy(['ProductType' => $ProductType]); if (empty($Deliveries)) { - throw new ItemValidateException('配送準備ができていないエラー'); + throw new ItemValidateException('cart.product.not.producttype', ['%product%' => $item->getProductClass()->getProduct()->getName()]); } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php index d12ee5426ae..84b502b1850 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php @@ -13,7 +13,7 @@ protected function validate(ItemInterface $item) { $ProductClass = $item->getProductClass(); if (!$ProductClass->isEnable()) { - throw new ItemValidateException(); + throw new ItemValidateException('cart.product.not.status'); } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php index 65ef69dba0d..77bf30f4935 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -51,7 +51,7 @@ protected function validate(ItemHolderInterface $item) { $totalPrice = $item->getTotal(); if ($totalPrice > $this->maxTotalFee) { - throw new ItemValidateException(); + throw new ItemValidateException('cart.over.price_limit'); } } } \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 84938bceaff..87f9fbb02f7 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -19,7 +19,7 @@ protected function validate(ItemInterface $item) $limit = $item->getProductClass()->getSaleLimit(); $quantity = $item->getQuantity(); if ($limit < $quantity) { - throw new ItemValidateException('販売制限数!'); + throw new ItemValidateException('cart.over.sale_limit', ['%product%' => $item->getProductClass()->getProduct()->getName()]); } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 639dbdf2c85..0ba2cf6bdaf 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -18,8 +18,11 @@ protected function validate(ItemInterface $item) } $stock = $item->getProductClass()->getStock(); $quantity = $item->getQuantity(); + if ($stock == 0) { + throw new ItemValidateException('cart.zero.stock', ['%product%' => $item->getProductClass()->getProduct()->getName()]); + } if ($stock < $quantity) { - throw new ItemValidateException(); + throw new ItemValidateException('cart.over.stock', ['%product%' => $item->getProductClass()->getProduct()->getName()]); } } diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php index d916472f394..8b31fd20fd8 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php @@ -49,6 +49,9 @@ public function addProcessResult(ProcessResult $processResult) $this->processResults[] = $processResult; } + /** + * @return array|ProcessResult[] + */ public function getErrors() { return array_filter($this->processResults, function(ProcessResult $processResult) { @@ -56,6 +59,9 @@ public function getErrors() }); } + /** + * @return array|ProcessResult[] + */ public function getWarning() { return array_filter($this->processResults, function(ProcessResult $processResult) { diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index d7f4c0ebfbb..ea5f216baf6 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -44,7 +44,7 @@ public function process(ItemInterface $item) $this->handle($item); } - return ProcessResult::warn($e->getMessage()); + return ProcessResult::warn($e->getMessage(), $e->getMessageArgs()); } } From 473fb6f63cb1e9050f00abd8f8a9fa6cf047e871 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Wed, 12 Jul 2017 18:31:27 +0900 Subject: [PATCH 45/75] =?UTF-8?q?=E3=82=BD=E3=83=BC=E3=83=88=E3=82=92?= =?UTF-8?q?=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ItemCollection のテストケースを追加 --- src/Eccube/Entity/Cart.php | 2 +- src/Eccube/Entity/Order.php | 4 +- .../Service/PurchaseFlow/ItemCollection.php | 32 +++++ .../PurchaseFlow/ItemCollectionTest.php | 130 ++++++++++++++++++ 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index 68ded2798c2..fb36dd36a56 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -197,7 +197,7 @@ public function getCartItems() */ public function getItems() { - return new ItemCollection($this->getCartItems()); + return (new ItemCollection($this->getCartItems()))->sort(); } /** diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 088d6da809c..edb27e75934 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -628,7 +628,7 @@ public function __construct(\Eccube\Entity\Master\OrderStatus $orderStatus = nul ->setDelFlg(Constant::DISABLED); $this->OrderDetails = new \Doctrine\Common\Collections\ArrayCollection(); - $this->ShipmentItems = new \Eccube\Service\Calculator\ShipmentItemCollection([]); + $this->ShipmentItems = new \Doctrine\Common\Collections\ArrayCollection(); $this->MailHistories = new \Doctrine\Common\Collections\ArrayCollection(); } @@ -1571,7 +1571,7 @@ public function getShipmentItems() */ public function getItems() { - return new ItemCollection($this->getShipmentItems()); + return (new ItemCollection($this->getShipmentItems()->toArray()))->sort(); } /** diff --git a/src/Eccube/Service/PurchaseFlow/ItemCollection.php b/src/Eccube/Service/PurchaseFlow/ItemCollection.php index fcd39546c29..0fe89c39690 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemCollection.php +++ b/src/Eccube/Service/PurchaseFlow/ItemCollection.php @@ -93,4 +93,36 @@ public function getType() { return $this->type; } + + public function sort() + { + $Items = $this->toArray(); + usort($Items, function (ItemInterface $a, ItemInterface $b) { + if ($a->getOrderItemType() === $b->getOrderItemType()) { + return ($a->getId() < $b->getId()) ? -1 : 1; + } elseif ($a->isProduct()) { + return -1; + } elseif ($a->isDeliveryFee()) { + if ($b->isProduct()) { + return 1; + } + return -1; + } elseif ($a->isCharge()) { + if ($b->isDeliveryFee() || $b->isProduct()) { + return 1; + } + return -1; + } elseif ($a->isDiscount()) { + if (!$b->isTax()) { + return 1; + } + return -1; + } elseif ($a->isTax()) { + return 1; + } + + return 0; + }); + return new self($Items); + } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php new file mode 100644 index 00000000000..c7f9133dd3d --- /dev/null +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php @@ -0,0 +1,130 @@ +createProduct(); + $ProductClasses = $Product->getProductClasses()->toArray(); + $Customer = $this->createCustomer(); + $this->ItemHolder = $this->app['eccube.fixture.generator']->createOrder( + $Customer, $ProductClasses); + $this->Items = $this->ItemHolder->getItems()->toArray(); + } + + public function testInstance() + { + $actual = new ItemCollection($this->Items); + self::assertInstanceOf(ItemCollection::class, $actual); + } + + public function testInstanceWithCollection() + { + $actual = new ItemCollection($this->ItemHolder->getItems()); + self::assertInstanceOf(ItemCollection::class, $actual); + } + + public function testReduce() + { + $reducer = function ($sum, ItemInterface $item) { + return $sum =+ $item->getPrice() * $item->getQuantity(); + }; + + $this->expected = array_reduce($this->Items, $reducer, 0); + $this->actual = (new ItemCollection($this->Items))->reduce($reducer, 0); + $this->verify(); + } + + public function testGetProductClasses() + { + $Items = (new ItemCollection($this->Items))->getProductClasses(); + foreach ($Items as $Item) { + self::assertTrue($Item->isProduct()); + } + } + + public function testGetDeliveryFees() + { + $Items = (new ItemCollection($this->Items))->getDeliveryFees(); + foreach ($Items as $Item) { + self::assertTrue($Item->isDeliveryFee()); + } + } + + public function testGetCharges() + { + $Items = (new ItemCollection($this->Items))->getCharges(); + foreach ($Items as $Item) { + self::assertTrue($Item->isCharge()); + } + } + + public function testGetDiscounts() + { + $Items = (new ItemCollection($this->Items))->getCharges(); + foreach ($Items as $Item) { + self::assertTrue($Item->isCharge()); + } + } + + public function testHasItemByOrderItemType() + { + $ProductClassType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::PRODUCT); + $DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE); + $ChargeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::CHARGE); + $DiscountType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DISCOUNT); + + $Items = new ItemCollection($this->Items); + + self::assertTrue($Items->hasItemByOrderItemType($ProductClassType)); + self::assertTrue($Items->hasItemByOrderItemType($DeliveryFeeType)); + self::assertTrue($Items->hasItemByOrderItemType($ChargeType)); + self::assertTrue($Items->hasItemByOrderItemType($DiscountType)); + } + + public function testSort() + { + shuffle($this->Items); + + $this->expected = [ 1 => '商品', 2 => '送料', 3 => '手数料', 4 => '割引']; + $this->actual = []; + $Items = (new ItemCollection($this->Items))->sort(); + foreach ($Items as $Item) { + $this->actual[$Item->getOrderItemType()->getId()] = $Item->getOrderItemType()->getName(); + } + + $this->verify(); + } + + public function testSortWithProductClasses() + { + shuffle($this->Items); + + $ids = (new ItemCollection($this->Items)) + ->getProductClasses() + ->map(function (ItemInterface $Item) { + return $Item->getId(); + })->toArray(); + sort($ids); + + $this->expected = $ids; + $this->actual = []; + $Items = (new ItemCollection($this->Items))->sort()->getProductClasses(); + foreach ($Items as $Item) { + $this->actual[] = $Item->getId(); + } + + $this->verify('product_class_id 順にソートされているはず'); + } +} From e9b415ffb587d0290e2e9295429fb4a2a70370ff Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 13 Jul 2017 17:06:14 +0900 Subject: [PATCH 46/75] =?UTF-8?q?=E8=B3=BC=E5=85=A5=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E6=A9=9F=E6=A7=8B=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseFlow/PurchaseException.php | 29 +++++++++++++++++++ .../Service/PurchaseFlow/PurchaseFlow.php | 22 ++++++++++++++ .../PurchaseFlow/PurchaseProcessor.php | 16 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/Eccube/Service/PurchaseFlow/PurchaseException.php create mode 100644 src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseException.php b/src/Eccube/Service/PurchaseFlow/PurchaseException.php new file mode 100644 index 00000000000..3b1a0abb1f4 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/PurchaseException.php @@ -0,0 +1,29 @@ +calculateDeliveryFeeTotal($itemHolder); @@ -44,6 +49,23 @@ public function execute(ItemHolderInterface $itemHolder) return $flowResult; } + /** + * @param ItemHolderInterface $target + * @param ItemHolderInterface $origin + * @throws PurchaseException + */ + public function purchase(ItemHolderInterface $target, ItemHolderInterface $origin) + { + foreach ($this->purchaseProcessors as $processor) { + $processor->process($target, $origin); + } + } + + public function addPurchaseProcessort(PurchaseProcessor $processor) + { + $this->purchaseProcessors[] = $processor; + } + public function addItemHolderProcessor(ItemHolderProcessor $prosessor) { $this->itemHolderProcessors[] = $prosessor; diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php new file mode 100644 index 00000000000..27c7c89e635 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php @@ -0,0 +1,16 @@ + Date: Thu, 13 Jul 2017 17:45:30 +0900 Subject: [PATCH 47/75] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Cart.php | 16 ---------------- src/Eccube/Entity/ItemHolderInterface.php | 14 -------------- 2 files changed, 30 deletions(-) diff --git a/src/Eccube/Entity/Cart.php b/src/Eccube/Entity/Cart.php index fb36dd36a56..556f2befffe 100644 --- a/src/Eccube/Entity/Cart.php +++ b/src/Eccube/Entity/Cart.php @@ -284,22 +284,6 @@ public function setPayments($payments) return $this; } - /** - * @param $error - */ - public function addError($error) - { - $this->errors[] = $error; - } - - /** - * @return ItemValidateException[] - */ - public function getErrors() - { - return $this->errors; - } - /** * @param ItemInterface $item */ diff --git a/src/Eccube/Entity/ItemHolderInterface.php b/src/Eccube/Entity/ItemHolderInterface.php index d801bdbd6e6..afbe4510e10 100644 --- a/src/Eccube/Entity/ItemHolderInterface.php +++ b/src/Eccube/Entity/ItemHolderInterface.php @@ -2,27 +2,13 @@ namespace Eccube\Entity; - -use Eccube\Service\ItemValidateException; - interface ItemHolderInterface { - /** - * @param string $error - * @return void - */ - public function addError($error); - /** * @return ItemInterface[] */ public function getItems(); - /** - * @return ItemValidateException[] - */ - public function getErrors(); - /** * 合計金額を返します。 * @return int From 094fa44fb4b2346f41b7f1ab42b2fe73578aa6a8 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 13 Jul 2017 17:59:52 +0900 Subject: [PATCH 48/75] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9=E3=81=AE=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 42 ++++++++---------------- src/Eccube/Service/CartService.php | 5 ++- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 27a35ca1c77..6729a25f780 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -43,7 +43,7 @@ class CartController extends AbstractController */ public function addTestProduct(Application $app) { - $app['eccube.service.cart']->addProductClass(10, 2); + $app['eccube.service.cart']->addProduct(10, 2); $app['eccube.service.cart']->save(); return $app->redirect($app->url('cart')); @@ -60,12 +60,12 @@ public function index(Application $app, Request $request) { // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); - /** @var PurchaseFlowResult $Result */ - $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + /** @var PurchaseFlowResult $result */ + $result = $app['eccube.purchase.flow.cart']->execute($Cart); // 復旧不可のエラーが発生した場合はカートをクリアして再描画 - if ($Result->hasError()) { - foreach ($Result->getErrors() as $error) { + if ($result->hasError()) { + foreach ($result->getErrors() as $error) { $app->addRequestError($error->getMessage()); } $app['eccube.service.cart']->clear(); @@ -76,11 +76,11 @@ public function index(Application $app, Request $request) $app['eccube.service.cart']->save(); - foreach ($Result->getWarning() as $warning) { + foreach ($result->getWarning() as $warning) { $app->addRequestError($warning->getMessage()); } - // TODO purchaseFlow/itemHolderから取得できるように + // TODO itemHolderから取得できるように $least = 0; $quantity = 0; $isDeliveryFree = false; @@ -137,22 +137,6 @@ public function handleCartItem(Application $app, Request $request, $operation, $ return $app->redirect($app->url('cart')); } - // カートを取得して明細の正規化を実行 - $Cart = $app['eccube.service.cart']->getCart(); - /** @var PurchaseFlowResult $Result */ - $Result = $app['eccube.purchase.flow.cart']->execute($Cart); - - // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ - if ($Result->hasError()) { - foreach ($Result->getErrors() as $error) { - $app->addRequestError($error->getMessage()); - } - $app['eccube.service.cart']->clear(); - $app['eccube.service.cart']->save(); - - return $app->redirect($app->url('cart')); - } - // 明細の増減・削除 switch ($operation) { case 'up': @@ -166,12 +150,14 @@ public function handleCartItem(Application $app, Request $request, $operation, $ break; } - /** @var PurchaseFlowResult $Result */ - $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + // カートを取得して明細の正規化を実行 + $Cart = $app['eccube.service.cart']->getCart(); + /** @var PurchaseFlowResult $result */ + $result = $app['eccube.purchase.flow.cart']->execute($Cart); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ - if ($Result->hasError()) { - foreach ($Result->getErrors() as $error) { + if ($result->hasError()) { + foreach ($result->getErrors() as $error) { $app->addRequestError($error->getMessage()); } $app['eccube.service.cart']->clear(); @@ -182,7 +168,7 @@ public function handleCartItem(Application $app, Request $request, $operation, $ $app['eccube.service.cart']->save(); - foreach ($Result->getWarning() as $warning) { + foreach ($result->getWarning() as $warning) { $app->addRequestError($warning->getMessage()); } diff --git a/src/Eccube/Service/CartService.php b/src/Eccube/Service/CartService.php index 4ebc50f5dbb..683d07e5274 100644 --- a/src/Eccube/Service/CartService.php +++ b/src/Eccube/Service/CartService.php @@ -53,13 +53,12 @@ public function __construct(Session $session, EntityManager $em) $this->session = $session; $this->cart = $session->get('cart', new Cart()); $this->em = $em; + + $this->loadItems(); } public function getCart() { - // LoadProcessorに切り離してもよい? - $this->loadItems(); - return $this->cart; } From 9085a1b628917ed5c85df2152b4113965b44b530 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Thu, 13 Jul 2017 11:48:34 +0900 Subject: [PATCH 49/75] =?UTF-8?q?ShoppingController=E3=81=AE=E5=88=86?= =?UTF-8?q?=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/AbstractShoppingController.php | 72 ++ .../NonMemberShoppingController.php | 398 ++++++++++ .../Controller/ShippingMultipleController.php | 339 +++++++++ src/Eccube/Controller/ShoppingController.php | 707 +----------------- .../FrontControllerProvider.php | 6 +- 5 files changed, 813 insertions(+), 709 deletions(-) create mode 100644 src/Eccube/Controller/AbstractShoppingController.php create mode 100644 src/Eccube/Controller/NonMemberShoppingController.php create mode 100644 src/Eccube/Controller/ShippingMultipleController.php diff --git a/src/Eccube/Controller/AbstractShoppingController.php b/src/Eccube/Controller/AbstractShoppingController.php new file mode 100644 index 00000000000..bb372fc53ba --- /dev/null +++ b/src/Eccube/Controller/AbstractShoppingController.php @@ -0,0 +1,72 @@ +execute($itemHolder); + foreach ($flowResult->getWarning() as $warning) { + $app->addRequestError($warning->getMessage()); + } + foreach ($flowResult->getErrors() as $error) { + $app->addRequestError($error->getMessage()); + } + return $flowResult; + } + +} \ No newline at end of file diff --git a/src/Eccube/Controller/NonMemberShoppingController.php b/src/Eccube/Controller/NonMemberShoppingController.php new file mode 100644 index 00000000000..8ec219b9409 --- /dev/null +++ b/src/Eccube/Controller/NonMemberShoppingController.php @@ -0,0 +1,398 @@ +forward($app->path("shopping/checkToCart")); + if ($response->isRedirection() || $response->getContent()) { + return $response; + } + + // ログイン済みの場合は, 購入画面へリダイレクト. + if ($app->isGranted('ROLE_USER')) { + return $app->redirect($app->url('shopping')); + } + + $builder = $app['form.factory']->createBuilder(NonMemberType::class); + + $event = new EventArgs( + array( + 'builder' => $builder, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event); + + $form = $builder->getForm(); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + + log_info('非会員お客様情報登録開始'); + + $data = $form->getData(); + $Customer = new Customer(); + $Customer + ->setName01($data['name01']) + ->setName02($data['name02']) + ->setKana01($data['kana01']) + ->setKana02($data['kana02']) + ->setCompanyName($data['company_name']) + ->setEmail($data['email']) + ->setTel01($data['tel01']) + ->setTel02($data['tel02']) + ->setTel03($data['tel03']) + ->setZip01($data['zip01']) + ->setZip02($data['zip02']) + ->setZipCode($data['zip01'].$data['zip02']) + ->setPref($data['pref']) + ->setAddr01($data['addr01']) + ->setAddr02($data['addr02']); + + // 非会員複数配送用 + $CustomerAddress = new CustomerAddress(); + $CustomerAddress + ->setCustomer($Customer) + ->setName01($data['name01']) + ->setName02($data['name02']) + ->setKana01($data['kana01']) + ->setKana02($data['kana02']) + ->setCompanyName($data['company_name']) + ->setTel01($data['tel01']) + ->setTel02($data['tel02']) + ->setTel03($data['tel03']) + ->setZip01($data['zip01']) + ->setZip02($data['zip02']) + ->setZipCode($data['zip01'].$data['zip02']) + ->setPref($data['pref']) + ->setAddr01($data['addr01']) + ->setAddr02($data['addr02']) + ->setDelFlg(Constant::DISABLED); + $Customer->addCustomerAddress($CustomerAddress); + + // 受注情報を取得 + /** @var Order $Order */ + $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); + + // 初回アクセス(受注データがない)の場合は, 受注情報を作成 + if (is_null($Order)) { + // 受注情報を作成 + try { + // 受注情報を作成 +// $Order = $app['eccube.service.shopping']->createOrder($Customer); + $Order = $app['eccube.helper.order']->createProcessingOrder( + $Customer, $Customer->getCustomerAddresses()->current(), $cartService->getCart()->getCartItems()); + $cartService->setPreOrderId($Order->getPreOrderId()); + $cartService->save(); + } catch (CartException $e) { + $app->addRequestError($e->getMessage()); + return $app->redirect($app->url('cart')); + } + } + + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { + return $app->redirect($app->url('cart')); + } + + // 非会員用セッションを作成 + $nonMember = array(); + $nonMember['customer'] = $Customer; + $nonMember['pref'] = $Customer->getPref()->getId(); + $app['session']->set($this->sessionKey, $nonMember); + + $customerAddresses = array(); + $customerAddresses[] = $CustomerAddress; + $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); + + $event = new EventArgs( + array( + 'form' => $form, + 'Order' => $Order, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event); + + if ($event->getResponse() !== null) { + return $event->getResponse(); + } + + log_info('非会員お客様情報登録完了', array($Order->getId())); + + return $app->redirect($app->url('shopping')); + } + + return $app->render('Shopping/nonmember.twig', array( + 'form' => $form->createView(), + )); + } + + /** + * 非会員用複数配送設定時の新規お届け先の設定 + */ + public function shippingMultipleEdit(Application $app, Request $request) + { + // カートチェック + $response = $app->forward($app->path("shopping/checkToCart")); + if ($response->isRedirection() || $response->getContent()) { + return $response; + } + + // 非会員用Customerを取得 + $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); + $CustomerAddress = new CustomerAddress(); + $CustomerAddress->setCustomer($Customer); + $Customer->addCustomerAddress($CustomerAddress); + + $builder = $app['form.factory']->createBuilder(ShoppingShippingType::class, $CustomerAddress); + + $event = new EventArgs( + array( + 'builder' => $builder, + 'Customer' => $Customer, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event); + + $form = $builder->getForm(); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + + log_info('非会員お届け先追加処理開始'); + + // 非会員用のセッションに追加 + $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); + $customerAddresses = unserialize($customerAddresses); + $customerAddresses[] = $CustomerAddress; + $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); + + $event = new EventArgs( + array( + 'form' => $form, + 'CustomerAddresses' => $customerAddresses, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event); + + log_info('非会員お届け先追加処理完了'); + + return $app->redirect($app->url('shopping_shipping_multiple')); + } + + return $app->render('Shopping/shipping_multiple_edit.twig', array( + 'form' => $form->createView(), + )); + } + + /** + * お客様情報の変更(非会員) + */ + public function customer(Application $app, Request $request) + { + if ($request->isXmlHttpRequest()) { + try { + + log_info('非会員お客様情報変更処理開始'); + + $data = $request->request->all(); + + // 入力チェック + $errors = $this->customerValidation($app, $data); + + foreach ($errors as $error) { + if ($error->count() != 0) { + log_info('非会員お客様情報変更入力チェックエラー'); + $response = new Response(json_encode('NG'), 400); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + } + + $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref'])); + if (!$pref) { + log_info('非会員お客様情報変更入力チェックエラー'); + $response = new Response(json_encode('NG'), 400); + $response->headers->set('Content-Type', 'application/json'); + return $response; + } + + $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); + if (!$Order) { + log_info('カートが存在しません'); + $app->addError('front.shopping.order.error'); + return $app->redirect($app->url('shopping_error')); + } + + $Order + ->setName01($data['customer_name01']) + ->setName02($data['customer_name02']) + ->setCompanyName($data['customer_company_name']) + ->setTel01($data['customer_tel01']) + ->setTel02($data['customer_tel02']) + ->setTel03($data['customer_tel03']) + ->setZip01($data['customer_zip01']) + ->setZip02($data['customer_zip02']) + ->setZipCode($data['customer_zip01'].$data['customer_zip02']) + ->setPref($pref) + ->setAddr01($data['customer_addr01']) + ->setAddr02($data['customer_addr02']) + ->setEmail($data['customer_email']); + + // 配送先を更新 + $app['orm.em']->flush(); + + // 受注関連情報を最新状態に更新 + $app['orm.em']->refresh($Order); + + $event = new EventArgs( + array( + 'Order' => $Order, + 'data' => $data, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event); + + log_info('非会員お客様情報変更処理完了', array($Order->getId())); + $response = new Response(json_encode('OK')); + $response->headers->set('Content-Type', 'application/json'); + } catch (\Exception $e) { + log_error('予期しないエラー', array($e->getMessage())); + $app['monolog']->error($e); + + $response = new Response(json_encode('NG'), 500); + $response->headers->set('Content-Type', 'application/json'); + } + + return $response; + } + } + + /** + * 非会員でのお客様情報変更時の入力チェック + * + * @param Application $app + * @param array $data リクエストパラメータ + * @return array + */ + protected function customerValidation(Application $app, array $data) + { + // 入力チェック + $errors = array(); + + $errors[] = $app['validator']->validate($data['customer_name01'], array( + new Assert\NotBlank(), + new Assert\Length(array('max' => $app['config']['name_len'],)), + new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) + )); + + $errors[] = $app['validator']->validate($data['customer_name02'], array( + new Assert\NotBlank(), + new Assert\Length(array('max' => $app['config']['name_len'],)), + new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) + )); + + $errors[] = $app['validator']->validate($data['customer_company_name'], array( + new Assert\Length(array('max' => $app['config']['stext_len'])), + )); + + $errors[] = $app['validator']->validate($data['customer_tel01'], array( + new Assert\NotBlank(), + new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), + new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), + )); + + $errors[] = $app['validator']->validate($data['customer_tel02'], array( + new Assert\NotBlank(), + new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), + new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), + )); + + $errors[] = $app['validator']->validate($data['customer_tel03'], array( + new Assert\NotBlank(), + new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), + new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), + )); + + $errors[] = $app['validator']->validate($data['customer_zip01'], array( + new Assert\NotBlank(), + new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), + new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])), + )); + + $errors[] = $app['validator']->validate($data['customer_zip02'], array( + new Assert\NotBlank(), + new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), + new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])), + )); + + $errors[] = $app['validator']->validate($data['customer_addr01'], array( + new Assert\NotBlank(), + new Assert\Length(array('max' => $app['config']['address1_len'])), + )); + + $errors[] = $app['validator']->validate($data['customer_addr02'], array( + new Assert\NotBlank(), + new Assert\Length(array('max' => $app['config']['address2_len'])), + )); + + $errors[] = $app['validator']->validate($data['customer_email'], array( + new Assert\NotBlank(), + new Assert\Email(array('strict' => true)), + )); + + return $errors; + } +} \ No newline at end of file diff --git a/src/Eccube/Controller/ShippingMultipleController.php b/src/Eccube/Controller/ShippingMultipleController.php new file mode 100644 index 00000000000..35c81514ec9 --- /dev/null +++ b/src/Eccube/Controller/ShippingMultipleController.php @@ -0,0 +1,339 @@ +forward($app->path("shopping/checkToCart")); + if ($response->isRedirection() || $response->getContent()) { + return $response; + } + + /** @var \Eccube\Entity\Order $Order */ + $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); + if (!$Order) { + log_info('購入処理中の受注情報がないため購入エラー'); + $app->addError('front.shopping.order.error'); + return $app->redirect($app->url('shopping_error')); + } + + // 処理しやすいようにすべてのShippingItemをまとめる + $ShipmentItems = array(); + foreach ($Order->getShippings() as $Shipping) { + foreach ($Shipping->getProductOrderItems() as $ShipmentItem) { + $ShipmentItems[] = $ShipmentItem; + } + } + + // Orderに含まれる商品ごとの数量を求める + $ItemQuantitiesByClassId = array(); + foreach ($ShipmentItems as $item) { + $itemId = $item->getProductClass()->getId(); + $quantity = $item->getQuantity(); + if (array_key_exists($itemId, $ItemQuantitiesByClassId)) { + $ItemQuantitiesByClassId[$itemId] += $quantity; + } else { + $ItemQuantitiesByClassId[$itemId] = $quantity; + } + } + + // FormBuilder用に商品ごとにShippingItemをまとめる + $ShipmentItemsForFormBuilder = array(); + $tmpAddedClassIds = array(); + foreach ($ShipmentItems as $item) { + $itemId = $item->getProductClass()->getId(); + if (!in_array($itemId, $tmpAddedClassIds)) { + $ShipmentItemsForFormBuilder[] = $item; + $tmpAddedClassIds[] = $itemId; + } + } + + // Form生成 + $builder = $app->form(); + $builder + ->add('shipping_multiple', CollectionType::class, array( + 'entry_type' => ShippingMultipleType::class, + 'data' => $ShipmentItemsForFormBuilder, + 'allow_add' => true, + 'allow_delete' => true, + )); + // Event + $event = new EventArgs( + array( + 'builder' => $builder, + 'Order' => $Order, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event); + + $form = $builder->getForm(); + $form->handleRequest($request); + + $errors = array(); + if ($form->isSubmitted() && $form->isValid()) { + + log_info('複数配送設定処理開始', array($Order->getId())); + + $data = $form['shipping_multiple']; + + // フォームの入力から、送り先ごとに商品の数量を集計する + $arrShipmentItemTemp = array(); + foreach ($data as $mulitples) { + $ShipmentItem = $mulitples->getData(); + foreach ($mulitples as $items) { + foreach ($items as $item) { + $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); + $itemId = $ShipmentItem->getProductClass()->getId(); + $quantity = $item['quantity']->getData(); + + if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($itemId, $arrShipmentItemTemp[$cusAddId])) { + $arrShipmentItemTemp[$cusAddId][$itemId] = $arrShipmentItemTemp[$cusAddId][$itemId] + $quantity; + } else { + $arrShipmentItemTemp[$cusAddId][$itemId] = $quantity; + } + } + } + } + + // フォームの入力から、商品ごとの数量を集計する + $itemQuantities = array(); + foreach ($arrShipmentItemTemp as $FormItemByAddress) { + foreach ($FormItemByAddress as $itemId => $quantity) { + if (array_key_exists($itemId, $itemQuantities)) { + $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity; + } else { + $itemQuantities[$itemId] = $quantity; + } + } + } + + // 「Orderに含まれる商品ごとの数量」と「フォームに入力された商品ごとの数量」が一致しているかの確認 + // 数量が異なっているならエラーを表示する + foreach ($ItemQuantitiesByClassId as $key => $value) { + if (array_key_exists($key, $itemQuantities)) { + if ($itemQuantities[$key] != $value) { + $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff')); + + // 対象がなければエラー + log_info('複数配送設定入力チェックエラー', array($Order->getId())); + return $app->render('Shopping/shipping_multiple.twig', array( + 'form' => $form->createView(), + 'shipmentItems' => $ShipmentItemsForFormBuilder, + 'compItemQuantities' => $ItemQuantitiesByClassId, + 'errors' => $errors, + )); + } + } + } + + // -- ここから先がお届け先を再生成する処理 -- + + // お届け先情報をすべて削除 + foreach ($Order->getShippings() as $Shipping) { + $app['orm.em']->remove($Shipping); + } + + // お届け先のリストを作成する + $ShippingList = array(); + foreach ($data as $mulitples) { + $ShipmentItem = $mulitples->getData(); + $ProductClass = $ShipmentItem->getProductClass(); + $Delivery = $ShipmentItem->getShipping()->getDelivery(); + $productTypeId = $ProductClass->getProductType()->getId(); + + foreach ($mulitples as $items) { + foreach ($items as $item) { + $CustomerAddress = $this->getCustomerAddress($app, $item['customer_address']->getData()); + $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); + + $Shipping = new Shipping(); + $Shipping + ->setFromCustomerAddress($CustomerAddress) + ->setDelivery($Delivery) + ->setDelFlg(Constant::DISABLED); + + $ShippingList[$cusAddId][$productTypeId] = $Shipping; + } + } + } + // お届け先のリストを保存 + foreach ($ShippingList as $ShippingListByAddress) { + foreach ($ShippingListByAddress as $Shipping) { + $app['orm.em']->persist($Shipping); + } + } + + $ProductOrderType = $app['eccube.repository.master.order_item_type']->find(OrderItemType::PRODUCT); + + // お届け先に、配送商品の情報(ShipmentItem)を関連付ける + foreach ($data as $mulitples) { + $ShipmentItem = $mulitples->getData(); + $ProductClass = $ShipmentItem->getProductClass(); + $Product = $ShipmentItem->getProduct(); + $productTypeId = $ProductClass->getProductType()->getId(); + $productClassId = $ProductClass->getId(); + + foreach ($mulitples as $items) { + foreach ($items as $item) { + $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); + + // お届け先から商品の数量を取得 + $quantity = 0; + if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($productClassId, $arrShipmentItemTemp[$cusAddId])) { + $quantity = $arrShipmentItemTemp[$cusAddId][$productClassId]; + unset($arrShipmentItemTemp[$cusAddId][$productClassId]); + } else { + // この配送先には送る商品がないのでスキップ(通常ありえない) + continue; + } + + // 関連付けるお届け先のインスタンスを取得 + $Shipping = $ShippingList[$cusAddId][$productTypeId]; + + // インスタンスを生成して保存 + $ShipmentItem = new ShipmentItem(); + $ShipmentItem->setShipping($Shipping) + ->setOrder($Order) + ->setProductClass($ProductClass) + ->setProduct($Product) + ->setProductName($Product->getName()) + ->setProductCode($ProductClass->getCode()) + ->setPrice($ProductClass->getPrice02()) + ->setQuantity($quantity) + ->setOrderItemType($ProductOrderType); + + $ClassCategory1 = $ProductClass->getClassCategory1(); + if (!is_null($ClassCategory1)) { + $ShipmentItem->setClasscategoryName1($ClassCategory1->getName()); + $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName()); + } + $ClassCategory2 = $ProductClass->getClassCategory2(); + if (!is_null($ClassCategory2)) { + $ShipmentItem->setClasscategoryName2($ClassCategory2->getName()); + $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName()); + } + $Shipping->addShipmentItem($ShipmentItem); + $app['orm.em']->persist($ShipmentItem); + } + } + } + + // 送料を計算(お届け先ごと) + foreach ($ShippingList as $data) { + // data is product type => shipping + foreach ($data as $Shipping) { + // 配送料金の設定 + $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); + } + } + + // 合計金額の再計算 + $flowResult = $this->executePurchaseFlow($app, $Order); + if ($flowResult->hasWarning() || $flowResult->hasError()) { + return $app->redirect($app->url('shopping_error')); + } + + // 配送先を更新 + $app['orm.em']->flush(); + + $event = new EventArgs( + array( + 'form' => $form, + 'Order' => $Order, + ), + $request + ); + $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event); + + log_info('複数配送設定処理完了', array($Order->getId())); + return $app->redirect($app->url('shopping')); + } + + return $app->render('Shopping/shipping_multiple.twig', array( + 'form' => $form->createView(), + 'shipmentItems' => $ShipmentItemsForFormBuilder, + 'compItemQuantities' => $ItemQuantitiesByClassId, + 'errors' => $errors, + )); + } + + /** + * フォームの情報からお届け先のインデックスを返す + * @param mixed $CustomerAddressData + * @return int + */ + private function getCustomerAddressId($CustomerAddressData) + { + if ($CustomerAddressData instanceof CustomerAddress) { + return $CustomerAddressData->getId(); + } else { + return $CustomerAddressData; + } + } + + /** + * フォームの情報からお届け先のインスタンスを返す + * + * @param Application $app + * @param mixed $CustomerAddressData + * @return CustomerAddress + */ + private function getCustomerAddress(Application $app, $CustomerAddressData) + { + if ($CustomerAddressData instanceof CustomerAddress) { + return $CustomerAddressData; + } else { + $cusAddId = $CustomerAddressData; + $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); + $customerAddresses = unserialize($customerAddresses); + + $CustomerAddress = $customerAddresses[$cusAddId]; + $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId()); + $CustomerAddress->setPref($pref); + + return $CustomerAddress; + } + } +} \ No newline at end of file diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index b8a9408e17e..ec44c6ef36b 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -25,59 +25,28 @@ namespace Eccube\Controller; use Eccube\Application; -use Eccube\Common\Constant; use Eccube\Entity\Customer; use Eccube\Entity\CustomerAddress; -use Eccube\Entity\ItemHolderInterface; -use Eccube\Entity\Master\OrderItemType; use Eccube\Entity\Order; -use Eccube\Entity\ShipmentItem; -use Eccube\Entity\Shipping; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Exception\CartException; use Eccube\Exception\ShoppingException; use Eccube\Form\Type\Front\CustomerLoginType; -use Eccube\Form\Type\Front\NonMemberType; use Eccube\Form\Type\Front\ShoppingShippingType; -use Eccube\Form\Type\ShippingMultipleType; use Eccube\Form\Type\Shopping\OrderType; -use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; -use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Validator\Constraints as Assert; /** * @Route("/shopping") */ -class ShoppingController extends AbstractController +class ShoppingController extends AbstractShoppingController { - - /** - * @var string 非会員用セッションキー - */ - private $sessionKey = 'eccube.front.shopping.nonmember'; - - /** - * @var string 非会員用セッションキー - */ - private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress'; - - /** - * @var string 複数配送警告メッセージ - */ - private $sessionMultipleKey = 'eccube.front.shopping.multiple'; - - /** - * @var string 受注IDキー - */ - private $sessionOrderKey = 'eccube.front.shopping.order.id'; - /** * 購入画面表示 * @@ -446,90 +415,6 @@ public function shippingEdit(Application $app, Request $request, $id) )); } - /** - * お客様情報の変更(非会員) - */ - public function customer(Application $app, Request $request) - { - if ($request->isXmlHttpRequest()) { - try { - - log_info('非会員お客様情報変更処理開始'); - - $data = $request->request->all(); - - // 入力チェック - $errors = $this->customerValidation($app, $data); - - foreach ($errors as $error) { - if ($error->count() != 0) { - log_info('非会員お客様情報変更入力チェックエラー'); - $response = new Response(json_encode('NG'), 400); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } - } - - $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref'])); - if (!$pref) { - log_info('非会員お客様情報変更入力チェックエラー'); - $response = new Response(json_encode('NG'), 400); - $response->headers->set('Content-Type', 'application/json'); - return $response; - } - - $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); - if (!$Order) { - log_info('カートが存在しません'); - $app->addError('front.shopping.order.error'); - return $app->redirect($app->url('shopping_error')); - } - - $Order - ->setName01($data['customer_name01']) - ->setName02($data['customer_name02']) - ->setCompanyName($data['customer_company_name']) - ->setTel01($data['customer_tel01']) - ->setTel02($data['customer_tel02']) - ->setTel03($data['customer_tel03']) - ->setZip01($data['customer_zip01']) - ->setZip02($data['customer_zip02']) - ->setZipCode($data['customer_zip01'].$data['customer_zip02']) - ->setPref($pref) - ->setAddr01($data['customer_addr01']) - ->setAddr02($data['customer_addr02']) - ->setEmail($data['customer_email']); - - // 配送先を更新 - $app['orm.em']->flush(); - - // 受注関連情報を最新状態に更新 - $app['orm.em']->refresh($Order); - - $event = new EventArgs( - array( - 'Order' => $Order, - 'data' => $data, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event); - - log_info('非会員お客様情報変更処理完了', array($Order->getId())); - $response = new Response(json_encode('OK')); - $response->headers->set('Content-Type', 'application/json'); - } catch (\Exception $e) { - log_error('予期しないエラー', array($e->getMessage())); - $app['monolog']->error($e); - - $response = new Response(json_encode('NG'), 500); - $response->headers->set('Content-Type', 'application/json'); - } - - return $response; - } - } - /** * ログイン */ @@ -569,501 +454,6 @@ public function login(Application $app, Request $request) )); } - /** - * 非会員処理 - */ - public function nonmember(Application $app, Request $request) - { - $cartService = $app['eccube.service.cart']; - - // カートチェック - $response = $app->forward($app->path("shopping/checkToCart")); - if ($response->isRedirection() || $response->getContent()) { - return $response; - } - - // ログイン済みの場合は, 購入画面へリダイレクト. - if ($app->isGranted('ROLE_USER')) { - return $app->redirect($app->url('shopping')); - } - - $builder = $app['form.factory']->createBuilder(NonMemberType::class); - - $event = new EventArgs( - array( - 'builder' => $builder, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event); - - $form = $builder->getForm(); - - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - - log_info('非会員お客様情報登録開始'); - - $data = $form->getData(); - $Customer = new Customer(); - $Customer - ->setName01($data['name01']) - ->setName02($data['name02']) - ->setKana01($data['kana01']) - ->setKana02($data['kana02']) - ->setCompanyName($data['company_name']) - ->setEmail($data['email']) - ->setTel01($data['tel01']) - ->setTel02($data['tel02']) - ->setTel03($data['tel03']) - ->setZip01($data['zip01']) - ->setZip02($data['zip02']) - ->setZipCode($data['zip01'].$data['zip02']) - ->setPref($data['pref']) - ->setAddr01($data['addr01']) - ->setAddr02($data['addr02']); - - // 非会員複数配送用 - $CustomerAddress = new CustomerAddress(); - $CustomerAddress - ->setCustomer($Customer) - ->setName01($data['name01']) - ->setName02($data['name02']) - ->setKana01($data['kana01']) - ->setKana02($data['kana02']) - ->setCompanyName($data['company_name']) - ->setTel01($data['tel01']) - ->setTel02($data['tel02']) - ->setTel03($data['tel03']) - ->setZip01($data['zip01']) - ->setZip02($data['zip02']) - ->setZipCode($data['zip01'].$data['zip02']) - ->setPref($data['pref']) - ->setAddr01($data['addr01']) - ->setAddr02($data['addr02']) - ->setDelFlg(Constant::DISABLED); - $Customer->addCustomerAddress($CustomerAddress); - - // 受注情報を取得 - /** @var Order $Order */ - $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); - - // 初回アクセス(受注データがない)の場合は, 受注情報を作成 - if (is_null($Order)) { - // 受注情報を作成 - try { - // 受注情報を作成 -// $Order = $app['eccube.service.shopping']->createOrder($Customer); - $Order = $app['eccube.helper.order']->createProcessingOrder( - $Customer, $Customer->getCustomerAddresses()->current(), $cartService->getCart()->getCartItems()); - $cartService->setPreOrderId($Order->getPreOrderId()); - $cartService->save(); - } catch (CartException $e) { - $app->addRequestError($e->getMessage()); - return $app->redirect($app->url('cart')); - } - } - - $flowResult = $this->executePurchaseFlow($app, $Order); - if ($flowResult->hasWarning() || $flowResult->hasError()) { - return $app->redirect($app->url('cart')); - } - - // 非会員用セッションを作成 - $nonMember = array(); - $nonMember['customer'] = $Customer; - $nonMember['pref'] = $Customer->getPref()->getId(); - $app['session']->set($this->sessionKey, $nonMember); - - $customerAddresses = array(); - $customerAddresses[] = $CustomerAddress; - $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); - - $event = new EventArgs( - array( - 'form' => $form, - 'Order' => $Order, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event); - - if ($event->getResponse() !== null) { - return $event->getResponse(); - } - - log_info('非会員お客様情報登録完了', array($Order->getId())); - - return $app->redirect($app->url('shopping')); - } - - return $app->render('Shopping/nonmember.twig', array( - 'form' => $form->createView(), - )); - } - - /** - * 複数配送処理 - */ - public function shippingMultiple(Application $app, Request $request) - { - // カートチェック - $response = $app->forward($app->path("shopping/checkToCart")); - if ($response->isRedirection() || $response->getContent()) { - return $response; - } - - /** @var \Eccube\Entity\Order $Order */ - $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']); - if (!$Order) { - log_info('購入処理中の受注情報がないため購入エラー'); - $app->addError('front.shopping.order.error'); - return $app->redirect($app->url('shopping_error')); - } - - // 処理しやすいようにすべてのShippingItemをまとめる - $ShipmentItems = array(); - foreach ($Order->getShippings() as $Shipping) { - foreach ($Shipping->getProductOrderItems() as $ShipmentItem) { - $ShipmentItems[] = $ShipmentItem; - } - } - - // Orderに含まれる商品ごとの数量を求める - $ItemQuantitiesByClassId = array(); - foreach ($ShipmentItems as $item) { - $itemId = $item->getProductClass()->getId(); - $quantity = $item->getQuantity(); - if (array_key_exists($itemId, $ItemQuantitiesByClassId)) { - $ItemQuantitiesByClassId[$itemId] += $quantity; - } else { - $ItemQuantitiesByClassId[$itemId] = $quantity; - } - } - - // FormBuilder用に商品ごとにShippingItemをまとめる - $ShipmentItemsForFormBuilder = array(); - $tmpAddedClassIds = array(); - foreach ($ShipmentItems as $item) { - $itemId = $item->getProductClass()->getId(); - if (!in_array($itemId, $tmpAddedClassIds)) { - $ShipmentItemsForFormBuilder[] = $item; - $tmpAddedClassIds[] = $itemId; - } - } - - // Form生成 - $builder = $app->form(); - $builder - ->add('shipping_multiple', CollectionType::class, array( - 'entry_type' => ShippingMultipleType::class, - 'data' => $ShipmentItemsForFormBuilder, - 'allow_add' => true, - 'allow_delete' => true, - )); - // Event - $event = new EventArgs( - array( - 'builder' => $builder, - 'Order' => $Order, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event); - - $form = $builder->getForm(); - $form->handleRequest($request); - - $errors = array(); - if ($form->isSubmitted() && $form->isValid()) { - - log_info('複数配送設定処理開始', array($Order->getId())); - - $data = $form['shipping_multiple']; - - // フォームの入力から、送り先ごとに商品の数量を集計する - $arrShipmentItemTemp = array(); - foreach ($data as $mulitples) { - $ShipmentItem = $mulitples->getData(); - foreach ($mulitples as $items) { - foreach ($items as $item) { - $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); - $itemId = $ShipmentItem->getProductClass()->getId(); - $quantity = $item['quantity']->getData(); - - if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($itemId, $arrShipmentItemTemp[$cusAddId])) { - $arrShipmentItemTemp[$cusAddId][$itemId] = $arrShipmentItemTemp[$cusAddId][$itemId] + $quantity; - } else { - $arrShipmentItemTemp[$cusAddId][$itemId] = $quantity; - } - } - } - } - - // フォームの入力から、商品ごとの数量を集計する - $itemQuantities = array(); - foreach ($arrShipmentItemTemp as $FormItemByAddress) { - foreach ($FormItemByAddress as $itemId => $quantity) { - if (array_key_exists($itemId, $itemQuantities)) { - $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity; - } else { - $itemQuantities[$itemId] = $quantity; - } - } - } - - // 「Orderに含まれる商品ごとの数量」と「フォームに入力された商品ごとの数量」が一致しているかの確認 - // 数量が異なっているならエラーを表示する - foreach ($ItemQuantitiesByClassId as $key => $value) { - if (array_key_exists($key, $itemQuantities)) { - if ($itemQuantities[$key] != $value) { - $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff')); - - // 対象がなければエラー - log_info('複数配送設定入力チェックエラー', array($Order->getId())); - return $app->render('Shopping/shipping_multiple.twig', array( - 'form' => $form->createView(), - 'shipmentItems' => $ShipmentItemsForFormBuilder, - 'compItemQuantities' => $ItemQuantitiesByClassId, - 'errors' => $errors, - )); - } - } - } - - // -- ここから先がお届け先を再生成する処理 -- - - // お届け先情報をすべて削除 - foreach ($Order->getShippings() as $Shipping) { - $app['orm.em']->remove($Shipping); - } - - // お届け先のリストを作成する - $ShippingList = array(); - foreach ($data as $mulitples) { - $ShipmentItem = $mulitples->getData(); - $ProductClass = $ShipmentItem->getProductClass(); - $Delivery = $ShipmentItem->getShipping()->getDelivery(); - $productTypeId = $ProductClass->getProductType()->getId(); - - foreach ($mulitples as $items) { - foreach ($items as $item) { - $CustomerAddress = $this->getCustomerAddress($app, $item['customer_address']->getData()); - $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); - - $Shipping = new Shipping(); - $Shipping - ->setFromCustomerAddress($CustomerAddress) - ->setDelivery($Delivery) - ->setDelFlg(Constant::DISABLED); - - $ShippingList[$cusAddId][$productTypeId] = $Shipping; - } - } - } - // お届け先のリストを保存 - foreach ($ShippingList as $ShippingListByAddress) { - foreach ($ShippingListByAddress as $Shipping) { - $app['orm.em']->persist($Shipping); - } - } - - $ProductOrderType = $app['eccube.repository.master.order_item_type']->find(OrderItemType::PRODUCT); - - // お届け先に、配送商品の情報(ShipmentItem)を関連付ける - foreach ($data as $mulitples) { - $ShipmentItem = $mulitples->getData(); - $ProductClass = $ShipmentItem->getProductClass(); - $Product = $ShipmentItem->getProduct(); - $productTypeId = $ProductClass->getProductType()->getId(); - $productClassId = $ProductClass->getId(); - - foreach ($mulitples as $items) { - foreach ($items as $item) { - $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData()); - - // お届け先から商品の数量を取得 - $quantity = 0; - if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($productClassId, $arrShipmentItemTemp[$cusAddId])) { - $quantity = $arrShipmentItemTemp[$cusAddId][$productClassId]; - unset($arrShipmentItemTemp[$cusAddId][$productClassId]); - } else { - // この配送先には送る商品がないのでスキップ(通常ありえない) - continue; - } - - // 関連付けるお届け先のインスタンスを取得 - $Shipping = $ShippingList[$cusAddId][$productTypeId]; - - // インスタンスを生成して保存 - $ShipmentItem = new ShipmentItem(); - $ShipmentItem->setShipping($Shipping) - ->setOrder($Order) - ->setProductClass($ProductClass) - ->setProduct($Product) - ->setProductName($Product->getName()) - ->setProductCode($ProductClass->getCode()) - ->setPrice($ProductClass->getPrice02()) - ->setQuantity($quantity) - ->setOrderItemType($ProductOrderType); - - $ClassCategory1 = $ProductClass->getClassCategory1(); - if (!is_null($ClassCategory1)) { - $ShipmentItem->setClasscategoryName1($ClassCategory1->getName()); - $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName()); - } - $ClassCategory2 = $ProductClass->getClassCategory2(); - if (!is_null($ClassCategory2)) { - $ShipmentItem->setClasscategoryName2($ClassCategory2->getName()); - $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName()); - } - $Shipping->addShipmentItem($ShipmentItem); - $app['orm.em']->persist($ShipmentItem); - } - } - } - - // 送料を計算(お届け先ごと) - foreach ($ShippingList as $data) { - // data is product type => shipping - foreach ($data as $Shipping) { - // 配送料金の設定 - $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping); - } - } - - // 合計金額の再計算 - $flowResult = $this->executePurchaseFlow($app, $Order); - if ($flowResult->hasWarning() || $flowResult->hasError()) { - return $app->redirect($app->url('shopping_error')); - } - - // 配送先を更新 - $app['orm.em']->flush(); - - $event = new EventArgs( - array( - 'form' => $form, - 'Order' => $Order, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event); - - log_info('複数配送設定処理完了', array($Order->getId())); - return $app->redirect($app->url('shopping')); - } - - return $app->render('Shopping/shipping_multiple.twig', array( - 'form' => $form->createView(), - 'shipmentItems' => $ShipmentItemsForFormBuilder, - 'compItemQuantities' => $ItemQuantitiesByClassId, - 'errors' => $errors, - )); - } - - /** - * フォームの情報からお届け先のインデックスを返す - * - * @param Application $app - * @param mixed $CustomerAddressData - * @return int - */ - private function getCustomerAddressId($CustomerAddressData) - { - if ($CustomerAddressData instanceof CustomerAddress) { - return $CustomerAddressData->getId(); - } else { - return $CustomerAddressData; - } - } - - /** - * フォームの情報からお届け先のインスタンスを返す - * - * @param Application $app - * @param mixed $CustomerAddressData - * @return CustomerAddress - */ - private function getCustomerAddress(Application $app, $CustomerAddressData) - { - if ($CustomerAddressData instanceof CustomerAddress) { - return $CustomerAddressData; - } else { - $cusAddId = $CustomerAddressData; - $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); - $customerAddresses = unserialize($customerAddresses); - - $CustomerAddress = $customerAddresses[$cusAddId]; - $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId()); - $CustomerAddress->setPref($pref); - - return $CustomerAddress; - } - } - - /** - * 非会員用複数配送設定時の新規お届け先の設定 - */ - public function shippingMultipleEdit(Application $app, Request $request) - { - // カートチェック - $response = $app->forward($app->path("shopping/checkToCart")); - if ($response->isRedirection() || $response->getContent()) { - return $response; - } - - // 非会員用Customerを取得 - $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey); - $CustomerAddress = new CustomerAddress(); - $CustomerAddress->setCustomer($Customer); - $Customer->addCustomerAddress($CustomerAddress); - - $builder = $app['form.factory']->createBuilder(ShoppingShippingType::class, $CustomerAddress); - - $event = new EventArgs( - array( - 'builder' => $builder, - 'Customer' => $Customer, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event); - - $form = $builder->getForm(); - - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - - log_info('非会員お届け先追加処理開始'); - - // 非会員用のセッションに追加 - $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey); - $customerAddresses = unserialize($customerAddresses); - $customerAddresses[] = $CustomerAddress; - $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses)); - - $event = new EventArgs( - array( - 'form' => $form, - 'CustomerAddresses' => $customerAddresses, - ), - $request - ); - $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event); - - log_info('非会員お届け先追加処理完了'); - - return $app->redirect($app->url('shopping_shipping_multiple')); - } - - return $app->render('Shopping/shipping_multiple_edit.twig', array( - 'form' => $form->createView(), - )); - } - /** * 購入エラー画面表示 */ @@ -1083,82 +473,6 @@ public function shoppingError(Application $app, Request $request) return $app->render('Shopping/shopping_error.twig'); } - /** - * 非会員でのお客様情報変更時の入力チェック - * - * @param Application $app - * @param array $data リクエストパラメータ - * @return array - */ - protected function customerValidation(Application $app, array $data) - { - // 入力チェック - $errors = array(); - - $errors[] = $app['validator']->validate($data['customer_name01'], array( - new Assert\NotBlank(), - new Assert\Length(array('max' => $app['config']['name_len'],)), - new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) - )); - - $errors[] = $app['validator']->validate($data['customer_name02'], array( - new Assert\NotBlank(), - new Assert\Length(array('max' => $app['config']['name_len'],)), - new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace')) - )); - - $errors[] = $app['validator']->validate($data['customer_company_name'], array( - new Assert\Length(array('max' => $app['config']['stext_len'])), - )); - - $errors[] = $app['validator']->validate($data['customer_tel01'], array( - new Assert\NotBlank(), - new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), - new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), - )); - - $errors[] = $app['validator']->validate($data['customer_tel02'], array( - new Assert\NotBlank(), - new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), - new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), - )); - - $errors[] = $app['validator']->validate($data['customer_tel03'], array( - new Assert\NotBlank(), - new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), - new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])), - )); - - $errors[] = $app['validator']->validate($data['customer_zip01'], array( - new Assert\NotBlank(), - new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), - new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])), - )); - - $errors[] = $app['validator']->validate($data['customer_zip02'], array( - new Assert\NotBlank(), - new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')), - new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])), - )); - - $errors[] = $app['validator']->validate($data['customer_addr01'], array( - new Assert\NotBlank(), - new Assert\Length(array('max' => $app['config']['address1_len'])), - )); - - $errors[] = $app['validator']->validate($data['customer_addr02'], array( - new Assert\NotBlank(), - new Assert\Length(array('max' => $app['config']['address2_len'])), - )); - - $errors[] = $app['validator']->validate($data['customer_email'], array( - new Assert\NotBlank(), - new Assert\Email(array('strict' => true)), - )); - - return $errors; - } - /** * カート画面のチェック * @@ -1317,7 +631,6 @@ public function redirectToChange(Application $app, Request $request) /** * 複数配送時のエラーを表示する - * TODO ItemHolderProcessor化? * * @Route("/handleMultipleErrors", name="shopping/handleMultipleErrors") * @param Application $app @@ -1514,22 +827,4 @@ public function afterComplete(Application $app, Request $request) // 完了画面表示 return $app->redirect($app->url('shopping_complete')); } - - /** - * @param Application $app - * @param ItemHolderInterface $itemHolder - * @return PurchaseFlowResult - */ - private function executePurchaseFlow(Application $app, ItemHolderInterface $itemHolder) - { - /** @var PurchaseFlowResult $flowResult */ - $flowResult = $app['eccube.purchase.flow.shopping']->execute($itemHolder); - foreach ($flowResult->getWarning() as $warning) { - $app->addRequestError($warning->getMessage()); - } - foreach ($flowResult->getErrors() as $error) { - $app->addRequestError($error->getMessage()); - } - return $flowResult; - } } diff --git a/src/Eccube/ControllerProvider/FrontControllerProvider.php b/src/Eccube/ControllerProvider/FrontControllerProvider.php index 52dde5db283..c8bae6c5096 100644 --- a/src/Eccube/ControllerProvider/FrontControllerProvider.php +++ b/src/Eccube/ControllerProvider/FrontControllerProvider.php @@ -112,11 +112,11 @@ public function connect(Application $app) $c->match('/shopping/shipping_edit/{id}', '\Eccube\Controller\ShoppingController::shippingEdit')->assert('id', '\d+')->bind('shopping_shipping_edit'); $c->match('/shopping/complete', '\Eccube\Controller\ShoppingController::complete')->bind('shopping_complete'); $c->match('/shopping/login', '\Eccube\Controller\ShoppingController::login')->bind('shopping_login'); - $c->match('/shopping/nonmember', '\Eccube\Controller\ShoppingController::nonmember')->bind('shopping_nonmember'); - $c->match('/shopping/customer', '\Eccube\Controller\ShoppingController::customer')->bind('shopping_customer'); + $c->match('/shopping/nonmember', '\Eccube\Controller\NonMemberShoppingController::index')->bind('shopping_nonmember'); + $c->match('/shopping/customer', '\Eccube\Controller\NonMemberShoppingController::customer')->bind('shopping_customer'); $c->match('/shopping/shopping_error', '\Eccube\Controller\ShoppingController::shoppingError')->bind('shopping_error'); $c->match('/shopping/shipping_multiple_change', '\Eccube\Controller\ShoppingController::shippingMultipleChange')->bind('shopping_shipping_multiple_change'); - $c->match('/shopping/shipping_multiple', '\Eccube\Controller\ShoppingController::shippingMultiple')->bind('shopping_shipping_multiple'); + $c->match('/shopping/shipping_multiple', '\Eccube\Controller\ShippingMultipleController::index')->bind('shopping_shipping_multiple'); $c->match('/shopping/shipping_multiple_edit', '\Eccube\Controller\ShoppingController::shippingMultipleEdit')->bind('shopping_shipping_multiple_edit'); return $c; From 8ac84d65ce470dfc8d1f14f22b596bc09b9148e7 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 13 Jul 2017 18:15:33 +0900 Subject: [PATCH 50/75] =?UTF-8?q?=E5=95=86=E5=93=81=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9?= =?UTF-8?q?=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/ProductController.php | 22 ++++++++++--------- src/Eccube/Service/CartService.php | 3 +++ .../Processor/PaymentProcessor.php | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Eccube/Controller/ProductController.php b/src/Eccube/Controller/ProductController.php index 24f29da9390..648e9b32b29 100644 --- a/src/Eccube/Controller/ProductController.php +++ b/src/Eccube/Controller/ProductController.php @@ -26,6 +26,7 @@ use Eccube\Application; use Eccube\Common\Constant; +use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Exception\CartException; @@ -278,21 +279,22 @@ public function detail(Application $app, Request $request, $id) $app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity']); // 明細の正規化 - $Result = $app['eccube.purchase.flow.cart']->execute($Cart); + $result = $app['eccube.purchase.flow.cart']->execute($Cart); - // 復旧不可のエラーが発生した場合はsaveしない. - if ($Result->hasError()) { - foreach ($Result->getErrors() as $error) { + // 復旧不可のエラーが発生した場合は追加した明細を削除. + if ($result->hasError()) { + $Cart->removeCartItemByIdentifier(ProductClass::class, $addCartData['product_class_id']); + foreach ($result->getErrors() as $error) { $app->addRequestError($error); } - } else { - foreach ($Result->getWarning() as $warning) { - $app->addRequestError($warning); - } - // エラーがなければsave - $app['eccube.service.cart']->save(); } + foreach ($result->getWarning() as $warning) { + $app->addRequestError($warning); + } + + $app['eccube.service.cart']->save(); + log_info('カート追加処理完了', array('product_id' => $Product->getId(), 'product_class_id' => $addCartData['product_class_id'], 'quantity' => $addCartData['quantity'])); $event = new EventArgs( diff --git a/src/Eccube/Service/CartService.php b/src/Eccube/Service/CartService.php index 683d07e5274..9b5706b0b96 100644 --- a/src/Eccube/Service/CartService.php +++ b/src/Eccube/Service/CartService.php @@ -57,6 +57,9 @@ public function __construct(Session $session, EntityManager $em) $this->loadItems(); } + /** + * @return ItemHolderInterface|Cart + */ public function getCart() { return $this->cart; diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index e036b57a7e7..b66009bbb72 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -85,7 +85,7 @@ protected function validate(ItemHolderInterface $itemHolder) // 共通項がなければエラー if (empty($paymentIds)) { - throw new ItemValidateException(); + throw new ItemValidateException('支払い方法が異なる'); } } From 24dd7609db6a7b053d6f8bf4e3bee96bbeb0d6d3 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 14 Jul 2017 12:48:29 +0900 Subject: [PATCH 51/75] =?UTF-8?q?PurchaseFlow=E3=81=AEProcessor=E3=82=92Ar?= =?UTF-8?q?rayCollection=E3=81=A7=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/PurchaseFlow.php | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 3e5d803130e..9f583e967f1 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -2,26 +2,48 @@ namespace Eccube\Service\PurchaseFlow; +use Doctrine\Common\Collections\ArrayCollection; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ItemInterface; class PurchaseFlow { - // TODO collection? /** - * @var ItemHolderProcessor[] + * @var ArrayCollection|ItemHolderProcessor[] */ - protected $itemHolderProcessors = []; + protected $itemHolderProcessors; /** - * @var ItemProcessor[] + * @var ArrayCollection|ItemProcessor[] */ - protected $itemProcessors = []; + protected $itemProcessors; /** - * @var PurchaseProcessor[] + * @var ArrayCollection|PurchaseProcessor[] */ - protected $purchaseProcessors = []; + protected $purchaseProcessors; + + public function __construct() + { + $this->itemProcessors = new ArrayCollection(); + $this->itemHolderProcessors = new ArrayCollection(); + $this->purchaseProcessors = new ArrayCollection(); + } + + public function setItemProcessors(ArrayCollection $processors) + { + $this->itemProcessors = $processors; + } + + public function setItemHolderProcessors(ArrayCollection $processors) + { + $this->itemHolderProcessors = $processors; + } + + public function setPurchaseProcessors(ArrayCollection $processors) + { + $this->purchaseProcessors = $processors; + } public function execute(ItemHolderInterface $itemHolder) { From 57ba170da0ef8343e999e3258aade770bd858817 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 14 Jul 2017 12:49:18 +0900 Subject: [PATCH 52/75] =?UTF-8?q?cartFlow=E3=81=AEproccessor=E3=82=92di?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServiceProvider/EccubeServiceProvider.php | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index b68a37a13c4..7e16f69b1db 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -24,6 +24,7 @@ namespace Eccube\ServiceProvider; +use Doctrine\Common\Collections\ArrayCollection; use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; @@ -535,18 +536,39 @@ public function register(Container $app) // TODO QueryCustomizerの追加方法は要検討 $app['eccube.queries']->addCustomizer(new \Acme\Entity\AdminProductListCustomizer()); - $app['eccube.purchase.flow.cart'] = function () use ($app) { + $app['eccube.purchase.flow.cart.item_processors'] = function ($app) { + $processors = new ArrayCollection(); + $processors->add(new DeletedProductValidator()); + $processors->add(new DisplayStatusValidator()); + $processors->add(new SaleLimitValidator()); + $processors->add(new DeliverySettingValidator($app['eccube.repository.delivery'])); + + return $processors; + }; + + $app['eccube.purchase.flow.cart.holder_processors'] = function ($app) { + $processors = new ArrayCollection(); + $processors->add(new PaymentProcessor($app)); + $processors->add(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); + $processors->add(new DeliveryFeeFreeProcessor($app)); + $processors->add(new PaymentTotalNegativeValidator()); + + return $processors; + }; + + // example + $app->extend('eccube.purchase.flow.cart.item_processors', function ($processors, $app) { + + $processors->add(new StockValidator()); + + return $processors; + }); + + $app['eccube.purchase.flow.cart'] = function ($app) { $flow = new PurchaseFlow(); - $flow->addItemProcessor(new DeletedProductValidator()); - $flow->addItemProcessor(new DisplayStatusValidator()); - $flow->addItemProcessor(new StockValidator()); - $flow->addItemProcessor(new SaleLimitValidator()); - $flow->addItemProcessor(new DeliverySettingValidator($app['eccube.repository.delivery'])); + $flow->setItemProcessors($app['eccube.purchase.flow.cart.item_processors']); + $flow->setItemHolderProcessors($app['eccube.purchase.flow.cart.holder_processors']); - $flow->addItemHolderProcessor(new PaymentProcessor($app)); - $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); - $flow->addItemHolderProcessor(new DeliveryFeeFreeProcessor($app)); - $flow->addItemHolderProcessor(new PaymentTotalNegativeValidator()); return $flow; }; From 06267a469e88bef9cc6b63b49abd095f30bc7897 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 14 Jul 2017 13:24:39 +0900 Subject: [PATCH 53/75] Fix typo --- src/Eccube/Service/PurchaseFlow/PurchaseFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 9f583e967f1..8414d418dc5 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -83,7 +83,7 @@ public function purchase(ItemHolderInterface $target, ItemHolderInterface $origi } } - public function addPurchaseProcessort(PurchaseProcessor $processor) + public function addPurchaseProcessor(PurchaseProcessor $processor) { $this->purchaseProcessors[] = $processor; } From e8faad2887459d76ad56b8dd5dff9916243b9690 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Fri, 14 Jul 2017 14:38:27 +0900 Subject: [PATCH 54/75] =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=81=8B=E3=82=89=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=82=B5?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/EmptyProcessor.php | 20 ++++++++++++++++ .../Processor/ValidatableEmptyProcessor.php | 23 ++++++++++++++++++ .../PurchaseProcessorsServiceProvider.php | 24 +++++++++++++++++++ app/Plugin/PurchaseProcessors/config.yml | 5 ++++ 4 files changed, 72 insertions(+) create mode 100644 app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php create mode 100644 app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php create mode 100644 app/Plugin/PurchaseProcessors/ServiceProvider/PurchaseProcessorsServiceProvider.php create mode 100644 app/Plugin/PurchaseProcessors/config.yml diff --git a/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php new file mode 100644 index 00000000000..76386b9e970 --- /dev/null +++ b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php @@ -0,0 +1,20 @@ +setQuantity(100); + } +} diff --git a/app/Plugin/PurchaseProcessors/ServiceProvider/PurchaseProcessorsServiceProvider.php b/app/Plugin/PurchaseProcessors/ServiceProvider/PurchaseProcessorsServiceProvider.php new file mode 100644 index 00000000000..d3ebd205540 --- /dev/null +++ b/app/Plugin/PurchaseProcessors/ServiceProvider/PurchaseProcessorsServiceProvider.php @@ -0,0 +1,24 @@ +extend( + 'eccube.purchase.flow.cart.item_processors', + function (ArrayCollection $processors, Container $app) { + $processors[] = new EmptyProcessor(); + $processors[] = new ValidatableEmptyProcessor(); + return $processors; + } + ); + } +} diff --git a/app/Plugin/PurchaseProcessors/config.yml b/app/Plugin/PurchaseProcessors/config.yml new file mode 100644 index 00000000000..bdf63eff5aa --- /dev/null +++ b/app/Plugin/PurchaseProcessors/config.yml @@ -0,0 +1,5 @@ +name: PurchaseFlowにProcessorを追加するサンプル +code: PurchaseProcessors +version: 1.0.0 +service: + - PurchaseProcessorsServiceProvider From e63805676a2bd622b46dbc07b3b84166f9553598 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 14 Jul 2017 15:38:48 +0900 Subject: [PATCH 55/75] =?UTF-8?q?=E5=8F=97=E6=B3=A8=E7=B7=A8=E9=9B=86?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=81=AE=E6=9B=B4=E6=96=B0=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=20PurchaseProcessor=20=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/Order/EditController.php | 43 +++++-------- .../AdminOrderRegisterPurchaseProcessor.php | 30 +++++++++ .../Processor/UpdateDatePurchaseProcessor.php | 64 +++++++++++++++++++ .../ServiceProvider/EccubeServiceProvider.php | 14 ++-- 4 files changed, 116 insertions(+), 35 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index 06ba2bb58cf..beaad6b8117 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -35,6 +35,7 @@ use Eccube\Form\Type\Admin\OrderType; use Eccube\Form\Type\Admin\SearchCustomerType; use Eccube\Form\Type\Admin\SearchProductType; +use Eccube\Service\PurchaseFlow\PurchageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Form\FormError; @@ -134,8 +135,16 @@ public function index(Application $app, Request $request, $id = null) // TODO 編集前のOrder情報が必要かもしれない // TODO 手数料, 値引きの集計は未実装 // $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); - if ('GET' === $request->getMethod()) { - $app['eccube.purchase.flow.order.get']->execute($TargetOrder); + $flowResult = $app['eccube.purchase.flow.order']->execute($TargetOrder); + if ($flowResult->hasWarning()) { + foreach ($flowResult->getWarning() as $warning) { + $app->addWarning($warning->getMessage(), 'admin'); + } + } + if ($flowResult->hasError()) { + foreach ($flowResult->getErrors() as $error) { + $app->addError($error->getMessage(), 'admin'); + } } // 登録ボタン押下 @@ -143,30 +152,12 @@ public function index(Application $app, Request $request, $id = null) case 'register': log_info('受注登録開始', array($TargetOrder->getId())); - // TODO 在庫の有無や販売制限数のチェックなども行う必要があるため、完了処理もcaluclatorのように抽象化できないか検討する. - if ($form->isValid()) { - $app['eccube.purchase.flow.order.post']->execute($TargetOrder); - // TODO hasError でチェックしたい - foreach ($TargetOrder->getErrors() as $error) { - $app->addError($error, 'admin'); - break 2; - } - - $BaseInfo = $app['eccube.repository.base_info']->get(); - - // TODO 後続にある会員情報の更新のように、完了処理もcaluclatorのように抽象化できないか検討する. - // 受注日/発送日/入金日の更新. - $this->updateDate($app, $TargetOrder, $OriginOrder); - - // 画面上で削除された明細をremove - foreach ($OriginalShipmentItems as $ShipmentItem) { - if (false === $TargetOrder->getShipmentItems()->contains($ShipmentItem)) { - $ShipmentItem->setOrder(null); - } - } - - foreach ($TargetOrder->getShipmentItems() as $ShipmentItem) { - $ShipmentItem->setOrder($TargetOrder); + if ($flowResult->hasError() === false && $form->isValid()) { + try { + $app['eccube.purchase.flow.order']->purchase($TargetOrder, $OriginOrder); + } catch (PurchageException $e) { + $app->addError($e->getMessage(), 'admin'); + break; } $app['orm.em']->persist($TargetOrder); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php new file mode 100644 index 00000000000..4e384661a97 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php @@ -0,0 +1,30 @@ +getItems() as $ShipmentItem) { + if (false === $target->getShipmentItems()->contains($ShipmentItem)) { + $ShipmentItem->setOrder(null); + } + } + + foreach ($target->getItems() as $ShipmentItem) { + $ShipmentItem->setOrder($target); + } + } +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php new file mode 100644 index 00000000000..75b78fa757b --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php @@ -0,0 +1,64 @@ +app = $app; + } + /** + * {@inheritdoc} + */ + public function process(ItemHolderInterface $TargetOrder, ItemHolderInterface $OriginOrder) + { + $dateTime = new \DateTime(); + + // 編集 + if ($TargetOrder->getId()) { + // 発送済 + if ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_deliv']) { + // 編集前と異なる場合のみ更新 + if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { + $TargetOrder->setCommitDate($dateTime); + // お届け先情報の発送日も更新する. + $Shippings = $TargetOrder->getShippings(); + foreach ($Shippings as $Shipping) { + $Shipping->setShippingCommitDate($dateTime); + } + } + // 入金済 + } elseif ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_pre_end']) { + // 編集前と異なる場合のみ更新 + if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { + $TargetOrder->setPaymentDate($dateTime); + } + } + // 新規 + } else { + // 発送済 + if ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_deliv']) { + $TargetOrder->setCommitDate($dateTime); + // お届け先情報の発送日も更新する. + $Shippings = $TargetOrder->getShippings(); + foreach ($Shippings as $Shipping) { + $Shipping->setShippingCommitDate($dateTime); + } + // 入金済 + } elseif ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_pre_end']) { + $TargetOrder->setPaymentDate($dateTime); + } + // 受注日時 + $TargetOrder->setOrderDate($dateTime); + } + } +} diff --git a/src/Eccube/ServiceProvider/EccubeServiceProvider.php b/src/Eccube/ServiceProvider/EccubeServiceProvider.php index 7e16f69b1db..b962a5d450e 100644 --- a/src/Eccube/ServiceProvider/EccubeServiceProvider.php +++ b/src/Eccube/ServiceProvider/EccubeServiceProvider.php @@ -27,6 +27,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Eccube\EventListener\TransactionListener; use Eccube\Service\OrderHelper; +use Eccube\Service\PurchaseFlow\Processor\AdminOrderRegisterPurchaseProcessor; use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; @@ -36,8 +37,8 @@ use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; use Eccube\Service\PurchaseFlow\Processor\SaleLimitValidator; -use Eccube\Service\PurchaseFlow\Processor\StockReduceProcessor; use Eccube\Service\PurchaseFlow\Processor\StockValidator; +use Eccube\Service\PurchaseFlow\Processor\UpdateDatePurchaseProcessor; use Eccube\Service\PurchaseFlow\PurchaseFlow; use Pimple\Container; use Pimple\ServiceProviderInterface; @@ -582,17 +583,12 @@ public function register(Container $app) return $flow; }; - $app['eccube.purchase.flow.order.get'] = function () use ($app) { - $flow = new PurchaseFlow(); - $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); - return $flow; - }; - - $app['eccube.purchase.flow.order.post'] = function () use ($app) { + $app['eccube.purchase.flow.order'] = function () use ($app) { $flow = new PurchaseFlow(); $flow->addItemProcessor(new StockValidator()); $flow->addItemHolderProcessor(new PaymentTotalLimitValidator($app['config']['max_total_fee'])); - $flow->addItemProcessor(new StockReduceProcessor($app)); // 参考実装 + $flow->addPurchaseProcessor(new UpdateDatePurchaseProcessor($app)); + $flow->addPurchaseProcessor(new AdminOrderRegisterPurchaseProcessor($app)); return $flow; }; } From a0ef6949e9931b0fb90aa82373e6dde9540b07f1 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 18 Jul 2017 13:28:38 +0900 Subject: [PATCH 56/75] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=B3?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/Order/EditController.php | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index beaad6b8117..30e8178d135 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -115,29 +115,11 @@ public function index(Application $app, Request $request, $id = null) ); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); - // FIXME 税額計算は CalculateService で処理する. ここはテストを通すための暫定処理 - // see EditControllerTest::testOrderProcessingWithTax - // $OrderDetails = $TargetOrder->getOrderDetails(); - // $taxtotal = 0; - // foreach ($OrderDetails as $OrderDetail) { - // $tax = $app['eccube.service.tax_rule'] - // ->calcTax($OrderDetail->getPrice(), $OrderDetail->getTaxRate(), $OrderDetail->getTaxRule()); - // $OrderDetail->setPriceIncTax($OrderDetail->getPrice() + $tax); - - // $taxtotal += $tax * $OrderDetail->getQuantity(); - // } - // $TargetOrder->setTax($taxtotal); - - // 入力情報にもとづいて再計算. - // TODO 購入フローのように、明細の自動生成をどこまで行うか検討する. 単純集計でよいような気がする - // 集計は,この1行でいけるはず - // プラグインで Strategy をセットしたりする - // TODO 編集前のOrder情報が必要かもしれない - // TODO 手数料, 値引きの集計は未実装 - // $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); + $flowResult = $app['eccube.purchase.flow.order']->execute($TargetOrder); if ($flowResult->hasWarning()) { foreach ($flowResult->getWarning() as $warning) { + // TODO Warning の場合の処理 $app->addWarning($warning->getMessage(), 'admin'); } } From 7d8dffcd0e3ff88aa778f566558d95d369351f8c Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 18 Jul 2017 14:57:36 +0900 Subject: [PATCH 57/75] =?UTF-8?q?=E7=94=BB=E9=9D=A2=E5=81=B4=E3=81=A7?= =?UTF-8?q?=E3=82=82=E3=82=BD=E3=83=BC=E3=83=88=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Entity/Order.php | 12 +++++++++++- src/Eccube/Form/Type/Admin/OrderType.php | 8 +++++++- src/Eccube/Resource/template/admin/Order/edit.twig | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index edb27e75934..6648e5c4ff6 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1565,7 +1565,7 @@ public function getShipmentItems() } /** - * Alias of getShipmentItems() + * Sorted to getShipmentItems() * * @return ItemCollection */ @@ -1574,6 +1574,16 @@ public function getItems() return (new ItemCollection($this->getShipmentItems()->toArray()))->sort(); } + /** + * Alias of removeItem() + * + * @return boolean + */ + public function removeItem(\Eccube\Entity\ShipmentItem $shipmentItem) + { + return $this->removeShipmentItem($shipmentItem); + } + /** * Get shippings. * diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index df30668a747..2e3a9a30a68 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -241,7 +241,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'entry_type' => ShipmentItemType::class, 'allow_add' => true, 'allow_delete' => true, - 'prototype' => true, + 'prototype' => true + )) + ->add('Items', CollectionType::class, array( + 'entry_type' => ShipmentItemType::class, + 'allow_add' => true, + 'allow_delete' => true, + 'prototype' => true )) ->add('OrderDetailsErrors', TextType::class, [ 'mapped' => false, diff --git a/src/Eccube/Resource/template/admin/Order/edit.twig b/src/Eccube/Resource/template/admin/Order/edit.twig index 75eb128792c..2aa27a8be9c 100644 --- a/src/Eccube/Resource/template/admin/Order/edit.twig +++ b/src/Eccube/Resource/template/admin/Order/edit.twig @@ -381,7 +381,7 @@ var setModeAndSubmit = function(mode, keyname, keyid) { {{ form_errors(form.OrderDetailsErrors) }} - {% for shipmentItemForm in form.ShipmentItems %} + {% for shipmentItemForm in form.Items %}
{{ form_widget(shipmentItemForm.Order) }} {{ form_widget(shipmentItemForm.Shipping) }} From 5a37a0d9b09c3c3c7d7ee28e890ffe240776092f Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Tue, 18 Jul 2017 15:50:17 +0900 Subject: [PATCH 58/75] =?UTF-8?q?Options=20=E3=81=A7=20Items=20=E3=82=92?= =?UTF-8?q?=E6=B8=A1=E3=81=99=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/Order/EditController.php | 6 +++++- src/Eccube/Entity/Order.php | 10 ---------- src/Eccube/Form/Type/Admin/OrderType.php | 16 +++------------- .../Resource/template/admin/Order/edit.twig | 2 +- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index 30e8178d135..56432e3659c 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -89,7 +89,11 @@ public function index(Application $app, Request $request, $id = null) } $builder = $app['form.factory'] - ->createBuilder(OrderType::class, $TargetOrder); + ->createBuilder(OrderType::class, $TargetOrder, + [ + 'SortedItems' => $TargetOrder->getItems() + ] + ); $event = new EventArgs( array( diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 6648e5c4ff6..02deb09dbc3 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1574,16 +1574,6 @@ public function getItems() return (new ItemCollection($this->getShipmentItems()->toArray()))->sort(); } - /** - * Alias of removeItem() - * - * @return boolean - */ - public function removeItem(\Eccube\Entity\ShipmentItem $shipmentItem) - { - return $this->removeShipmentItem($shipmentItem); - } - /** * Get shippings. * diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index 2e3a9a30a68..8a8b4294819 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -231,23 +231,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) new Assert\NotBlank(), ), )) - // ->add('OrderDetails', CollectionType::class, array( - // 'entry_type' => OrderDetailType::class, - // 'allow_add' => true, - // 'allow_delete' => true, - // 'prototype' => true, - // )) ->add('ShipmentItems', CollectionType::class, array( 'entry_type' => ShipmentItemType::class, 'allow_add' => true, 'allow_delete' => true, - 'prototype' => true - )) - ->add('Items', CollectionType::class, array( - 'entry_type' => ShipmentItemType::class, - 'allow_add' => true, - 'allow_delete' => true, - 'prototype' => true + 'prototype' => true, + 'data' => $options['SortedItems'] )) ->add('OrderDetailsErrors', TextType::class, [ 'mapped' => false, @@ -368,6 +357,7 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setDefaults(array( 'data_class' => 'Eccube\Entity\Order', 'orign_order' => null, + 'SortedItems' => null )); } diff --git a/src/Eccube/Resource/template/admin/Order/edit.twig b/src/Eccube/Resource/template/admin/Order/edit.twig index 2aa27a8be9c..75eb128792c 100644 --- a/src/Eccube/Resource/template/admin/Order/edit.twig +++ b/src/Eccube/Resource/template/admin/Order/edit.twig @@ -381,7 +381,7 @@ var setModeAndSubmit = function(mode, keyname, keyid) { {{ form_errors(form.OrderDetailsErrors) }} - {% for shipmentItemForm in form.Items %} + {% for shipmentItemForm in form.ShipmentItems %}
{{ form_widget(shipmentItemForm.Order) }} {{ form_widget(shipmentItemForm.Shipping) }} From 4fcef7ba00aec5b97cccd664a732967b58de255b Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 18 Jul 2017 17:38:18 +0900 Subject: [PATCH 59/75] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CartService.php | 2 +- .../Eccube/Tests/Service/CartServiceTest.php | 351 ++---------------- .../Processor/DeletedProductValidatorTest.php | 2 +- .../Tests/Service/ShoppingServiceTest.php | 5 +- .../AbstractShoppingControllerTestCase.php | 12 +- tests/Eccube/Tests/Web/CartControllerTest.php | 13 - .../Tests/Web/Mypage/MypageControllerTest.php | 2 + 7 files changed, 51 insertions(+), 336 deletions(-) diff --git a/src/Eccube/Service/CartService.php b/src/Eccube/Service/CartService.php index 9b5706b0b96..a8a5d6f2fa0 100644 --- a/src/Eccube/Service/CartService.php +++ b/src/Eccube/Service/CartService.php @@ -76,7 +76,7 @@ protected function loadItems() } } - public function addProduct($ProductClass, $quantity) + public function addProduct($ProductClass, $quantity = 1) { if (!$ProductClass instanceof ProductClass) { $ProductClassId = $ProductClass; diff --git a/tests/Eccube/Tests/Service/CartServiceTest.php b/tests/Eccube/Tests/Service/CartServiceTest.php index 81ffd75c6af..2759a3db316 100644 --- a/tests/Eccube/Tests/Service/CartServiceTest.php +++ b/tests/Eccube/Tests/Service/CartServiceTest.php @@ -108,87 +108,72 @@ public function testAddProducts_Quantity() $this->assertCount(0, $cartService->getCart()->getCartItems()); $cartService->addProduct(1); - $this->assertEquals(1, $cartService->getProductQuantity(1)); + $quantity = $cartService->getCart()->getItems()->reduce(function($q, $item) { + $q += $item->getQuantity(); + return $q; + }); + $this->assertEquals(1, $quantity); $cartService->clear(); $cartService->addProduct(10, 6); - $this->assertEquals(5, $cartService->getProductQuantity(10)); + $quantity = $cartService->getCart()->getItems()->reduce(function($q, $item) { + $q += $item->getQuantity(); + return $q; + }); + // 明細の丸め処理はpurchaseFlowで実行されるため、販売制限数を超えてもカートには入る + $this->assertEquals(6, $quantity); $cartService->clear(); $cartService->addProduct(10, 101); - $this->assertEquals(5, $cartService->getProductQuantity(10)); + $cartService->addProduct(10, 6); + $quantity = $cartService->getCart()->getItems()->reduce(function($q, $item) { + $q += $item->getQuantity(); + return $q; + }); + // 明細の丸め処理はpurchaseFlowで実行されるため、販売制限数を超えてもカートには入る + $this->assertEquals(107, $quantity); } public function testUpProductQuantity() { $cartService = $this->app['eccube.service.cart']; - $cartService->setProductQuantity(1, 1); - $cartService->upProductQuantity(1); - - $quantity = $cartService->getProductQuantity(1); + $cartService->clear(); + $cartService->addProduct(10, 1); + $cartService->addProduct(10, 1); + $quantity = $cartService->getCart()->getItems()->reduce(function($q, $item) { + $q += $item->getQuantity(); + return $q; + }); $this->assertEquals(2, $quantity); } public function testDownProductQuantity() { $cartService = $this->app['eccube.service.cart']; + $cartService->clear(); + $cartService->addProduct(10, 2); + $cartService->addProduct(10, -1); - $cartService->setProductQuantity(1, 2); - $cartService->downProductQuantity(1); - - $quantity = $cartService->getProductQuantity(1); - - $this->assertEquals(1, $quantity); - } - - public function testDownProductQuantity_NotRemove() - { - $cartService = $this->app['eccube.service.cart']; - - $cartService->setProductQuantity(1, 1); - $cartService->downProductQuantity(1); - - $quantity = $cartService->getProductQuantity(1); + $quantity = $cartService->getCart()->getItems()->reduce(function($q, $item) { + $q += $item->getQuantity(); + return $q; + }); $this->assertEquals(1, $quantity); - $this->assertCount(1, $cartService->getCart()->getCartItems()); } public function testRemoveProduct() { $cartService = $this->app['eccube.service.cart']; - $cartService->setProductQuantity(1, 2); + $cartService->addProduct(1, 2); $cartService->removeProduct(1); $this->assertCount(0, $cartService->getCart()->getCartItems()); } - public function testGetErrors() - { - $cartService = $this->app['eccube.service.cart']; - - $this->assertCount(0, $cartService->getErrors()); - - $cartService->addError('foo'); - $cartService->addError('bar'); - - $this->assertCount(2, $cartService->getErrors()); - } - - public function testGetMessages() - { - $cartService = $this->app['eccube.service.cart']; - $this->assertCount(0, $cartService->getMessages()); - - $cartService->setMessage('foo'); - $cartService->setMessage('bar'); - - $this->assertCount(2, $cartService->getMessages()); - } - public function testSave() { $cartService = $this->app['eccube.service.cart']; @@ -201,274 +186,4 @@ public function testSave() $this->actual = $this->app['session']->get('cart')->getPreOrderId(); $this->verify(); } - - public function testAddProductType() - { - $cartService = $this->app['eccube.service.cart']; - $cartService->setCanAddProductType($this->ProductType1); - - $this->expected = $this->ProductType1; - $this->actual = $cartService->getCanAddProductType(); - $this->verify(); - } - - public function testSetProductQuantityWithId() - { - $ProductClasses = $this->Product->getProductClasses(); - - $this->app['eccube.service.cart']->setProductQuantity($ProductClasses[0]->getId(), 1) - ->save(); - - $Cart = $this->app['session']->get('cart'); - $CartItems = $Cart->getCartItems(); - - $this->expected = 1; - $this->actual = count($CartItems); - $this->verify(); - } - - public function testSetProductQuantityWithObject() - { - $ProductClasses = $this->Product->getProductClasses(); - $ProductClass = $ProductClasses[0]; - $this->app['eccube.service.cart']->setProductQuantity($ProductClass, 1) - ->save(); - $Cart = $this->app['session']->get('cart'); - $CartItems = $Cart->getCartItems(); - - $this->expected = 1; - $this->actual = count($CartItems); - $this->verify(); - } - - public function testSetProductQuantityWithProductNotFound() - { - try { - $this->app['eccube.service.cart']->setProductQuantity(999999, 1) - ->save(); - $this->fail(); - } catch (CartException $e) { - $this->expected = 'cart.product.delete'; - $this->actual = $e->getMessage(); - } - $this->verify(); - } - - public function testSetProductQuantityWithProductHide() - { - $Disp = $this->app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_HIDE); - $this->Product->setStatus($Disp); - $this->app['orm.em']->flush(); - - try { - $ProductClasses = $this->Product->getProductClasses(); - $ProductClass = $ProductClasses[0]; - $this->app['eccube.service.cart']->setProductQuantity($ProductClass, 1) - ->save(); - $this->fail(); - } catch (CartException $e) { - $this->expected = 'cart.product.not.status'; - $this->actual = $e->getMessage(); - } - $this->verify(); - } - - public function testSetProductQuantityWithOverPrice() - { - $ProductClasses = $this->Product->getProductClasses(); - $ProductClass = $ProductClasses[0]; - $ProductClass->setPrice02($this->app['config']['max_total_fee']); - $this->app['orm.em']->flush(); - - try { - $this->app['eccube.service.cart']->setProductQuantity($ProductClass, 2)->save(); - } catch (CartException $e) { - $this->actual = $this->app['eccube.service.cart']->getError(); - $this->expected = 'cart.over.price_limit'; - } - - $this->verify(); - } - - public function testSetProductQuantityWithOverStock() - { - $ProductClasses = $this->Product->getProductClasses(); - $ProductClass = $ProductClasses[0]; - $ProductClass->setStockUnlimited(0); - $ProductClass->setStock(10); - $this->app['orm.em']->flush(); - - $this->app['eccube.service.cart']->setProductQuantity($ProductClass, 20)->save(); - - $this->actual = $this->app['eccube.service.cart']->getErrors(); - $this->expected = array('cart.over.stock'); - $this->verify(); - } - - public function testSetProductQuantityWithOverSaleLimit() - { - $ProductClasses = $this->Product->getProductClasses(); - $ProductClass = $ProductClasses[0]; - $ProductClass->setStockUnlimited(0); - $ProductClass->setStock(10); - $ProductClass->setSaleLimit(5); - $this->app['orm.em']->flush(); - - $this->app['eccube.service.cart']->setProductQuantity($ProductClass, 7)->save(); - - $this->actual = $this->app['eccube.service.cart']->getErrors(); - $this->expected = array('cart.over.sale_limit'); - $this->verify(); - } - - public function testCanAddProductPaymentWithCartEmpty() - { - - $this->actual = $this->app['eccube.service.cart']->canAddProductPayment($this->ProductType1); - $this->assertTrue($this->actual, 'カートが空の場合は true'); - - $this->expected = 4; - $this->actual = count($this->app['eccube.service.cart']->getCart()->getPayments()); - $this->verify('設定されている支払い方法は'.$this->expected.'種類'); - } - - public function testSetProductQuantityWithMultipleProductType() - { - // カート投入 - $ProductClasses1 = $this->Product->getProductClasses(); - $ProductClasses2 = $this->Product2->getProductClasses(); - - try { - $this->app['eccube.service.cart'] - ->addProduct($ProductClasses1[0]->getId(), 1) - ->save(); - $this->app['eccube.service.cart'] - ->addProduct($ProductClasses2[0]->getId(), 1) - ->save(); - $this->fail(); - } catch (CartException $e) { - $this->actual = $e->getMessage(); - } - $this->expected = 'cart.product.type.kind'; - $this->verify('複数配送OFFの場合は複数商品種別のカート投入はエラー'); - } - - public function testSetProductQuantityWithMultipleShipping() - { - $this->markTestIncomplete('multiple shipping is not implemented.'); - // 複数配送対応としておく - $BaseInfo = $this->app['eccube.repository.base_info']->get(); - $BaseInfo->setOptionMultipleShipping(Constant::ENABLED); - - // product_class_id = 2 の ProductType を 2 に変更 - $ProductClass = $this->app['orm.em'] - ->getRepository('Eccube\Entity\ProductClass') - ->find(2); - $ProductClass->setProductType($this->ProductType2); - - // ProductType 1 と 2 で, 共通する支払い方法を削除しておく - $PaymentOption = $this - ->app['orm.em'] - ->getRepository('\Eccube\Entity\PaymentOption') - ->findOneBy( - array( - 'delivery_id' => 1, - 'payment_id' => 3 - ) - ); - $this->assertNotNull($PaymentOption); - $this->app['orm.em']->remove($PaymentOption); - $this->app['orm.em']->flush(); - - // カート投入 - try { - // XXX createProduct() で生成した商品を使いたいが, - // createProduct() で生成すると CartService::getCart()->getCartItem() で - // 商品が取得できないため, 初期設定商品を使用する - $this->app['eccube.service.cart']->setProductQuantity(1, 1); - $this->app['eccube.service.cart']->setProductQuantity(2, 1); - $this->fail(); - } catch (CartException $e) { - $this->actual = $e->getMessage(); - } - $this->expected = 'cart.product.payment.kind'; - $this->verify('複数配送ONの場合は支払い方法の異なるカート投入はエラー'); - } - - - public function testCanAddProductPaymentWithMultiple() - { - // 複数配送対応としておく - $BaseInfo = $this->app['eccube.repository.base_info']->get(); - $BaseInfo->setOptionMultipleShipping(Constant::ENABLED); - - // カート投入 - // XXX createProduct() で生成した商品を使いたいが, - // createProduct() で生成すると CartService::getCart()->getCartItem() で - // 商品が取得できないため, 初期設定商品を使用する - $this->app['eccube.service.cart']->setProductQuantity(1, 1); - $this->app['eccube.service.cart']->setProductQuantity(2, 1); - - $ProductType1 = $this->app['eccube.repository.master.product_type']->find(1); - $this->actual = $this->app['eccube.service.cart']->canAddProductPayment($ProductType1); - $this->assertTrue($this->actual, '共通の支払い方法が存在するため true'); - } - - public function testRemoveProductWithMultiple() - { - // 複数配送対応としておく - $BaseInfo = $this->app['eccube.repository.base_info']->get(); - $BaseInfo->setOptionMultipleShipping(Constant::ENABLED); - - // product_class_id = 2 の ProductType を 2 に変更 - $ProductClass = $this->app['orm.em'] - ->getRepository('Eccube\Entity\ProductClass') - ->find(2); - $ProductClass->setProductType($this->ProductType2); - - // カート投入 - // XXX createProduct() で生成した商品を使いたいが, - // createProduct() で生成すると CartService::getCart()->getCartItem() で - // 商品が取得できないため, 初期設定商品を使用する - $this->app['eccube.service.cart']->setProductQuantity(1, 1); - $this->app['eccube.service.cart']->setProductQuantity(2, 1); - - $this->expected = 1; - $this->actual = count($this->app['eccube.service.cart']->getCart()->getPayments()); - $this->verify('設定されている支払い方法は'.$this->expected.'種類'); - - // ProductType2 の商品を削除すると支払い方法が再設定される - $this->app['eccube.service.cart']->removeProduct(2); - - $this->expected = 4; - $this->actual = count($this->app['eccube.service.cart']->getCart()->getPayments()); - $this->verify('設定されている支払い方法は'.$this->expected.'種類'); - } - - public function testGetProductTypetWithMultiple() - { - // 複数配送対応としておく - $BaseInfo = $this->app['eccube.repository.base_info']->get(); - $BaseInfo->setOptionMultipleShipping(Constant::ENABLED); - - // product_class_id = 2 の ProductType を 2 に変更 - $ProductClass = $this->app['orm.em'] - ->getRepository('Eccube\Entity\ProductClass') - ->find(2); - $ProductClass->setProductType($this->ProductType2); - - // カート投入 - // XXX createProduct() で生成した商品を使いたいが, - // createProduct() で生成すると CartService::getCart()->getCartItem() で - // 商品が取得できないため, 初期設定商品を使用する - $this->app['eccube.service.cart']->setProductQuantity(1, 1); - $this->app['eccube.service.cart']->setProductQuantity(2, 1); - $this->app['eccube.service.cart']->setProductQuantity(3, 1); - - $ProductTypes = $this->app['eccube.service.cart']->getProductTypes(); - - $this->expected = 2; - $this->actual = count($ProductTypes); - $this->verify(); - } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php index e451c6ab77c..927e27fa6dd 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php @@ -66,6 +66,6 @@ public function testDisplayStatusWithClosed() $result = $this->validator->process($this->cartItem); self::assertEquals(0, $this->cartItem->getQuantity()); - self::assertTrue($result->isError()); + self::assertTrue($result->isWarning()); } } diff --git a/tests/Eccube/Tests/Service/ShoppingServiceTest.php b/tests/Eccube/Tests/Service/ShoppingServiceTest.php index dd40ca22d4d..d15f8cf29e8 100644 --- a/tests/Eccube/Tests/Service/ShoppingServiceTest.php +++ b/tests/Eccube/Tests/Service/ShoppingServiceTest.php @@ -27,8 +27,9 @@ public function setUp() ) ); $this->CartService = $this->app['eccube.service.cart']; - $this->CartService->setProductQuantity(1, 1) - ->save(); + $this->CartService->clear(); + $this->CartService->addProduct(1, 1); + $this->CartService->save(); $this->ProductType1 = $this->app['eccube.repository.master.product_type']->find(1); $this->ProductType2 = $this->app['eccube.repository.master.product_type']->find(2); diff --git a/tests/Eccube/Tests/Web/AbstractShoppingControllerTestCase.php b/tests/Eccube/Tests/Web/AbstractShoppingControllerTestCase.php index df8d3cfe448..ae8a9efbdb2 100644 --- a/tests/Eccube/Tests/Web/AbstractShoppingControllerTestCase.php +++ b/tests/Eccube/Tests/Web/AbstractShoppingControllerTestCase.php @@ -61,8 +61,18 @@ public function createShippingFormData() protected function scenarioCartIn($client, $product_class_id = 1) { - $crawler = $client->request('POST', '/cart/add', array('product_class_id' => $product_class_id)); + $crawler = $client->request( + 'PUT', + $this->app->path( + 'cart_handle_item', + [ + 'operation' => 'up', + 'productClassId' => $product_class_id, + ] + ) + ); $this->app['eccube.service.cart']->lock(); + return $crawler; } diff --git a/tests/Eccube/Tests/Web/CartControllerTest.php b/tests/Eccube/Tests/Web/CartControllerTest.php index d17a1af092a..80cbfcb3af1 100644 --- a/tests/Eccube/Tests/Web/CartControllerTest.php +++ b/tests/Eccube/Tests/Web/CartControllerTest.php @@ -33,13 +33,6 @@ public function testRoutingCart() $this->assertTrue($this->client->getResponse()->isSuccessful()); } - public function testRoutingCartAdd() - { - $this->client->request('POST', '/cart/add', array('product_class_id' => 1)); - - $this->assertTrue($this->client->getResponse()->isRedirection()); - } - public function testRoutingCartUp() { $this->client->request('PUT', '/cart/up/1'); @@ -52,12 +45,6 @@ public function testRoutingCartDown() $this->assertTrue($this->client->getResponse()->isRedirection()); } - public function testRoutingCartSetQuantity() - { - $this->client->request('PUT', '/cart/setQuantity/2/1'); - $this->assertTrue($this->client->getResponse()->isRedirection()); - } - public function testRoutingCartRemove() { $this->client->request('PUT', '/cart/remove/1'); diff --git a/tests/Eccube/Tests/Web/Mypage/MypageControllerTest.php b/tests/Eccube/Tests/Web/Mypage/MypageControllerTest.php index de361fb93f8..d16277939d3 100644 --- a/tests/Eccube/Tests/Web/Mypage/MypageControllerTest.php +++ b/tests/Eccube/Tests/Web/Mypage/MypageControllerTest.php @@ -64,6 +64,8 @@ public function testRoutingFavoriteDelete() public function testRoutingOrder() { + self::markTestIncomplete('purchaseFlowに対応後、テストを作成'); + $this->logIn(); $client = $this->client; From f6c2d5d0fc4d938e8cb4ddad135e8ecd08f1ecf9 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Tue, 18 Jul 2017 18:09:54 +0900 Subject: [PATCH 60/75] =?UTF-8?q?Processor=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseFlow/Processor/DisplayStatusValidator.php | 3 +++ .../Service/PurchaseFlow/Processor/SaleLimitValidator.php | 5 +++++ src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php index 84b502b1850..04de747e4f0 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php @@ -11,6 +11,9 @@ class DisplayStatusValidator extends ValidatableItemProcessor { protected function validate(ItemInterface $item) { + if (!$item->isProduct()) { + return; + } $ProductClass = $item->getProductClass(); if (!$ProductClass->isEnable()) { throw new ItemValidateException('cart.product.not.status'); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 87f9fbb02f7..274c49e7fdf 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -16,7 +16,12 @@ protected function validate(ItemInterface $item) if (!$item->isProduct()) { return; } + $limit = $item->getProductClass()->getSaleLimit(); + if (is_null($limit)) { + return; + } + $quantity = $item->getQuantity(); if ($limit < $quantity) { throw new ItemValidateException('cart.over.sale_limit', ['%product%' => $item->getProductClass()->getProduct()->getName()]); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 0ba2cf6bdaf..2c3da7c17a8 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -16,6 +16,9 @@ protected function validate(ItemInterface $item) if (!$item->isProduct()) { return; } + if ($item->getProductClass()->getStockUnlimited()) { + return; + } $stock = $item->getProductClass()->getStock(); $quantity = $item->getQuantity(); if ($stock == 0) { From e7203a5f227c16c23576294250ac1d222c0daf37 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Wed, 19 Jul 2017 10:01:59 +0900 Subject: [PATCH 61/75] =?UTF-8?q?=E5=9E=8B=E5=AE=A3=E8=A8=80=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/PurchaseFlow/ItemValidateException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php index d9ef9622297..ef39538841e 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php +++ b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php @@ -38,7 +38,7 @@ function __construct($message = null, $messageArgs = []) /** * @return array */ - public function getMessageArgs(): array + public function getMessageArgs() { return $this->messageArgs; } From a5bedca44d02ce768edd841ae6eea9ff0588ad46 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Wed, 19 Jul 2017 16:26:21 +0900 Subject: [PATCH 62/75] =?UTF-8?q?PurchaseContext=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/CartController.php | 4 ++- .../PurchaseFlow/ItemHolderProcessor.php | 4 ++- .../Service/PurchaseFlow/ItemProcessor.php | 5 ++- .../PurchaseFlow/Processor/Context.php | 36 +++++++++++++++++++ .../Service/PurchaseFlow/PurchaseFlow.php | 13 +++---- .../PurchaseFlow/PurchaseProcessor.php | 5 +-- 6 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/Eccube/Service/PurchaseFlow/Processor/Context.php diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 6729a25f780..345be51bcc5 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -28,6 +28,7 @@ use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -153,7 +154,8 @@ public function handleCartItem(Application $app, Request $request, $operation, $ // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); /** @var PurchaseFlowResult $result */ - $result = $app['eccube.purchase.flow.cart']->execute($Cart); + + $result = $app['eccube.purchase.flow.cart']->execute($Cart, PurchaseContext::create($app)); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ if ($result->hasError()) { diff --git a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php index cdac6590996..d6f38c06769 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php @@ -4,12 +4,14 @@ use Eccube\Entity\ItemHolderInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; interface ItemHolderProcessor { /** * @param ItemHolderInterface $itemHolder + * @param PurchaseContext $context * @return ProcessResult */ - public function process(ItemHolderInterface $itemHolder); + public function process(ItemHolderInterface $itemHolder, PurchaseContext $context); } \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php index 8f6737e719b..e089765e5a7 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php @@ -4,12 +4,15 @@ use Eccube\Entity\ItemInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; interface ItemProcessor { /** * @param ItemInterface $item + * @param PurchaseContext $context * @return ProcessResult */ - public function process(ItemInterface $item); + public function process(ItemInterface $item, PurchaseContext $context); + } \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/Processor/Context.php b/src/Eccube/Service/PurchaseFlow/Processor/Context.php new file mode 100644 index 00000000000..e7be1e34eb1 --- /dev/null +++ b/src/Eccube/Service/PurchaseFlow/Processor/Context.php @@ -0,0 +1,36 @@ +user(), $originHolder); + } + + protected function __construct(Customer $user, ItemHolderInterface $originHolder = null) + { + $this->user = $user; + $this->originHolder = $originHolder; + } + + public function getOriginHolder() + { + return $this->originHolder; + } + + public function getUser() + { + return $this->user; + } +} \ No newline at end of file diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 8414d418dc5..ebef4170cf6 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -5,6 +5,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ItemInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; class PurchaseFlow { @@ -45,7 +46,7 @@ public function setPurchaseProcessors(ArrayCollection $processors) $this->purchaseProcessors = $processors; } - public function execute(ItemHolderInterface $itemHolder) + public function calculate(ItemHolderInterface $itemHolder, PurchaseContext $context) { $this->calculateDeliveryFeeTotal($itemHolder); $this->calculateCharge($itemHolder); @@ -58,13 +59,13 @@ public function execute(ItemHolderInterface $itemHolder) foreach ($itemHolder->getItems() as $item) { foreach ($this->itemProcessors as $itemProsessor) { - $result = $itemProsessor->process($item); + $result = $itemProsessor->process($item, $context); $flowResult->addProcessResult($result); } } foreach ($this->itemHolderProcessors as $holderProcessor) { - $result = $holderProcessor->process($itemHolder); + $result = $holderProcessor->process($itemHolder, $context); $flowResult->addProcessResult($result); } @@ -73,13 +74,13 @@ public function execute(ItemHolderInterface $itemHolder) /** * @param ItemHolderInterface $target - * @param ItemHolderInterface $origin + * @param PurchaseContext $context * @throws PurchaseException */ - public function purchase(ItemHolderInterface $target, ItemHolderInterface $origin) + public function purchase(ItemHolderInterface $target, PurchaseContext $context) { foreach ($this->purchaseProcessors as $processor) { - $processor->process($target, $origin); + $processor->process($target, $context); } } diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php index 27c7c89e635..6b657ad3178 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php @@ -4,13 +4,14 @@ use Eccube\Entity\ItemHolderInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; interface PurchaseProcessor { /** * @param ItemHolderInterface $target - * @param ItemHolderInterface $origin + * @param PurchaseContext $context * @throws PurchaseException */ - public function process(ItemHolderInterface $target, ItemHolderInterface $origin); + public function process(ItemHolderInterface $target, PurchaseContext $context); } \ No newline at end of file From fc994f9c10a528baf45f8f1700e38fe38919f4ad Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 19 Jul 2017 16:46:52 +0900 Subject: [PATCH 63/75] =?UTF-8?q?PurchaseContext=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=97=E3=81=9F=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=95=E3=82=A7=E3=82=A4=E3=82=B9=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminOrderRegisterPurchaseProcessor.php | 5 ++--- .../Processor/DeliveryFeeFreeProcessor.php | 3 ++- .../Processor/DeliveryFeeProcessor.php | 3 ++- .../Processor/PaymentProcessor.php | 2 -- .../{Context.php => PurchaseContext.php} | 2 +- .../Processor/StockReduceProcessor.php | 15 ++++++--------- .../Processor/UpdateDatePurchaseProcessor.php | 4 ++-- .../ValidatableItemHolderProcessor.php | 8 +++++++- .../PurchaseFlow/ValidatableItemProcessor.php | 6 ++++-- .../Processor/DeletedProductValidatorTest.php | 5 +++-- .../Processor/DeliveryFeeFreeProcessorTest.php | 7 ++++--- .../Service/PurchaseFlow/PurchaseFlowTest.php | 18 +++++++++--------- 12 files changed, 42 insertions(+), 36 deletions(-) rename src/Eccube/Service/PurchaseFlow/Processor/{Context.php => PurchaseContext.php} (86%) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php index 4e384661a97..0d3ae03dd07 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php @@ -3,7 +3,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; use Eccube\Entity\ItemHolderInterface; -use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\PurchaseProcessor; /** @@ -14,10 +13,10 @@ class AdminOrderRegisterPurchaseProcessor implements PurchaseProcessor /** * {@inheritdoc} */ - public function process(ItemHolderInterface $target, ItemHolderInterface $origin) + public function process(ItemHolderInterface $target, PurchaseContext $context) { // 画面上で削除された明細をremove - foreach ($origin->getItems() as $ShipmentItem) { + foreach ($context->getOriginHolder()->getItems() as $ShipmentItem) { if (false === $target->getShipmentItems()->contains($ShipmentItem)) { $ShipmentItem->setOrder(null); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php index 13f4044cb1e..de708d65a86 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php @@ -50,9 +50,10 @@ public function __construct(Application $app) /** * @param ItemHolderInterface $itemHolder + * @param PurchaseContext $context * @return ProcessResult */ - public function process(ItemHolderInterface $itemHolder) + public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { /* @var $BaseInfo \Eccube\Entity\BaseInfo */ $BaseInfo = $this->app['eccube.repository.base_info']->get(); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php index bc33ddb81aa..0f3a46d8e38 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -53,9 +53,10 @@ public function __construct($app) /** * @param ItemHolderInterface $itemHolder + * @param PurchaseContext $context * @return ProcessResult */ - public function process(ItemHolderInterface $itemHolder) + public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { if ($this->containsDeliveryFeeItem($itemHolder) == false) { $this->addDeliveryFeeItem($itemHolder); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index b66009bbb72..217887f8ec9 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -26,11 +26,9 @@ use Doctrine\Common\Collections\ArrayCollection; use Eccube\Application; -use Eccube\Entity\Cart; use Eccube\Entity\Delivery; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\Master\ProductType; -use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; diff --git a/src/Eccube/Service/PurchaseFlow/Processor/Context.php b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php similarity index 86% rename from src/Eccube/Service/PurchaseFlow/Processor/Context.php rename to src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php index e7be1e34eb1..0e112519acc 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/Context.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php @@ -18,7 +18,7 @@ public static function create(Application $app, ItemHolderInterface $originHolde return new self($app->user(), $originHolder); } - protected function __construct(Customer $user, ItemHolderInterface $originHolder = null) + protected function __construct(Customer $user = null, ItemHolderInterface $originHolder = null) { $this->user = $user; $this->originHolder = $originHolder; diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php index 14671d20852..e2dfb8c2276 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php @@ -2,17 +2,12 @@ namespace Eccube\Service\PurchaseFlow\Processor; +use Doctrine\DBAL\LockMode; use Eccube\Common\Constant; use Eccube\Entity\ItemInterface; -use Eccube\Entity\Master\OrderItemType; -use Eccube\Entity\Master\TaxDisplayType; -use Eccube\Entity\Master\TaxType; -use Eccube\Entity\Order; use Eccube\Entity\ShipmentItem; -use Eccube\Entity\Shipping; use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\ProcessResult; -use Doctrine\DBAL\LockMode; /** * 在庫制御. @@ -32,12 +27,14 @@ public function __construct($app) } /** - * @param ItemHolderInterface $itemHolder + * @param ItemInterface $item + * @param PurchaseContext $context * @return ProcessResult + * @internal param ItemHolderInterface $itemHolder */ - public function process(ItemInterface $item) + public function process(ItemInterface $item, PurchaseContext $context) { - if (!$item instanceof \Eccube\Entity\ShipmentItem) { + if (!$item instanceof ShipmentItem) { // ShipmentItem 以外の場合は何もしない return ProcessResult::success(); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php index 75b78fa757b..cc79476709e 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php @@ -3,7 +3,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; use Eccube\Entity\ItemHolderInterface; -use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\PurchaseProcessor; /** @@ -19,9 +18,10 @@ public function __construct($app) /** * {@inheritdoc} */ - public function process(ItemHolderInterface $TargetOrder, ItemHolderInterface $OriginOrder) + public function process(ItemHolderInterface $TargetOrder, PurchaseContext $context) { $dateTime = new \DateTime(); + $OriginOrder = $context->getOriginHolder(); // 編集 if ($TargetOrder->getId()) { diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php index daf0ab1f9db..b2bf4feae2c 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php @@ -3,10 +3,16 @@ namespace Eccube\Service\PurchaseFlow; use Eccube\Entity\ItemHolderInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; abstract class ValidatableItemHolderProcessor implements ItemHolderProcessor { - public final function process(ItemHolderInterface $itemHolder) + /** + * @param ItemHolderInterface $itemHolder + * @param PurchaseContext $context + * @return ProcessResult + */ + public final function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { try { $this->validate($itemHolder); diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index ea5f216baf6..c8cdf874368 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -26,14 +26,16 @@ use Eccube\Entity\CartItem; use Eccube\Entity\ItemInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; abstract class ValidatableItemProcessor implements ItemProcessor { /** * @param ItemInterface $item - * @throws ItemValidateException + * @param PurchaseContext $context + * @return ProcessResult */ - public function process(ItemInterface $item) + public function process(ItemInterface $item, PurchaseContext $context) { try { $this->validate($item); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php index 927e27fa6dd..0375fe79aa6 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php @@ -7,6 +7,7 @@ use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class DeletedProductValidatorTest extends EccubeTestCase @@ -52,7 +53,7 @@ public function testInstance() */ public function testProductIsValid() { - $result = $this->validator->process($this->cartItem); + $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -63,7 +64,7 @@ public function testProductIsValid() public function testDisplayStatusWithClosed() { $this->Product->setDelFlg(1); - $result = $this->validator->process($this->cartItem); + $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals(0, $this->cartItem->getQuantity()); self::assertTrue($result->isWarning()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php index e46db55a183..d52370cb896 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php @@ -27,6 +27,7 @@ use Eccube\Entity\BaseInfo; use Eccube\Entity\Order; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\ProcessResult; use Eccube\Tests\EccubeTestCase; @@ -60,7 +61,7 @@ public function testNewInstance() */ public function testProcess() { - $result = $this->processor->process($this->Order); + $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); @@ -79,7 +80,7 @@ public function testProcessWithAmount() $BaseInfo = $this->app['eccube.repository.base_info']->get(); $BaseInfo->setDeliveryFreeAmount(1); // 1円以上で送料無料 - $result = $this->processor->process($this->Order); + $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); @@ -98,7 +99,7 @@ public function testProcessWithQuantity() $BaseInfo = $this->app['eccube.repository.base_info']->get(); $BaseInfo->setDeliveryFreeQuantity(1); // 1個以上で送料無料 - $result = $this->processor->process($this->Order); + $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php index f0c45f34289..776bd4fd574 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php @@ -3,7 +3,6 @@ namespace Eccube\Tests\Service\PurchaseFlow; use Eccube\Entity\Cart; -use Eccube\Entity\CartItem; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\ItemInterface; use Eccube\Entity\Order; @@ -11,6 +10,7 @@ use Eccube\Service\PurchaseFlow\ItemHolderProcessor; use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\ItemValidateException; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\ProcessResult; use Eccube\Service\PurchaseFlow\PurchaseFlow; use Eccube\Service\PurchaseFlow\PurchaseFlowResult; @@ -42,7 +42,7 @@ public function testExecute() $itemHolder = new Cart(); $expected = new PurchaseFlowResult($itemHolder); - $this->assertEquals($expected, $this->flow->execute($itemHolder)); + $this->assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } public function testAddProcesser() @@ -60,7 +60,7 @@ public function testProcessItemProcessors() $itemHolder = new Cart(); $expected = new PurchaseFlowResult($itemHolder); - self::assertEquals($expected, $this->flow->execute($itemHolder)); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } public function testProcessItemHolderProcessor() @@ -70,7 +70,7 @@ public function testProcessItemHolderProcessor() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::success()); - self::assertEquals($expected, $this->flow->execute($itemHolder)); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } public function testProcessItemHolderProcessor_validationErrors() @@ -80,7 +80,7 @@ public function testProcessItemHolderProcessor_validationErrors() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::error('error 1')); - self::assertEquals($expected, $this->flow->execute($itemHolder)); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } public function testProcessItemProcessors_validationErrors() @@ -93,7 +93,7 @@ public function testProcessItemProcessors_validationErrors() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::warn('error 1')); $expected->addProcessResult(ProcessResult::warn('error 2')); - self::assertEquals($expected, $this->flow->execute($itemHolder)); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } public function testProcessItemProcessors_validationErrors_with_multi_items() @@ -109,14 +109,14 @@ public function testProcessItemProcessors_validationErrors_with_multi_items() $expected->addProcessResult(ProcessResult::warn('error 2')); $expected->addProcessResult(ProcessResult::warn('error 1')); $expected->addProcessResult(ProcessResult::warn('error 2')); - self::assertEquals($expected, $this->flow->execute($itemHolder)); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); } } class PurchaseFlowTest_ItemHolderProcessor implements ItemHolderProcessor { - public function process(ItemHolderInterface $itemHolder) + public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { return ProcessResult::success(); } @@ -125,7 +125,7 @@ public function process(ItemHolderInterface $itemHolder) class PurchaseFlowTest_ItemProcessor implements ItemProcessor { - public function process(ItemInterface $item) + public function process(ItemInterface $item, PurchaseContext $context) { return ProcessResult::success(); } From 9f9705de42ce77024fb52540d74cbc277d7c2bac Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Wed, 19 Jul 2017 17:02:07 +0900 Subject: [PATCH 64/75] =?UTF-8?q?FormExtension=E3=81=AE=E3=82=B5=E3=83=B3?= =?UTF-8?q?=E3=83=97=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Form/Extension/EntryTypeExtension.php | 39 +++++++++++++++++++ .../FormExtensionServiceProvider.php | 22 +++++++++++ app/Plugin/FormExtension/config.yml | 5 +++ 3 files changed, 66 insertions(+) create mode 100644 app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php create mode 100644 app/Plugin/FormExtension/ServiceProvider/FormExtensionServiceProvider.php create mode 100644 app/Plugin/FormExtension/config.yml diff --git a/app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php b/app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php new file mode 100644 index 00000000000..af3dd7db7f2 --- /dev/null +++ b/app/Plugin/FormExtension/Form/Extension/EntryTypeExtension.php @@ -0,0 +1,39 @@ +remove('job'); + $builder->add( + 'job', + JobType::class, + [ + 'required' => true, + 'constraints' => [ + new NotBlank(), + ], + ] + ); + } + + /** + * {@inheritdoc} + */ + public function getExtendedType() + { + return EntryType::class; + } +} diff --git a/app/Plugin/FormExtension/ServiceProvider/FormExtensionServiceProvider.php b/app/Plugin/FormExtension/ServiceProvider/FormExtensionServiceProvider.php new file mode 100644 index 00000000000..020a154fb0f --- /dev/null +++ b/app/Plugin/FormExtension/ServiceProvider/FormExtensionServiceProvider.php @@ -0,0 +1,22 @@ +extend( + 'form.type.extensions', + function ($extensions) { + $extensions[] = new EntryTypeExtension(); + + return $extensions; + } + ); + } +} diff --git a/app/Plugin/FormExtension/config.yml b/app/Plugin/FormExtension/config.yml new file mode 100644 index 00000000000..a0efd7a1877 --- /dev/null +++ b/app/Plugin/FormExtension/config.yml @@ -0,0 +1,5 @@ +name: FormExtensionのサンプル +code: FormExtension +version: 1.0.0 +service: + - FormExtensionServiceProvider From 5a8993130106640090f741703cf5b374f2da2a5b Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 19 Jul 2017 17:13:04 +0900 Subject: [PATCH 65/75] =?UTF-8?q?ValidatableItemProcessor=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=BF=E3=83=BC=E3=83=95=E3=82=A7=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=81=AEPurchaseContext=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Processor/DeletedProductValidator.php | 4 ++-- .../Processor/DeliverySettingValidator.php | 4 ++-- .../Processor/DisplayStatusValidator.php | 4 ++-- .../PurchaseFlow/Processor/PaymentProcessor.php | 2 +- .../Processor/PaymentTotalLimitValidator.php | 2 +- .../Processor/SaleLimitValidator.php | 2 +- .../PurchaseFlow/Processor/StockValidator.php | 4 ++-- .../ValidatableItemHolderProcessor.php | 4 ++-- .../PurchaseFlow/ValidatableItemProcessor.php | 8 ++++---- .../Processor/DeliveryFeeProcessorTest.php | 5 +++-- .../Processor/DeliverySettingValidatorTest.php | 5 +++-- .../Processor/DisplayStatusValidatorTest.php | 5 +++-- .../Processor/PaymentProcessorTest.php | 9 +++++---- .../PaymentTotalLimitValidatorTest.php | 9 +++++---- .../Processor/StockValidatorTest.php | 7 ++++--- .../Service/PurchaseFlow/PurchaseFlowTest.php | 4 ++-- .../ValidatableItemProcessorTest.php | 17 +++++++++-------- 17 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php index 6a5ec89284c..7824363894e 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php @@ -9,7 +9,7 @@ class DeletedProductValidator extends ValidatableItemProcessor { - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { $ProductClass = $item->getProductClass(); $Product = $ProductClass->getProduct(); @@ -18,7 +18,7 @@ protected function validate(ItemInterface $item) } } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { if ($item instanceof CartItem) { $item->setQuantity(0); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php index 0e69062e520..040e5e77ce8 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php @@ -22,7 +22,7 @@ public function __construct(DeliveryRepository $deliveryRepository) $this->deliveryRepository = $deliveryRepository; } - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { if (!$item->isProduct()) { return; @@ -36,7 +36,7 @@ protected function validate(ItemInterface $item) } } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { $item->setQuantity(0); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php index 04de747e4f0..7bbd176c803 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php @@ -9,7 +9,7 @@ class DisplayStatusValidator extends ValidatableItemProcessor { - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { if (!$item->isProduct()) { return; @@ -20,7 +20,7 @@ protected function validate(ItemInterface $item) } } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { if ($item instanceof CartItem) { $item->setQuantity(0); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index 217887f8ec9..b7535b6dedd 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -51,7 +51,7 @@ public function __construct(Application $app) $this->app = $app; } - protected function validate(ItemHolderInterface $itemHolder) + protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context) { // 明細の個数が1以下の場合はOK if (count($itemHolder->getItems()) <= 1) { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php index 77bf30f4935..1c3d16e07c2 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -47,7 +47,7 @@ public function __construct($maxTotalFee) $this->maxTotalFee = $maxTotalFee; } - protected function validate(ItemHolderInterface $item) + protected function validate(ItemHolderInterface $item, PurchaseContext $context) { $totalPrice = $item->getTotal(); if ($totalPrice > $this->maxTotalFee) { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 274c49e7fdf..7f8de4e373d 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -11,7 +11,7 @@ */ class SaleLimitValidator extends ValidatableItemProcessor { - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { if (!$item->isProduct()) { return; diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 2c3da7c17a8..2bbb97b51be 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -11,7 +11,7 @@ */ class StockValidator extends ValidatableItemProcessor { - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { if (!$item->isProduct()) { return; @@ -29,7 +29,7 @@ protected function validate(ItemInterface $item) } } - protected function handle(ItemInterface $item) { + protected function handle(ItemInterface $item, PurchaseContext $context) { $stock = $item->getProductClass()->getStock(); $item->setQuantity($stock); } diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php index b2bf4feae2c..ecb2b8d56a7 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php @@ -15,7 +15,7 @@ abstract class ValidatableItemHolderProcessor implements ItemHolderProcessor public final function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { try { - $this->validate($itemHolder); + $this->validate($itemHolder, $context); return ProcessResult::success(); } catch (ItemValidateException $e) { @@ -23,7 +23,7 @@ public final function process(ItemHolderInterface $itemHolder, PurchaseContext $ } } - protected abstract function validate(ItemHolderInterface $itemHolder); + protected abstract function validate(ItemHolderInterface $itemHolder, PurchaseContext $context); protected function handle(ItemHolderInterface $itemHolder) {} } diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index c8cdf874368..5cc9ad713da 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -38,21 +38,21 @@ abstract class ValidatableItemProcessor implements ItemProcessor public function process(ItemInterface $item, PurchaseContext $context) { try { - $this->validate($item); + $this->validate($item, $context); return ProcessResult::success(); } catch (ItemValidateException $e) { if ($item instanceof CartItem) { - $this->handle($item); + $this->handle($item, $context); } return ProcessResult::warn($e->getMessage(), $e->getMessageArgs()); } } - protected abstract function validate(ItemInterface $item); + protected abstract function validate(ItemInterface $item, PurchaseContext $context); - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php index d32aa0327c1..531018c58d1 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php @@ -28,6 +28,7 @@ use Eccube\Entity\Order; use Eccube\Entity\ShipmentItem; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeProcessor; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class DeliveryFeeProcessorTest extends EccubeTestCase @@ -44,7 +45,7 @@ public function testProcess() $Order->getShipmentItems()->removeElement($ShipmentItem); } } - $processor->process($Order); + $processor->process($Order, PurchaseContext::create($this->app)); self::assertNotEmpty($this->getDeliveryFees($Order)); } @@ -70,7 +71,7 @@ public function testProcessWithDeliveryFee() $DeliveryFee->setOrderItemType($OrderItemType); $Order->addItem($DeliveryFee); - $processor->process($Order); + $processor->process($Order, PurchaseContext::create($this->app)); $DeliveryFeeList = $this->getDeliveryFees($Order); self::assertCount(1, $DeliveryFeeList); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php index 48b10267e48..3d1131efd6f 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php @@ -7,6 +7,7 @@ use Eccube\Entity\Product; use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class DeliverySettingValidatorTest extends EccubeTestCase @@ -52,7 +53,7 @@ public function testInstance() */ public function testDeliverySettingIsValid() { - $result = $this->validator->process($this->cartItem); + $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -66,7 +67,7 @@ public function testDisplayStatusWithClosed() $ProductType->setId(10000); $this->ProductClass->setProductType($ProductType); - $this->validator->process($this->cartItem); + $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals(0, $this->cartItem->getQuantity()); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php index 37cbf776805..ebad989d6e6 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php @@ -8,6 +8,7 @@ use Eccube\Entity\Product; use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\Processor\DisplayStatusValidator; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class DisplayStatusValidatorTest extends EccubeTestCase @@ -59,7 +60,7 @@ public function testDisplayStatusWithShow() $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_SHOW); $this->Product->setStatus($Disp); - $this->validator->process($this->cartItem); + $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals(10, $this->cartItem->getQuantity()); } @@ -74,7 +75,7 @@ public function testDisplayStatusWithClosed() $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_HIDE); $this->Product->setStatus($Disp); - $this->validator->process($this->cartItem); + $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals(0, $this->cartItem->getQuantity()); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php index 0dc225ef610..c8b4a83bb9f 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php @@ -11,6 +11,7 @@ use Eccube\Entity\Product; use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\Processor\PaymentProcessor; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class PaymentProcessorTest extends EccubeTestCase @@ -101,7 +102,7 @@ public function testInstance() public function testCartNoItems() { $cart = new Cart(); - $result = $this->validator->process($cart); + $result = $this->validator->process($cart, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -113,7 +114,7 @@ public function testCartOneItem() $item->setObject($this->ProductClass1); $cart->addItem($item); - $result = $this->validator->process($cart); + $result = $this->validator->process($cart, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -129,7 +130,7 @@ public function testCartValidItems() $item2->setObject($this->ProductClass2); $cart->addItem($item2); - $result = $this->validator->process($cart); + $result = $this->validator->process($cart, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -155,7 +156,7 @@ public function testCartInValidItems() $item3->setObject($this->ProductClass3); $cart->addItem($item3); - $result = $this->validator->process($cart); + $result = $this->validator->process($cart, PurchaseContext::create($this->app)); self::assertTrue($result->isError()); self::assertCount(3, $cart->getItems()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php index 0983aef689f..25bc07f3437 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php @@ -26,6 +26,7 @@ use Eccube\Entity\Cart; use Eccube\Entity\Order; use Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Tests\EccubeTestCase; class PaymentTotalLimitValidatorTest extends EccubeTestCase @@ -37,7 +38,7 @@ public function testCartValidate() $cart = new Cart(); $cart->setTotal(100); - $result = $validator->process($cart); + $result = $validator->process($cart, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -48,7 +49,7 @@ public function testCartValidateFail() $cart = new Cart(); $cart->setTotal(1001); - $result = $validator->process($cart); + $result = $validator->process($cart, PurchaseContext::create($this->app)); self::assertTrue($result->isError()); } @@ -59,7 +60,7 @@ public function testOrderValidate() $order = new Order(); $order->setTotal(100); - $result = $validator->process($order); + $result = $validator->process($order, PurchaseContext::create($this->app)); self::assertFalse($result->isError()); } @@ -70,7 +71,7 @@ public function testOrderValidateFail() $order = new Order(); $order->setTotal(1001); - $result = $validator->process($order); + $result = $validator->process($order, PurchaseContext::create($this->app)); self::assertTrue($result->isError()); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php index 7ced34da641..08184f97da9 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php @@ -3,6 +3,7 @@ namespace Eccube\Tests\Service; use Eccube\Entity\CartItem; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\Processor\StockValidator; use Eccube\Tests\EccubeTestCase; @@ -36,14 +37,14 @@ public function testInstance() public function testValidStock() { $this->cartItem->setQuantity(1); - $this->validator->process($this->cartItem); + $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals(1, $this->cartItem->getQuantity()); } public function testValidStockFail() { $this->cartItem->setQuantity(PHP_INT_MAX); - $result = $this->validator->process($this->cartItem); + $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); self::assertTrue($result->isWarning()); @@ -59,7 +60,7 @@ public function testValidStockOrder() $Order->getShipmentItems()[0]->setQuantity(1); $this->ProductClass->setStock(100); - $this->validator->process($Order->getShipmentItems()[0]); + $this->validator->process($Order->getShipmentItems()[0], PurchaseContext::create($this->app)); self::assertEquals(1, $Order->getShipmentItems()[0]->getQuantity()); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php index 776bd4fd574..f27c7c59cd9 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php @@ -144,7 +144,7 @@ public function __construct($errorMessage) $this->errorMessage = $errorMessage; } - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { throw new ItemValidateException($this->errorMessage); } @@ -163,7 +163,7 @@ public function __construct($errorMessage) $this->errorMessage = $errorMessage; } - protected function validate(ItemHolderInterface $item) + protected function validate(ItemHolderInterface $item, PurchaseContext $context) { // TODO ItemHolerValidateException が必要か検討 throw new ItemValidateException($this->errorMessage); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php index 1503794c1d7..93696296dc2 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php @@ -27,6 +27,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Entity\ShipmentItem; use Eccube\Service\PurchaseFlow\ItemValidateException; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; use Eccube\Tests\EccubeTestCase; @@ -46,7 +47,7 @@ public function testValidateCartSuccess() $validator = new ValidatableItemProcessorTest_NormalValidator(); $item = new CartItem(); - $validator->process($item); + $validator->process($item, PurchaseContext::create($this->app)); $this->assertFalse($validator->handleCalled); } @@ -55,7 +56,7 @@ public function testValidateCartFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new CartItem(); - $validator->process($item); + $validator->process($item, PurchaseContext::create($this->app)); } public function testValidateOrderSuccess() @@ -63,7 +64,7 @@ public function testValidateOrderSuccess() $validator = new ValidatableItemProcessorTest_NormalValidator(); $item = new ShipmentItem(); - $result = $validator->process($item); + $result = $validator->process($item, PurchaseContext::create($this->app)); self::assertFalse($validator->handleCalled); self::assertFalse($result->isError()); } @@ -73,7 +74,7 @@ public function testValidateOrderFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new ShipmentItem(); - $result = $validator->process($item); + $result = $validator->process($item, PurchaseContext::create($this->app)); self::assertFalse($validator->handleCalled); self::assertTrue($result->isWarning()); } @@ -84,11 +85,11 @@ class ValidatableItemProcessorTest_NormalValidator extends ValidatableItemProces public $handleCalled = false; - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { $this->handleCalled = true; } @@ -99,12 +100,12 @@ class ValidatableItemProcessorTest_FailValidator extends ValidatableItemProcesso public $handleCalled = false; - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { throw new ItemValidateException(); } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { $this->handleCalled = true; } From dc0a8c9ef085e0a85b3dc896b1f18b0d3849b007 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 19 Jul 2017 17:35:58 +0900 Subject: [PATCH 66/75] =?UTF-8?q?Controller=E3=81=8B=E3=82=89=E3=81=AE?= =?UTF-8?q?=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/AbstractShoppingController.php | 3 ++- src/Eccube/Controller/Admin/Order/EditController.php | 9 +++++---- src/Eccube/Controller/CartController.php | 4 ++-- src/Eccube/Controller/ProductController.php | 4 +++- .../Processor/PaymentTotalNegativeValidator.php | 2 +- .../Service/PurchaseFlow/Processor/PurchaseContext.php | 7 ++++++- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Eccube/Controller/AbstractShoppingController.php b/src/Eccube/Controller/AbstractShoppingController.php index bb372fc53ba..051b9d1b6a4 100644 --- a/src/Eccube/Controller/AbstractShoppingController.php +++ b/src/Eccube/Controller/AbstractShoppingController.php @@ -26,6 +26,7 @@ use Eccube\Application; use Eccube\Entity\ItemHolderInterface; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchaseFlowResult; class AbstractShoppingController extends AbstractController @@ -59,7 +60,7 @@ class AbstractShoppingController extends AbstractController protected function executePurchaseFlow(Application $app, ItemHolderInterface $itemHolder) { /** @var PurchaseFlowResult $flowResult */ - $flowResult = $app['eccube.purchase.flow.shopping']->execute($itemHolder); + $flowResult = $app['eccube.purchase.flow.shopping']->calculate($itemHolder, PurchaseContext::create($app)); foreach ($flowResult->getWarning() as $warning) { $app->addRequestError($warning->getMessage()); } diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index 56432e3659c..edb258bc396 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -28,17 +28,16 @@ use Eccube\Common\Constant; use Eccube\Controller\AbstractController; use Eccube\Entity\Master\DeviceType; -use Eccube\Entity\ShipmentItem; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Form\Type\AddCartType; use Eccube\Form\Type\Admin\OrderType; use Eccube\Form\Type\Admin\SearchCustomerType; use Eccube\Form\Type\Admin\SearchProductType; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; -use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -107,6 +106,7 @@ public function index(Application $app, Request $request, $id = null) $form = $builder->getForm(); $form->handleRequest($request); + $purchaseContext = PurchaseContext::create($app, $OriginOrder); if ($form->isSubmitted()) { $event = new EventArgs( @@ -114,13 +114,14 @@ public function index(Application $app, Request $request, $id = null) 'builder' => $builder, 'OriginOrder' => $OriginOrder, 'TargetOrder' => $TargetOrder, + 'PurchaseContext' => $purchaseContext, ), $request ); $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); - $flowResult = $app['eccube.purchase.flow.order']->execute($TargetOrder); + $flowResult = $app['eccube.purchase.flow.order']->calculate($TargetOrder, $purchaseContext); if ($flowResult->hasWarning()) { foreach ($flowResult->getWarning() as $warning) { // TODO Warning の場合の処理 @@ -140,7 +141,7 @@ public function index(Application $app, Request $request, $id = null) if ($flowResult->hasError() === false && $form->isValid()) { try { - $app['eccube.purchase.flow.order']->purchase($TargetOrder, $OriginOrder); + $app['eccube.purchase.flow.order']->purchase($TargetOrder, $purchaseContext); } catch (PurchageException $e) { $app->addError($e->getMessage(), 'admin'); break; diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 345be51bcc5..6a8caefbecb 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -62,7 +62,7 @@ public function index(Application $app, Request $request) // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); /** @var PurchaseFlowResult $result */ - $result = $app['eccube.purchase.flow.cart']->execute($Cart); + $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create($app)); // 復旧不可のエラーが発生した場合はカートをクリアして再描画 if ($result->hasError()) { @@ -155,7 +155,7 @@ public function handleCartItem(Application $app, Request $request, $operation, $ $Cart = $app['eccube.service.cart']->getCart(); /** @var PurchaseFlowResult $result */ - $result = $app['eccube.purchase.flow.cart']->execute($Cart, PurchaseContext::create($app)); + $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create($app)); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ if ($result->hasError()) { diff --git a/src/Eccube/Controller/ProductController.php b/src/Eccube/Controller/ProductController.php index 648e9b32b29..71432bdd24a 100644 --- a/src/Eccube/Controller/ProductController.php +++ b/src/Eccube/Controller/ProductController.php @@ -34,6 +34,7 @@ use Eccube\Form\Type\Master\ProductListMaxType; use Eccube\Form\Type\Master\ProductListOrderByType; use Eccube\Form\Type\SearchProductType; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -279,7 +280,8 @@ public function detail(Application $app, Request $request, $id) $app['eccube.service.cart']->addProduct($addCartData['product_class_id'], $addCartData['quantity']); // 明細の正規化 - $result = $app['eccube.purchase.flow.cart']->execute($Cart); + $flow = $app['eccube.purchase.flow.cart']; + $result = $flow->calculate($Cart, PurchaseContext::create($app)); // 復旧不可のエラーが発生した場合は追加した明細を削除. if ($result->hasError()) { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php index c59cacd87a8..0ae6f2794cf 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php @@ -33,7 +33,7 @@ */ class PaymentTotalNegativeValidator extends ValidatableItemHolderProcessor { - protected function validate(ItemHolderInterface $item) + protected function validate(ItemHolderInterface $item, PurchaseContext $context) { if ($item->getTotal() < 0) { throw new ItemValidateException('shopping.total.price'); diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php index 0e112519acc..7987a1fc6c8 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php @@ -15,7 +15,12 @@ class PurchaseContext extends \SplObjectStorage public static function create(Application $app, ItemHolderInterface $originHolder = null) { - return new self($app->user(), $originHolder); + $user = $app->user(); + if ($user instanceof Customer) { + return new self($app->user(), $originHolder); + } else { + return new self(null, $originHolder); + } } protected function __construct(Customer $user = null, ItemHolderInterface $originHolder = null) From 6802a285658605c56becc0310e8d30f070832dd7 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 19 Jul 2017 17:59:15 +0900 Subject: [PATCH 67/75] =?UTF-8?q?=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php | 4 +++- .../Processor/ValidatableEmptyProcessor.php | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php index 76386b9e970..567681e06d4 100644 --- a/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php +++ b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php @@ -4,15 +4,17 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemProcessor; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\ProcessResult; class EmptyProcessor implements ItemProcessor { /** * @param ItemInterface $item + * @param PurchaseContext $context * @return ProcessResult */ - public function process(ItemInterface $item) + public function process(ItemInterface $item, PurchaseContext $context) { log_info('empty processor executed', [__METHOD__]); return ProcessResult::success(); diff --git a/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php b/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php index da2af4e3086..6cccbb312bb 100644 --- a/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php +++ b/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php @@ -4,11 +4,12 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; +use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; class ValidatableEmptyProcessor extends ValidatableItemProcessor { - protected function validate(ItemInterface $item) + protected function validate(ItemInterface $item, PurchaseContext $context) { $error = false; if ($error) { @@ -16,7 +17,7 @@ protected function validate(ItemInterface $item) } } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { $item->setQuantity(100); } From c0ed634ea1c6ab35388693eeec7239f5e80d4e49 Mon Sep 17 00:00:00 2001 From: kiy0taka Date: Wed, 19 Jul 2017 18:19:18 +0900 Subject: [PATCH 68/75] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=95=E3=82=A7=E3=82=A4=E3=82=B9=E4=BF=AE=E6=AD=A3=E6=BC=8F?= =?UTF-8?q?=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/Processor/SaleLimitValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 7f8de4e373d..8699549fbd5 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -28,7 +28,7 @@ protected function validate(ItemInterface $item, PurchaseContext $context) } } - protected function handle(ItemInterface $item) + protected function handle(ItemInterface $item, PurchaseContext $context) { $limit = $item->getProductClass()->getSaleLimit(); $item->setQuantity($limit); From 4deb6ab7a8f0c994d349cdc6aa50169a88f9f2d5 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 20 Jul 2017 13:02:35 +0900 Subject: [PATCH 69/75] Remove toArray --- src/Eccube/Entity/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index 02deb09dbc3..401ff02a868 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1571,7 +1571,7 @@ public function getShipmentItems() */ public function getItems() { - return (new ItemCollection($this->getShipmentItems()->toArray()))->sort(); + return (new ItemCollection($this->getShipmentItems()))->sort(); } /** From 808dab02e2f73d0655bdfcc725a249dfecaf412e Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 20 Jul 2017 14:22:21 +0900 Subject: [PATCH 70/75] =?UTF-8?q?Customer=E3=81=8C=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=81=AE=E3=81=AF=E3=82=AB=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E3=81=AE=E3=81=9F=E3=82=81=E3=80=81PurchaseContext?= =?UTF-8?q?=E3=81=AE=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=BC=E3=83=95=E3=82=A7?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/AbstractShoppingController.php | 2 +- src/Eccube/Controller/Admin/Order/EditController.php | 2 +- src/Eccube/Controller/CartController.php | 4 ++-- src/Eccube/Controller/ProductController.php | 2 +- .../PurchaseFlow/Processor/PurchaseContext.php | 12 +++--------- .../Processor/DeletedProductValidatorTest.php | 4 ++-- .../Processor/DeliveryFeeFreeProcessorTest.php | 6 +++--- .../Processor/DeliveryFeeProcessorTest.php | 4 ++-- .../Processor/DeliverySettingValidatorTest.php | 4 ++-- .../Processor/DisplayStatusValidatorTest.php | 4 ++-- .../PurchaseFlow/Processor/PaymentProcessorTest.php | 8 ++++---- .../Processor/PaymentTotalLimitValidatorTest.php | 8 ++++---- .../PurchaseFlow/Processor/StockValidatorTest.php | 6 +++--- .../Tests/Service/PurchaseFlow/PurchaseFlowTest.php | 12 ++++++------ .../PurchaseFlow/ValidatableItemProcessorTest.php | 8 ++++---- 15 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/Eccube/Controller/AbstractShoppingController.php b/src/Eccube/Controller/AbstractShoppingController.php index 051b9d1b6a4..c7dbf353c26 100644 --- a/src/Eccube/Controller/AbstractShoppingController.php +++ b/src/Eccube/Controller/AbstractShoppingController.php @@ -60,7 +60,7 @@ class AbstractShoppingController extends AbstractController protected function executePurchaseFlow(Application $app, ItemHolderInterface $itemHolder) { /** @var PurchaseFlowResult $flowResult */ - $flowResult = $app['eccube.purchase.flow.shopping']->calculate($itemHolder, PurchaseContext::create($app)); + $flowResult = $app['eccube.purchase.flow.shopping']->calculate($itemHolder, PurchaseContext::create()); foreach ($flowResult->getWarning() as $warning) { $app->addRequestError($warning->getMessage()); } diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index edb258bc396..440333517e4 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -106,7 +106,7 @@ public function index(Application $app, Request $request, $id = null) $form = $builder->getForm(); $form->handleRequest($request); - $purchaseContext = PurchaseContext::create($app, $OriginOrder); + $purchaseContext = PurchaseContext::create($OriginOrder); if ($form->isSubmitted()) { $event = new EventArgs( diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 6a8caefbecb..28114ab37fd 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -62,7 +62,7 @@ public function index(Application $app, Request $request) // カートを取得して明細の正規化を実行 $Cart = $app['eccube.service.cart']->getCart(); /** @var PurchaseFlowResult $result */ - $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create($app)); + $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create()); // 復旧不可のエラーが発生した場合はカートをクリアして再描画 if ($result->hasError()) { @@ -155,7 +155,7 @@ public function handleCartItem(Application $app, Request $request, $operation, $ $Cart = $app['eccube.service.cart']->getCart(); /** @var PurchaseFlowResult $result */ - $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create($app)); + $result = $app['eccube.purchase.flow.cart']->calculate($Cart, PurchaseContext::create()); // 復旧不可のエラーが発生した場合はカートをクリアしてカート一覧へ if ($result->hasError()) { diff --git a/src/Eccube/Controller/ProductController.php b/src/Eccube/Controller/ProductController.php index 71432bdd24a..7ed4c5cbd74 100644 --- a/src/Eccube/Controller/ProductController.php +++ b/src/Eccube/Controller/ProductController.php @@ -281,7 +281,7 @@ public function detail(Application $app, Request $request, $id) // 明細の正規化 $flow = $app['eccube.purchase.flow.cart']; - $result = $flow->calculate($Cart, PurchaseContext::create($app)); + $result = $flow->calculate($Cart, PurchaseContext::create()); // 復旧不可のエラーが発生した場合は追加した明細を削除. if ($result->hasError()) { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php index 7987a1fc6c8..592e25931f3 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php @@ -13,19 +13,13 @@ class PurchaseContext extends \SplObjectStorage private $originHolder; - public static function create(Application $app, ItemHolderInterface $originHolder = null) + public static function create(ItemHolderInterface $originHolder = null) { - $user = $app->user(); - if ($user instanceof Customer) { - return new self($app->user(), $originHolder); - } else { - return new self(null, $originHolder); - } + return new self($originHolder); } - protected function __construct(Customer $user = null, ItemHolderInterface $originHolder = null) + protected function __construct(ItemHolderInterface $originHolder = null) { - $this->user = $user; $this->originHolder = $originHolder; } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php index 0375fe79aa6..50dff6f557f 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php @@ -53,7 +53,7 @@ public function testInstance() */ public function testProductIsValid() { - $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $result = $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -64,7 +64,7 @@ public function testProductIsValid() public function testDisplayStatusWithClosed() { $this->Product->setDelFlg(1); - $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $result = $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals(0, $this->cartItem->getQuantity()); self::assertTrue($result->isWarning()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php index d52370cb896..2c2432a6666 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php @@ -61,7 +61,7 @@ public function testNewInstance() */ public function testProcess() { - $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); + $result = $this->processor->process($this->Order, PurchaseContext::create()); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); @@ -80,7 +80,7 @@ public function testProcessWithAmount() $BaseInfo = $this->app['eccube.repository.base_info']->get(); $BaseInfo->setDeliveryFreeAmount(1); // 1円以上で送料無料 - $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); + $result = $this->processor->process($this->Order, PurchaseContext::create()); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); @@ -99,7 +99,7 @@ public function testProcessWithQuantity() $BaseInfo = $this->app['eccube.repository.base_info']->get(); $BaseInfo->setDeliveryFreeQuantity(1); // 1個以上で送料無料 - $result = $this->processor->process($this->Order, PurchaseContext::create($this->app)); + $result = $this->processor->process($this->Order, PurchaseContext::create()); self::assertInstanceOf(ProcessResult::class, $result); self::assertFalse($result->isError()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php index 531018c58d1..b45974224a1 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php @@ -45,7 +45,7 @@ public function testProcess() $Order->getShipmentItems()->removeElement($ShipmentItem); } } - $processor->process($Order, PurchaseContext::create($this->app)); + $processor->process($Order, PurchaseContext::create()); self::assertNotEmpty($this->getDeliveryFees($Order)); } @@ -71,7 +71,7 @@ public function testProcessWithDeliveryFee() $DeliveryFee->setOrderItemType($OrderItemType); $Order->addItem($DeliveryFee); - $processor->process($Order, PurchaseContext::create($this->app)); + $processor->process($Order, PurchaseContext::create()); $DeliveryFeeList = $this->getDeliveryFees($Order); self::assertCount(1, $DeliveryFeeList); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php index 3d1131efd6f..9b2d3fa999b 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php @@ -53,7 +53,7 @@ public function testInstance() */ public function testDeliverySettingIsValid() { - $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $result = $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -67,7 +67,7 @@ public function testDisplayStatusWithClosed() $ProductType->setId(10000); $this->ProductClass->setProductType($ProductType); - $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals(0, $this->cartItem->getQuantity()); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php index ebad989d6e6..3438fbe1471 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php @@ -60,7 +60,7 @@ public function testDisplayStatusWithShow() $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_SHOW); $this->Product->setStatus($Disp); - $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals(10, $this->cartItem->getQuantity()); } @@ -75,7 +75,7 @@ public function testDisplayStatusWithClosed() $Disp = $app['eccube.repository.master.disp']->find(Disp::DISPLAY_HIDE); $this->Product->setStatus($Disp); - $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals(0, $this->cartItem->getQuantity()); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php index c8b4a83bb9f..682e890f52f 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentProcessorTest.php @@ -102,7 +102,7 @@ public function testInstance() public function testCartNoItems() { $cart = new Cart(); - $result = $this->validator->process($cart, PurchaseContext::create($this->app)); + $result = $this->validator->process($cart, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -114,7 +114,7 @@ public function testCartOneItem() $item->setObject($this->ProductClass1); $cart->addItem($item); - $result = $this->validator->process($cart, PurchaseContext::create($this->app)); + $result = $this->validator->process($cart, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -130,7 +130,7 @@ public function testCartValidItems() $item2->setObject($this->ProductClass2); $cart->addItem($item2); - $result = $this->validator->process($cart, PurchaseContext::create($this->app)); + $result = $this->validator->process($cart, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -156,7 +156,7 @@ public function testCartInValidItems() $item3->setObject($this->ProductClass3); $cart->addItem($item3); - $result = $this->validator->process($cart, PurchaseContext::create($this->app)); + $result = $this->validator->process($cart, PurchaseContext::create()); self::assertTrue($result->isError()); self::assertCount(3, $cart->getItems()); diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php index 25bc07f3437..103c694d52d 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php @@ -38,7 +38,7 @@ public function testCartValidate() $cart = new Cart(); $cart->setTotal(100); - $result = $validator->process($cart, PurchaseContext::create($this->app)); + $result = $validator->process($cart, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -49,7 +49,7 @@ public function testCartValidateFail() $cart = new Cart(); $cart->setTotal(1001); - $result = $validator->process($cart, PurchaseContext::create($this->app)); + $result = $validator->process($cart, PurchaseContext::create()); self::assertTrue($result->isError()); } @@ -60,7 +60,7 @@ public function testOrderValidate() $order = new Order(); $order->setTotal(100); - $result = $validator->process($order, PurchaseContext::create($this->app)); + $result = $validator->process($order, PurchaseContext::create()); self::assertFalse($result->isError()); } @@ -71,7 +71,7 @@ public function testOrderValidateFail() $order = new Order(); $order->setTotal(1001); - $result = $validator->process($order, PurchaseContext::create($this->app)); + $result = $validator->process($order, PurchaseContext::create()); self::assertTrue($result->isError()); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php index 08184f97da9..11496b7127a 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php @@ -37,14 +37,14 @@ public function testInstance() public function testValidStock() { $this->cartItem->setQuantity(1); - $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals(1, $this->cartItem->getQuantity()); } public function testValidStockFail() { $this->cartItem->setQuantity(PHP_INT_MAX); - $result = $this->validator->process($this->cartItem, PurchaseContext::create($this->app)); + $result = $this->validator->process($this->cartItem, PurchaseContext::create()); self::assertEquals($this->ProductClass->getStock(), $this->cartItem->getQuantity()); self::assertTrue($result->isWarning()); @@ -60,7 +60,7 @@ public function testValidStockOrder() $Order->getShipmentItems()[0]->setQuantity(1); $this->ProductClass->setStock(100); - $this->validator->process($Order->getShipmentItems()[0], PurchaseContext::create($this->app)); + $this->validator->process($Order->getShipmentItems()[0], PurchaseContext::create()); self::assertEquals(1, $Order->getShipmentItems()[0]->getQuantity()); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php index f27c7c59cd9..612e4fbf042 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php @@ -42,7 +42,7 @@ public function testExecute() $itemHolder = new Cart(); $expected = new PurchaseFlowResult($itemHolder); - $this->assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + $this->assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } public function testAddProcesser() @@ -60,7 +60,7 @@ public function testProcessItemProcessors() $itemHolder = new Cart(); $expected = new PurchaseFlowResult($itemHolder); - self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } public function testProcessItemHolderProcessor() @@ -70,7 +70,7 @@ public function testProcessItemHolderProcessor() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::success()); - self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } public function testProcessItemHolderProcessor_validationErrors() @@ -80,7 +80,7 @@ public function testProcessItemHolderProcessor_validationErrors() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::error('error 1')); - self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } public function testProcessItemProcessors_validationErrors() @@ -93,7 +93,7 @@ public function testProcessItemProcessors_validationErrors() $expected = new PurchaseFlowResult($itemHolder); $expected->addProcessResult(ProcessResult::warn('error 1')); $expected->addProcessResult(ProcessResult::warn('error 2')); - self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } public function testProcessItemProcessors_validationErrors_with_multi_items() @@ -109,7 +109,7 @@ public function testProcessItemProcessors_validationErrors_with_multi_items() $expected->addProcessResult(ProcessResult::warn('error 2')); $expected->addProcessResult(ProcessResult::warn('error 1')); $expected->addProcessResult(ProcessResult::warn('error 2')); - self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create($this->app))); + self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php index 93696296dc2..d65c8123945 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php @@ -47,7 +47,7 @@ public function testValidateCartSuccess() $validator = new ValidatableItemProcessorTest_NormalValidator(); $item = new CartItem(); - $validator->process($item, PurchaseContext::create($this->app)); + $validator->process($item, PurchaseContext::create()); $this->assertFalse($validator->handleCalled); } @@ -56,7 +56,7 @@ public function testValidateCartFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new CartItem(); - $validator->process($item, PurchaseContext::create($this->app)); + $validator->process($item, PurchaseContext::create()); } public function testValidateOrderSuccess() @@ -64,7 +64,7 @@ public function testValidateOrderSuccess() $validator = new ValidatableItemProcessorTest_NormalValidator(); $item = new ShipmentItem(); - $result = $validator->process($item, PurchaseContext::create($this->app)); + $result = $validator->process($item, PurchaseContext::create()); self::assertFalse($validator->handleCalled); self::assertFalse($result->isError()); } @@ -74,7 +74,7 @@ public function testValidateOrderFail() $validator = new ValidatableItemProcessorTest_FailValidator(); $item = new ShipmentItem(); - $result = $validator->process($item, PurchaseContext::create($this->app)); + $result = $validator->process($item, PurchaseContext::create()); self::assertFalse($validator->handleCalled); self::assertTrue($result->isWarning()); } From d592868bf2421e968d8434b8cb9e85664f2a45eb Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 20 Jul 2017 14:41:46 +0900 Subject: [PATCH 71/75] =?UTF-8?q?PurchaseContext=E3=81=AE=E9=9A=8E?= =?UTF-8?q?=E5=B1=A4=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/PurchaseFlow/{Processor => }/PurchaseContext.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Eccube/Service/PurchaseFlow/{Processor => }/PurchaseContext.php (100%) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php b/src/Eccube/Service/PurchaseFlow/PurchaseContext.php similarity index 100% rename from src/Eccube/Service/PurchaseFlow/Processor/PurchaseContext.php rename to src/Eccube/Service/PurchaseFlow/PurchaseContext.php From 9b66a7f10769f42e01fa4ba40891392a2cda566f Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 20 Jul 2017 14:54:50 +0900 Subject: [PATCH 72/75] =?UTF-8?q?PurchaseFlow=E3=81=AEnamespace=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=AB=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/AbstractShoppingController.php | 2 +- src/Eccube/Controller/Admin/Order/EditController.php | 2 +- src/Eccube/Controller/CartController.php | 2 +- src/Eccube/Controller/ProductController.php | 2 +- src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php | 1 - src/Eccube/Service/PurchaseFlow/ItemProcessor.php | 1 - .../Processor/AdminOrderRegisterPurchaseProcessor.php | 1 + .../Service/PurchaseFlow/Processor/DeletedProductValidator.php | 1 + .../Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php | 1 + .../Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php | 1 + .../Service/PurchaseFlow/Processor/DeliverySettingValidator.php | 1 + .../Service/PurchaseFlow/Processor/DisplayStatusValidator.php | 1 + src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php | 1 + .../PurchaseFlow/Processor/PaymentTotalLimitValidator.php | 1 + .../PurchaseFlow/Processor/PaymentTotalNegativeValidator.php | 1 + .../Service/PurchaseFlow/Processor/SaleLimitValidator.php | 1 + .../Service/PurchaseFlow/Processor/StockReduceProcessor.php | 1 + src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php | 1 + .../PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php | 1 + src/Eccube/Service/PurchaseFlow/PurchaseContext.php | 2 +- src/Eccube/Service/PurchaseFlow/PurchaseFlow.php | 1 - src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php | 1 - .../Service/PurchaseFlow/ValidatableItemHolderProcessor.php | 1 - src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php | 1 - .../PurchaseFlow/Processor/DeletedProductValidatorTest.php | 2 +- .../PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php | 2 +- .../Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php | 2 +- .../PurchaseFlow/Processor/DeliverySettingValidatorTest.php | 2 +- .../PurchaseFlow/Processor/DisplayStatusValidatorTest.php | 2 +- .../Service/PurchaseFlow/Processor/PaymentProcessorTest.php | 2 +- .../PurchaseFlow/Processor/PaymentTotalLimitValidatorTest.php | 2 +- .../Tests/Service/PurchaseFlow/Processor/StockValidatorTest.php | 2 +- tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php | 2 +- .../Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php | 2 +- 34 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Eccube/Controller/AbstractShoppingController.php b/src/Eccube/Controller/AbstractShoppingController.php index c7dbf353c26..080f5f080ef 100644 --- a/src/Eccube/Controller/AbstractShoppingController.php +++ b/src/Eccube/Controller/AbstractShoppingController.php @@ -26,7 +26,7 @@ use Eccube\Application; use Eccube\Entity\ItemHolderInterface; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchaseFlowResult; class AbstractShoppingController extends AbstractController diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index 440333517e4..ba470da4002 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -34,7 +34,7 @@ use Eccube\Form\Type\Admin\OrderType; use Eccube\Form\Type\Admin\SearchCustomerType; use Eccube\Form\Type\Admin\SearchProductType; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchageException; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; diff --git a/src/Eccube/Controller/CartController.php b/src/Eccube/Controller/CartController.php index 28114ab37fd..47151350255 100644 --- a/src/Eccube/Controller/CartController.php +++ b/src/Eccube/Controller/CartController.php @@ -28,7 +28,7 @@ use Eccube\Entity\ProductClass; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Service\PurchaseFlow\PurchaseFlowResult; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; diff --git a/src/Eccube/Controller/ProductController.php b/src/Eccube/Controller/ProductController.php index 7ed4c5cbd74..ed70dc71e7d 100644 --- a/src/Eccube/Controller/ProductController.php +++ b/src/Eccube/Controller/ProductController.php @@ -34,7 +34,7 @@ use Eccube\Form\Type\Master\ProductListMaxType; use Eccube\Form\Type\Master\ProductListOrderByType; use Eccube\Form\Type\SearchProductType; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; diff --git a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php index d6f38c06769..655ff95afcc 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php @@ -4,7 +4,6 @@ use Eccube\Entity\ItemHolderInterface; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; interface ItemHolderProcessor { diff --git a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php index e089765e5a7..490154f2b35 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php @@ -4,7 +4,6 @@ use Eccube\Entity\ItemInterface; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; interface ItemProcessor { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php index 0d3ae03dd07..fbd2d857a5c 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php @@ -4,6 +4,7 @@ use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\PurchaseProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 管理画面/受注登録/編集画面の完了処理 diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php index 7824363894e..83cac01ed9a 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeletedProductValidator.php @@ -6,6 +6,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; class DeletedProductValidator extends ValidatableItemProcessor { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php index de708d65a86..49f3af3fef1 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php @@ -28,6 +28,7 @@ use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemHolderProcessor; use Eccube\Service\PurchaseFlow\ProcessResult; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 送料無料条件. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php index 0f3a46d8e38..e35edc8c203 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -33,6 +33,7 @@ use Eccube\Entity\Shipping; use Eccube\Service\PurchaseFlow\ItemHolderProcessor; use Eccube\Service\PurchaseFlow\ProcessResult; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 送料明細追加. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php index 040e5e77ce8..f783ea5bb27 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php @@ -6,6 +6,7 @@ use Eccube\Repository\DeliveryRepository; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 商品種別に配送業者が設定されているかどうか. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php index 7bbd176c803..f651776ecc7 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DisplayStatusValidator.php @@ -6,6 +6,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; class DisplayStatusValidator extends ValidatableItemProcessor { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index b7535b6dedd..cf075946a04 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -31,6 +31,7 @@ use Eccube\Entity\Master\ProductType; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 支払い方法が一致しない明細がないかどうか. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php index 1c3d16e07c2..7a2ed747757 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -27,6 +27,7 @@ use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 購入金額上限チェック. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php index 0ae6f2794cf..3952113ba02 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php @@ -27,6 +27,7 @@ use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 合計金額のマイナスチェック. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php index 8699549fbd5..e4f099dd021 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/SaleLimitValidator.php @@ -5,6 +5,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 販売制限数チェック. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php index e2dfb8c2276..2efa7a448ff 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php @@ -8,6 +8,7 @@ use Eccube\Entity\ShipmentItem; use Eccube\Service\PurchaseFlow\ItemProcessor; use Eccube\Service\PurchaseFlow\ProcessResult; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 在庫制御. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 2bbb97b51be..44867ad869d 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -5,6 +5,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 在庫制限チェック. diff --git a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php index cc79476709e..2775b688c2b 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php @@ -4,6 +4,7 @@ use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\PurchaseProcessor; +use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 受注情報の日付更新 diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseContext.php b/src/Eccube/Service/PurchaseFlow/PurchaseContext.php index 592e25931f3..c9c5e26f19f 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseContext.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseContext.php @@ -1,6 +1,6 @@ Date: Thu, 20 Jul 2017 15:31:20 +0900 Subject: [PATCH 73/75] =?UTF-8?q?PurchaseFlow=E3=81=AEnamespace=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=AB=E4=BC=B4=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php | 2 +- .../PurchaseProcessors/Processor/ValidatableEmptyProcessor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php index 567681e06d4..ad53cfabd95 100644 --- a/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php +++ b/app/Plugin/PurchaseProcessors/Processor/EmptyProcessor.php @@ -4,7 +4,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemProcessor; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Service\PurchaseFlow\ProcessResult; class EmptyProcessor implements ItemProcessor diff --git a/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php b/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php index 6cccbb312bb..28c9a44a0aa 100644 --- a/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php +++ b/app/Plugin/PurchaseProcessors/Processor/ValidatableEmptyProcessor.php @@ -4,7 +4,7 @@ use Eccube\Entity\ItemInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; -use Eccube\Service\PurchaseFlow\Processor\PurchaseContext; +use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Service\PurchaseFlow\ValidatableItemProcessor; class ValidatableEmptyProcessor extends ValidatableItemProcessor From b21b31c5ced57c6ad8875265ed4e723a1f5e1926 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 20 Jul 2017 16:57:18 +0900 Subject: [PATCH 74/75] =?UTF-8?q?php-cs-fixer=E3=82=922.2=E7=B3=BB?= =?UTF-8?q?=E3=81=AB=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- composer.lock | 314 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 296 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 5ac41ff6967..a01be673268 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index e5426c36be0..05ce1c36da1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "c481a3af22b99abb45d013b0e81a3067", + "content-hash": "3b433883fa3fdb4a10749df61d1af931", "packages": [ { "name": "composer/ca-bundle", @@ -2168,7 +2168,7 @@ } ], "description": "Doctrine Annotations for Silex", - "time": "2017-02-13T15:44:29+00:00" + "time": "2017-02-13 15:44:29" }, { "name": "sergiors/doctrine-cache-service-provider", @@ -2268,7 +2268,7 @@ } ], "description": "Import your routes from YAML, PHP files or Directory.", - "time": "2017-05-31T15:01:21+00:00" + "time": "2017-05-31 15:01:21" }, { "name": "sergiors/sensio-framework-extra-service-provider", @@ -2325,7 +2325,7 @@ } ], "description": "SensioFrameworkExtraBundle for Silex", - "time": "2016-12-05T06:41:02+00:00" + "time": "2016-12-05 06:41:02" }, { "name": "sergiors/templating-service-provider", @@ -5394,44 +5394,70 @@ "packages-dev": [ { "name": "friendsofphp/php-cs-fixer", - "version": "v1.13.1", + "version": "v2.2.5", "source": { "type": "git", "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "0ea4f7ed06ca55da1d8fc45da26ff87f261c4088" + "reference": "27c2cd9d4abd2178b5b585fa2c3cca656d377c69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/0ea4f7ed06ca55da1d8fc45da26ff87f261c4088", - "reference": "0ea4f7ed06ca55da1d8fc45da26ff87f261c4088", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/27c2cd9d4abd2178b5b585fa2c3cca656d377c69", + "reference": "27c2cd9d4abd2178b5b585fa2c3cca656d377c69", "shasum": "" }, "require": { + "doctrine/annotations": "^1.2", + "ext-json": "*", "ext-tokenizer": "*", + "gecko-packages/gecko-php-unit": "^2.0", "php": "^5.3.6 || >=7.0 <7.2", - "sebastian/diff": "^1.1", - "symfony/console": "^2.3 || ^3.0", + "sebastian/diff": "^1.4", + "symfony/console": "^2.4 || ^3.0", "symfony/event-dispatcher": "^2.1 || ^3.0", - "symfony/filesystem": "^2.1 || ^3.0", - "symfony/finder": "^2.1 || ^3.0", + "symfony/filesystem": "^2.4 || ^3.0", + "symfony/finder": "^2.2 || ^3.0", + "symfony/options-resolver": "^2.6 || ^3.0", + "symfony/polyfill-php54": "^1.0", + "symfony/polyfill-php55": "^1.3", + "symfony/polyfill-php70": "^1.0", + "symfony/polyfill-php72": "^1.4", "symfony/process": "^2.3 || ^3.0", "symfony/stopwatch": "^2.5 || ^3.0" }, "conflict": { - "hhvm": "<3.9" + "hhvm": "<3.18" }, "require-dev": { - "phpunit/phpunit": "^4.5|^5", - "satooshi/php-coveralls": "^1.0" + "johnkary/phpunit-speedtrap": "^1.0.1", + "justinrainbow/json-schema": "^5.0", + "phpunit/phpunit": "^4.8.35 || ^5.4.3", + "satooshi/php-coveralls": "^1.0", + "symfony/phpunit-bridge": "^3.2.2" + }, + "suggest": { + "ext-mbstring": "For handling non-UTF8 characters in cache signature.", + "symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible." }, "bin": [ "php-cs-fixer" ], "type": "application", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + } + }, "autoload": { "psr-4": { - "Symfony\\CS\\": "Symfony/CS/" - } + "PhpCsFixer\\": "src/" + }, + "classmap": [ + "tests/Test/AbstractFixerTestCase.php", + "tests/Test/AbstractIntegrationTestCase.php", + "tests/Test/IntegrationCase.php", + "tests/Test/IntegrationCaseFactory.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -5448,7 +5474,7 @@ } ], "description": "A tool to automatically fix PHP code style", - "time": "2016-12-01T00:05:05+00:00" + "time": "2017-07-18T15:16:38+00:00" }, { "name": "fzaninotto/faker", @@ -5502,6 +5528,87 @@ ], "time": "2015-05-29T06:29:14+00:00" }, + { + "name": "gecko-packages/gecko-php-unit", + "version": "v2.1", + "source": { + "type": "git", + "url": "https://github.com/GeckoPackages/GeckoPHPUnit.git", + "reference": "5b9e9622c7efd3b22655270b80c03f9e52878a6e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GeckoPackages/GeckoPHPUnit/zipball/5b9e9622c7efd3b22655270b80c03f9e52878a6e", + "reference": "5b9e9622c7efd3b22655270b80c03f9e52878a6e", + "shasum": "" + }, + "require": { + "php": "^5.3.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.4.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeckoPackages\\PHPUnit\\": "src\\PHPUnit" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Additional PHPUnit tests.", + "homepage": "https://github.com/GeckoPackages", + "keywords": [ + "extension", + "filesystem", + "phpunit" + ], + "time": "2017-06-20T11:22:48+00:00" + }, + { + "name": "ircmaxell/password-compat", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/password_compat.git", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/5c5cde8822a69545767f7c7f3058cb15ff84614c", + "reference": "5c5cde8822a69545767f7c7f3058cb15ff84614c", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "files": [ + "lib/password.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@php.net", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash", + "homepage": "https://github.com/ircmaxell/password_compat", + "keywords": [ + "hashing", + "password" + ], + "time": "2014-11-20T16:49:30+00:00" + }, { "name": "mikey179/vfsStream", "version": "v1.6.4", @@ -6287,7 +6394,7 @@ "github", "test" ], - "time": "2017-03-31T10:12:47+00:00" + "time": "2017-03-31 10:12:47" }, { "name": "sebastian/comparator", @@ -6718,6 +6825,175 @@ "homepage": "https://symfony.com", "time": "2017-06-24T09:29:48+00:00" }, + { + "name": "symfony/polyfill-php54", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php54.git", + "reference": "7dd1a8b9f0442273fdfeb1c4f5eaff6890a82789" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php54/zipball/7dd1a8b9f0442273fdfeb1c4f5eaff6890a82789", + "reference": "7dd1a8b9f0442273fdfeb1c4f5eaff6890a82789", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php54\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-09T08:25:21+00:00" + }, + { + "name": "symfony/polyfill-php55", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php55.git", + "reference": "94566239a7720cde0820f15f0cc348ddb51ba51d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php55/zipball/94566239a7720cde0820f15f0cc348ddb51ba51d", + "reference": "94566239a7720cde0820f15f0cc348ddb51ba51d", + "shasum": "" + }, + "require": { + "ircmaxell/password-compat": "~1.0", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php55\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-09T08:25:21+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "d3a71580c1e2cab33b6d705f0ec40e9015e14d5c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/d3a71580c1e2cab33b6d705f0ec40e9015e14d5c", + "reference": "d3a71580c1e2cab33b6d705f0ec40e9015e14d5c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-09T08:25:21+00:00" + }, { "name": "webmozart/assert", "version": "1.2.0", From 335bbdd5c39251b7e98a88f03f3979745a71bbd0 Mon Sep 17 00:00:00 2001 From: chihiro-adachi Date: Thu, 20 Jul 2017 17:16:41 +0900 Subject: [PATCH 75/75] php-cs-fixer fix --rules=@Symfony --- .../Service/PurchaseFlow/ItemCollection.php | 12 ++++++++++-- .../Service/PurchaseFlow/ItemHolderProcessor.php | 6 +++--- .../Service/PurchaseFlow/ItemProcessor.php | 7 +++---- .../PurchaseFlow/ItemValidateException.php | 6 ++---- .../Service/PurchaseFlow/ProcessResult.php | 4 +--- .../AdminOrderRegisterPurchaseProcessor.php | 2 +- .../Processor/DeliveryFeeFreeProcessor.php | 5 +++-- .../Processor/DeliveryFeeProcessor.php | 14 +++++++++----- .../PurchaseFlow/Processor/PaymentProcessor.php | 4 ++-- .../Processor/PaymentTotalLimitValidator.php | 4 ++-- .../Processor/PaymentTotalNegativeValidator.php | 3 +-- .../Processor/StockReduceProcessor.php | 7 +++++-- .../PurchaseFlow/Processor/StockValidator.php | 3 ++- .../Processor/UpdateDatePurchaseProcessor.php | 4 +++- .../Service/PurchaseFlow/PurchaseContext.php | 5 +---- .../Service/PurchaseFlow/PurchaseException.php | 3 +-- src/Eccube/Service/PurchaseFlow/PurchaseFlow.php | 10 +++++++++- .../Service/PurchaseFlow/PurchaseFlowResult.php | 13 ++++++------- .../Service/PurchaseFlow/PurchaseProcessor.php | 6 +++--- .../ValidatableItemHolderProcessor.php | 11 +++++++---- .../PurchaseFlow/ValidatableItemProcessor.php | 6 +++--- .../Service/PurchaseFlow/ItemCollectionTest.php | 6 ++++-- .../Processor/DeletedProductValidatorTest.php | 5 ++--- .../Processor/DeliveryFeeFreeProcessorTest.php | 7 +++---- .../Processor/DeliveryFeeProcessorTest.php | 9 ++++----- .../Processor/DeliverySettingValidatorTest.php | 4 ++-- .../Processor/DisplayStatusValidatorTest.php | 4 ++-- .../Service/PurchaseFlow/PurchaseFlowTest.php | 16 +++++++--------- .../ValidatableItemProcessorTest.php | 6 +----- 29 files changed, 102 insertions(+), 90 deletions(-) diff --git a/src/Eccube/Service/PurchaseFlow/ItemCollection.php b/src/Eccube/Service/PurchaseFlow/ItemCollection.php index 0fe89c39690..6d813136715 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemCollection.php +++ b/src/Eccube/Service/PurchaseFlow/ItemCollection.php @@ -72,13 +72,16 @@ function (ItemInterface $ShipmentItem) use ($productName) { /* @var ShipmentItem $ShipmentItem */ return $ShipmentItem->getProductName() == $productName; }); + return !$ShipmentItems->isEmpty(); } /** - * 指定した受注明細区分の明細が存在するかどうか + * 指定した受注明細区分の明細が存在するかどうか. + * * @param OrderItemType $OrderItemType 受注区分 - * @return boolean + * + * @return bool */ public function hasItemByOrderItemType($OrderItemType) { @@ -86,6 +89,7 @@ public function hasItemByOrderItemType($OrderItemType) /* @var ShipmentItem $ShipmentItem */ return $ShipmentItem->getOrderItemType() && $ShipmentItem->getOrderItemType()->getId() == $OrderItemType->getId(); }); + return !$filteredItems->isEmpty(); } @@ -106,16 +110,19 @@ public function sort() if ($b->isProduct()) { return 1; } + return -1; } elseif ($a->isCharge()) { if ($b->isDeliveryFee() || $b->isProduct()) { return 1; } + return -1; } elseif ($a->isDiscount()) { if (!$b->isTax()) { return 1; } + return -1; } elseif ($a->isTax()) { return 1; @@ -123,6 +130,7 @@ public function sort() return 0; }); + return new self($Items); } } diff --git a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php index 655ff95afcc..3509d802d36 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemHolderProcessor.php @@ -2,15 +2,15 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\ItemHolderInterface; interface ItemHolderProcessor { /** * @param ItemHolderInterface $itemHolder - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @return ProcessResult */ public function process(ItemHolderInterface $itemHolder, PurchaseContext $context); -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php index 490154f2b35..578d722f3ec 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ItemProcessor.php @@ -2,16 +2,15 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\ItemInterface; interface ItemProcessor { /** - * @param ItemInterface $item + * @param ItemInterface $item * @param PurchaseContext $context + * * @return ProcessResult */ public function process(ItemInterface $item, PurchaseContext $context); - -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php index ef39538841e..9e452b165db 100644 --- a/src/Eccube/Service/PurchaseFlow/ItemValidateException.php +++ b/src/Eccube/Service/PurchaseFlow/ItemValidateException.php @@ -23,13 +23,11 @@ namespace Eccube\Service\PurchaseFlow; - class ItemValidateException extends \Exception { - private $messageArgs = []; - function __construct($message = null, $messageArgs = []) + public function __construct($message = null, $messageArgs = []) { parent::__construct($message); $this->messageArgs = $messageArgs; @@ -42,4 +40,4 @@ public function getMessageArgs() { return $this->messageArgs; } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/ProcessResult.php b/src/Eccube/Service/PurchaseFlow/ProcessResult.php index 1ca4a67307e..62e0ee9a7ff 100644 --- a/src/Eccube/Service/PurchaseFlow/ProcessResult.php +++ b/src/Eccube/Service/PurchaseFlow/ProcessResult.php @@ -2,12 +2,10 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Application; class ProcessResult { - const ERROR = 'ERROR'; const WARNING = 'WARNING'; const SUCCESS = 'SUCCESS'; @@ -55,4 +53,4 @@ public function getMessage() { return $this->message; } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php index fbd2d857a5c..a8e110bee33 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/AdminOrderRegisterPurchaseProcessor.php @@ -7,7 +7,7 @@ use Eccube\Service\PurchaseFlow\PurchaseContext; /** - * 管理画面/受注登録/編集画面の完了処理 + * 管理画面/受注登録/編集画面の完了処理. */ class AdminOrderRegisterPurchaseProcessor implements PurchaseProcessor { diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php index 49f3af3fef1..71b1a77179c 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessor.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; - use Eccube\Application; use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemHolderProcessor; @@ -42,6 +41,7 @@ class DeliveryFeeFreeProcessor implements ItemHolderProcessor /** * DeliveryFeeProcessor constructor. + * * @param Application $app */ public function __construct(Application $app) @@ -51,7 +51,8 @@ public function __construct(Application $app) /** * @param ItemHolderInterface $itemHolder - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @return ProcessResult */ public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php index e35edc8c203..e667d81a4c6 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/DeliveryFeeProcessor.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; - use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\Master\OrderItemType; use Eccube\Entity\Master\TaxDisplayType; @@ -40,11 +39,11 @@ */ class DeliveryFeeProcessor implements ItemHolderProcessor { - private $app; /** * DeliveryFeeProcessor constructor. + * * @param $app */ public function __construct($app) @@ -54,7 +53,8 @@ public function __construct($app) /** * @param ItemHolderInterface $itemHolder - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @return ProcessResult */ public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) @@ -62,11 +62,13 @@ public function process(ItemHolderInterface $itemHolder, PurchaseContext $contex if ($this->containsDeliveryFeeItem($itemHolder) == false) { $this->addDeliveryFeeItem($itemHolder); } + return ProcessResult::success(); } /** * @param ItemHolderInterface $itemHolder + * * @return bool */ private function containsDeliveryFeeItem(ItemHolderInterface $itemHolder) @@ -76,11 +78,13 @@ private function containsDeliveryFeeItem(ItemHolderInterface $itemHolder) return true; } } + return false; } /** - * TODO 送料無料計算 + * TODO 送料無料計算. + * * @param ItemHolderInterface $itemHolder */ private function addDeliveryFeeItem(ItemHolderInterface $itemHolder) @@ -95,7 +99,7 @@ private function addDeliveryFeeItem(ItemHolderInterface $itemHolder) /* @var Shipping $Shipping */ foreach ($Order->getShippings() as $Shipping) { $ShipmentItem = new ShipmentItem(); - $ShipmentItem->setProductName("送料") + $ShipmentItem->setProductName('送料') ->setPrice($Shipping->getShippingDeliveryFee()) ->setPriceIncTax($Shipping->getShippingDeliveryFee()) ->setTaxRate(8) diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php index cf075946a04..fd7cd2f9d1b 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentProcessor.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; - use Doctrine\Common\Collections\ArrayCollection; use Eccube\Application; use Eccube\Entity\Delivery; @@ -45,6 +44,7 @@ class PaymentProcessor extends ValidatableItemHolderProcessor /** * DeliveryFeeProcessor constructor. + * * @param Application $app */ public function __construct(Application $app) @@ -75,7 +75,7 @@ protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $co } if ($i === 0) { $paymentIds = $ids; - $i++; + ++$i; continue; } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php index 7a2ed747757..87a8c205b64 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalLimitValidator.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; - use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; @@ -41,6 +40,7 @@ class PaymentTotalLimitValidator extends ValidatableItemHolderProcessor /** * PaymentTotalLimitValidator constructor. + * * @param $maxTotalFee */ public function __construct($maxTotalFee) @@ -55,4 +55,4 @@ protected function validate(ItemHolderInterface $item, PurchaseContext $context) throw new ItemValidateException('cart.over.price_limit'); } } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php index 3952113ba02..efcb83949a4 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/PaymentTotalNegativeValidator.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow\Processor; - use Eccube\Entity\ItemHolderInterface; use Eccube\Service\PurchaseFlow\ItemValidateException; use Eccube\Service\PurchaseFlow\ValidatableItemHolderProcessor; @@ -40,4 +39,4 @@ protected function validate(ItemHolderInterface $item, PurchaseContext $context) throw new ItemValidateException('shopping.total.price'); } } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php index 2efa7a448ff..7d2acc9c179 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockReduceProcessor.php @@ -15,11 +15,11 @@ */ class StockReduceProcessor implements ItemProcessor { - private $app; /** * DeliveryFeeProcessor constructor. + * * @param $app */ public function __construct($app) @@ -28,9 +28,11 @@ public function __construct($app) } /** - * @param ItemInterface $item + * @param ItemInterface $item * @param PurchaseContext $context + * * @return ProcessResult + * * @internal param ItemHolderInterface $itemHolder */ public function process(ItemInterface $item, PurchaseContext $context) @@ -60,6 +62,7 @@ public function process(ItemInterface $item, PurchaseContext $context) return ProcessResult::fail('在庫エラー'); } } + return ProcessResult::success(); } } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php index 44867ad869d..976edfe5b95 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/StockValidator.php @@ -30,7 +30,8 @@ protected function validate(ItemInterface $item, PurchaseContext $context) } } - protected function handle(ItemInterface $item, PurchaseContext $context) { + protected function handle(ItemInterface $item, PurchaseContext $context) + { $stock = $item->getProductClass()->getStock(); $item->setQuantity($stock); } diff --git a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php index 2775b688c2b..a2f5a970627 100644 --- a/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/Processor/UpdateDatePurchaseProcessor.php @@ -7,15 +7,17 @@ use Eccube\Service\PurchaseFlow\PurchaseContext; /** - * 受注情報の日付更新 + * 受注情報の日付更新. */ class UpdateDatePurchaseProcessor implements PurchaseProcessor { protected $app; + public function __construct($app) { $this->app = $app; } + /** * {@inheritdoc} */ diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseContext.php b/src/Eccube/Service/PurchaseFlow/PurchaseContext.php index c9c5e26f19f..52dddf605bb 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseContext.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseContext.php @@ -2,9 +2,6 @@ namespace Eccube\Service\PurchaseFlow; - -use Eccube\Application; -use Eccube\Entity\Customer; use Eccube\Entity\ItemHolderInterface; class PurchaseContext extends \SplObjectStorage @@ -32,4 +29,4 @@ public function getUser() { return $this->user; } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseException.php b/src/Eccube/Service/PurchaseFlow/PurchaseException.php index 3b1a0abb1f4..aa4b8eab577 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseException.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseException.php @@ -23,7 +23,6 @@ namespace Eccube\Service\PurchaseFlow; - class PurchaseException extends \Exception { -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php index 863d09748e6..df630775acf 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlow.php @@ -73,7 +73,8 @@ public function calculate(ItemHolderInterface $itemHolder, PurchaseContext $cont /** * @param ItemHolderInterface $target - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @throws PurchaseException */ public function purchase(ItemHolderInterface $target, PurchaseContext $context) @@ -105,6 +106,7 @@ protected function calculateTotal(ItemHolderInterface $itemHolder) { $total = $itemHolder->getItems()->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; }, 0); $itemHolder->setTotal($total); @@ -121,6 +123,7 @@ protected function calculateSubTotal(ItemHolderInterface $itemHolder) ->getProductClasses() ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; }, 0); // TODO @@ -129,6 +132,7 @@ protected function calculateSubTotal(ItemHolderInterface $itemHolder) $itemHolder->setSubTotal($total); } } + /** * @param ItemHolderInterface $itemHolder */ @@ -138,6 +142,7 @@ protected function calculateDeliveryFeeTotal(ItemHolderInterface $itemHolder) ->getDeliveryFees() ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; }, 0); $itemHolder->setDeliveryFeeTotal($total); @@ -152,6 +157,7 @@ protected function calculateDiscount(ItemHolderInterface $itemHolder) ->getDiscounts() ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; }, 0); // TODO 後方互換のため discount には正の整数を代入する @@ -167,6 +173,7 @@ protected function calculateCharge(ItemHolderInterface $itemHolder) ->getCharges() ->reduce(function ($sum, ItemInterface $item) { $sum += $item->getPriceIncTax() * $item->getQuantity(); + return $sum; }, 0); $itemHolder->setCharge($total); @@ -180,6 +187,7 @@ protected function calculateTax(ItemHolderInterface $itemHolder) $total = $itemHolder->getItems() ->reduce(function ($sum, ItemInterface $item) { $sum += ($item->getPriceIncTax() - $item->getPrice()) * $item->getQuantity(); + return $sum; }, 0); $itemHolder->setTax($total); diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php index 8b31fd20fd8..00aff8901b8 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseFlowResult.php @@ -23,20 +23,19 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\ItemHolderInterface; class PurchaseFlowResult { - - /** @var ItemHolderInterface */ + /** @var ItemHolderInterface */ private $itemHolder; - /** @var ProcessResult[] */ + /** @var ProcessResult[] */ private $processResults = []; /** * PurcahseFlowResult constructor. + * * @param ItemHolderInterface $itemHolder */ public function __construct(ItemHolderInterface $itemHolder) @@ -54,7 +53,7 @@ public function addProcessResult(ProcessResult $processResult) */ public function getErrors() { - return array_filter($this->processResults, function(ProcessResult $processResult) { + return array_filter($this->processResults, function (ProcessResult $processResult) { return $processResult->isError(); }); } @@ -64,7 +63,7 @@ public function getErrors() */ public function getWarning() { - return array_filter($this->processResults, function(ProcessResult $processResult) { + return array_filter($this->processResults, function (ProcessResult $processResult) { return $processResult->isWarning(); }); } @@ -78,4 +77,4 @@ public function hasWarning() { return !empty($this->getWarning()); } -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php index 7e1d15b2839..8d5cc5808b5 100644 --- a/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/PurchaseProcessor.php @@ -2,15 +2,15 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\ItemHolderInterface; interface PurchaseProcessor { /** * @param ItemHolderInterface $target - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @throws PurchaseException */ public function process(ItemHolderInterface $target, PurchaseContext $context); -} \ No newline at end of file +} diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php index 6d396740381..6e813f1b38e 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemHolderProcessor.php @@ -8,10 +8,11 @@ abstract class ValidatableItemHolderProcessor implements ItemHolderProcessor { /** * @param ItemHolderInterface $itemHolder - * @param PurchaseContext $context + * @param PurchaseContext $context + * * @return ProcessResult */ - public final function process(ItemHolderInterface $itemHolder, PurchaseContext $context) + final public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { try { $this->validate($itemHolder, $context); @@ -22,7 +23,9 @@ public final function process(ItemHolderInterface $itemHolder, PurchaseContext $ } } - protected abstract function validate(ItemHolderInterface $itemHolder, PurchaseContext $context); + abstract protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context); - protected function handle(ItemHolderInterface $itemHolder) {} + protected function handle(ItemHolderInterface $itemHolder) + { + } } diff --git a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php index 83938ae5bfb..1064475b3fb 100644 --- a/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php +++ b/src/Eccube/Service/PurchaseFlow/ValidatableItemProcessor.php @@ -23,15 +23,15 @@ namespace Eccube\Service\PurchaseFlow; - use Eccube\Entity\CartItem; use Eccube\Entity\ItemInterface; abstract class ValidatableItemProcessor implements ItemProcessor { /** - * @param ItemInterface $item + * @param ItemInterface $item * @param PurchaseContext $context + * * @return ProcessResult */ public function process(ItemInterface $item, PurchaseContext $context) @@ -49,7 +49,7 @@ public function process(ItemInterface $item, PurchaseContext $context) } } - protected abstract function validate(ItemInterface $item, PurchaseContext $context); + abstract protected function validate(ItemInterface $item, PurchaseContext $context); protected function handle(ItemInterface $item, PurchaseContext $context) { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php index c7f9133dd3d..4bffdd40843 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ItemCollectionTest.php @@ -38,7 +38,9 @@ public function testInstanceWithCollection() public function testReduce() { $reducer = function ($sum, ItemInterface $item) { - return $sum =+ $item->getPrice() * $item->getQuantity(); + $sum += $item->getPrice() * $item->getQuantity(); + + return $sum; }; $this->expected = array_reduce($this->Items, $reducer, 0); @@ -97,7 +99,7 @@ public function testSort() { shuffle($this->Items); - $this->expected = [ 1 => '商品', 2 => '送料', 3 => '手数料', 4 => '割引']; + $this->expected = [1 => '商品', 2 => '送料', 3 => '手数料', 4 => '割引']; $this->actual = []; $Items = (new ItemCollection($this->Items))->sort(); foreach ($Items as $Item) { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php index f3b1420ff99..9b06914b94a 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeletedProductValidatorTest.php @@ -6,7 +6,6 @@ use Eccube\Entity\Product; use Eccube\Entity\ProductClass; use Eccube\Service\PurchaseFlow\Processor\DeletedProductValidator; -use Eccube\Service\PurchaseFlow\Processor\DeliverySettingValidator; use Eccube\Service\PurchaseFlow\PurchaseContext; use Eccube\Tests\EccubeTestCase; @@ -49,7 +48,7 @@ public function testInstance() } /** - * 削除フラグ(スタータス)が立っていなければ何もしない + * 削除フラグ(スタータス)が立っていなければ何もしない. */ public function testProductIsValid() { @@ -59,7 +58,7 @@ public function testProductIsValid() } /** - * 削除済商品の場合は明細の個数を0に設定する + * 削除済商品の場合は明細の個数を0に設定する. */ public function testDisplayStatusWithClosed() { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php index b77817bd10f..390425133fe 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeFreeProcessorTest.php @@ -23,7 +23,6 @@ namespace Eccube\Tests\Service\PurchaseFlow\Processor; - use Eccube\Entity\BaseInfo; use Eccube\Entity\Order; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeeFreeProcessor; @@ -57,7 +56,7 @@ public function testNewInstance() } /** - * 送料無料条件に合致しない場合 + * 送料無料条件に合致しない場合. */ public function testProcess() { @@ -72,7 +71,7 @@ public function testProcess() } /** - * 送料無料条件(金額)に合致する場合, 送料明細の個数は0になる + * 送料無料条件(金額)に合致する場合, 送料明細の個数は0になる. */ public function testProcessWithAmount() { @@ -91,7 +90,7 @@ public function testProcessWithAmount() } /** - * 送料無料条件(個数)に合致する場合, 送料明細の個数は0になる + * 送料無料条件(個数)に合致する場合, 送料明細の個数は0になる. */ public function testProcessWithQuantity() { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php index ee8bff5e700..d1aa22150df 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliveryFeeProcessorTest.php @@ -23,7 +23,6 @@ namespace Eccube\Tests\Service\PurchaseFlow\Processor; - use Eccube\Entity\Master\OrderItemType; use Eccube\Entity\Order; use Eccube\Entity\ShipmentItem; @@ -38,7 +37,7 @@ public function testProcess() $processor = new DeliveryFeeProcessor($this->app); $Order = $this->createOrder($this->createCustomer()); /** - * @var ShipmentItem $ShipmentItem + * @var ShipmentItem */ foreach ($Order->getShipmentItems() as $ShipmentItem) { if ($ShipmentItem->isDeliveryFee()) { @@ -50,14 +49,14 @@ public function testProcess() } /** - * すでに送料がある場合は送料を追加しない + * すでに送料がある場合は送料を追加しない. */ public function testProcessWithDeliveryFee() { $processor = new DeliveryFeeProcessor($this->app); $Order = $this->createOrder($this->createCustomer()); /** - * @var ShipmentItem $ShipmentItem + * @var ShipmentItem */ foreach ($Order->getShipmentItems() as $ShipmentItem) { if ($ShipmentItem->isDeliveryFee()) { @@ -80,7 +79,7 @@ public function testProcessWithDeliveryFee() private function getDeliveryFees(Order $Order) { - return array_filter($Order->getShipmentItems()->toArray(), function($ShipmentItem) { + return array_filter($Order->getShipmentItems()->toArray(), function ($ShipmentItem) { return $ShipmentItem->isDeliveryFee(); }); } diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php index a4eeeb577c1..935def62e69 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DeliverySettingValidatorTest.php @@ -49,7 +49,7 @@ public function testInstance() } /** - * 配送業者が適切に設定されていれば何もしない + * 配送業者が適切に設定されていれば何もしない. */ public function testDeliverySettingIsValid() { @@ -59,7 +59,7 @@ public function testDeliverySettingIsValid() } /** - * 配送業者が設定できていない商品の場合は明細の個数を0に設定する + * 配送業者が設定できていない商品の場合は明細の個数を0に設定する. */ public function testDisplayStatusWithClosed() { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php index 8bd2867f3e6..2e39375bf02 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/Processor/DisplayStatusValidatorTest.php @@ -51,7 +51,7 @@ public function testInstance() } /** - * 公開商品の場合はなにもしない + * 公開商品の場合はなにもしない. */ public function testDisplayStatusWithShow() { @@ -66,7 +66,7 @@ public function testDisplayStatusWithShow() } /** - * 非公開商品の場合は明細の個数を0に設定する + * 非公開商品の場合は明細の個数を0に設定する. */ public function testDisplayStatusWithClosed() { diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php index 831249f90c1..76c14508ab2 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/PurchaseFlowTest.php @@ -21,7 +21,7 @@ class PurchaseFlowTest extends EccubeTestCase { /** - * @var PurchaseFlow $flow + * @var PurchaseFlow */ protected $flow; @@ -36,7 +36,6 @@ public function setUp() public function testExecute() { - $this->assertInstanceOf(PurchaseFlow::class, $this->flow); $itemHolder = new Cart(); @@ -85,8 +84,8 @@ public function testProcessItemHolderProcessor_validationErrors() public function testProcessItemProcessors_validationErrors() { - $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); - $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor('error 1')); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor('error 2')); $itemHolder = new Order(); $itemHolder->addShipmentItem(new ShipmentItem()); @@ -98,8 +97,8 @@ public function testProcessItemProcessors_validationErrors() public function testProcessItemProcessors_validationErrors_with_multi_items() { - $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 1")); - $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor("error 2")); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor('error 1')); + $this->flow->addItemProcessor(new PurchaseFlowTest_FailProcessor('error 2')); $itemHolder = new Order(); $itemHolder->addShipmentItem(new ShipmentItem()); $itemHolder->addShipmentItem(new ShipmentItem()); @@ -111,7 +110,6 @@ public function testProcessItemProcessors_validationErrors_with_multi_items() $expected->addProcessResult(ProcessResult::warn('error 2')); self::assertEquals($expected, $this->flow->calculate($itemHolder, PurchaseContext::create())); } - } class PurchaseFlowTest_ItemHolderProcessor implements ItemHolderProcessor @@ -124,7 +122,6 @@ public function process(ItemHolderInterface $itemHolder, PurchaseContext $contex class PurchaseFlowTest_ItemProcessor implements ItemProcessor { - public function process(ItemInterface $item, PurchaseContext $context) { return ProcessResult::success(); @@ -137,6 +134,7 @@ class PurchaseFlowTest_FailProcessor extends ValidatableItemProcessor /** * PurchaseFlowTest_FailProcessor constructor. + * * @param $errorMessage */ public function __construct($errorMessage) @@ -156,6 +154,7 @@ class PurchaseFlowTest_FailItemHolderProcessor extends ValidatableItemHolderProc /** * PurchaseFlowTest_FailProcessor constructor. + * * @param $errorMessage */ public function __construct($errorMessage) @@ -169,4 +168,3 @@ protected function validate(ItemHolderInterface $item, PurchaseContext $context) throw new ItemValidateException($this->errorMessage); } } - diff --git a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php index 75b8977f276..1a44609543e 100644 --- a/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php +++ b/tests/Eccube/Tests/Service/PurchaseFlow/ValidatableItemProcessorTest.php @@ -33,7 +33,6 @@ class ValidatableItemProcessorTest extends EccubeTestCase { - /* * カートの場合 * エラーなら明細丸め処理 & カート画面にエラー表示¨ @@ -82,7 +81,6 @@ public function testValidateOrderFail() class ValidatableItemProcessorTest_NormalValidator extends ValidatableItemProcessor { - public $handleCalled = false; protected function validate(ItemInterface $item, PurchaseContext $context) @@ -97,7 +95,6 @@ protected function handle(ItemInterface $item, PurchaseContext $context) class ValidatableItemProcessorTest_FailValidator extends ValidatableItemProcessor { - public $handleCalled = false; protected function validate(ItemInterface $item, PurchaseContext $context) @@ -109,5 +106,4 @@ protected function handle(ItemInterface $item, PurchaseContext $context) { $this->handleCalled = true; } - -} \ No newline at end of file +}