Created
June 14, 2018 07:06
-
-
Save nanasess/479c846ca2794c1accb22474c7567e30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Eccube/Service/OrderHelper.php b/src/Eccube/Service/OrderHelper.php | |
index 6753b31af..bdad561cd 100644 | |
--- a/src/Eccube/Service/OrderHelper.php | |
+++ b/src/Eccube/Service/OrderHelper.php | |
@@ -21,6 +21,7 @@ use Eccube\Entity\Cart; | |
use Eccube\Entity\CartItem; | |
use Eccube\Entity\Customer; | |
use Eccube\Entity\CustomerAddress; | |
+use Eccube\Entity\ItemHolderInterface; | |
use Eccube\Entity\Master\OrderItemType; | |
use Eccube\Entity\Master\OrderStatus; | |
use Eccube\Entity\Master\ShippingStatus; | |
@@ -205,6 +206,17 @@ class OrderHelper | |
return $Cart; | |
} | |
+ public function compareTo(Cart $Cart, Order $Order) | |
+ { | |
+ $summarizeCartItems = $this->summarizeProductClassInQuantity($Cart); | |
+ $summarizeOrderItems = $this->summarizeProductClassInQuantity($Order); | |
+ dump(array_diff_assoc($summarizeCartItems, $summarizeOrderItems)); | |
+ if (array_diff_assoc($summarizeCartItems, $summarizeOrderItems)) { | |
+ return false; | |
+ } | |
+ return true; | |
+ } | |
+ | |
private function createPreOrderId() | |
{ | |
// ランダムなpre_order_idを作成 | |
@@ -379,4 +391,17 @@ class OrderHelper | |
$OrderItem->setShipping($Shipping); | |
} | |
} | |
+ | |
+ private function summarizeProductClassInQuantity(ItemHolderInterface $ItemHolder) | |
+ { | |
+ $Items = $ItemHolder->getItems()->filter(function ($Item) { | |
+ return $Item->isProduct(); | |
+ }); | |
+ $Result = []; | |
+ foreach ($Items as $Item) { | |
+ $Result[$Item->getProductClass()->getId()] = $Item->getQuantity(); | |
+ } | |
+ ksort($Result); | |
+ return $Result; | |
+ } | |
} | |
diff --git a/tests/Eccube/Tests/Service/OrderHelperTest.php b/tests/Eccube/Tests/Service/OrderHelperTest.php | |
index 137a6ecda..a478a2872 100644 | |
--- a/tests/Eccube/Tests/Service/OrderHelperTest.php | |
+++ b/tests/Eccube/Tests/Service/OrderHelperTest.php | |
@@ -17,6 +17,7 @@ use Eccube\Entity\Cart; | |
use Eccube\Entity\Order; | |
use Eccube\Entity\OrderItem; | |
use Eccube\Service\OrderHelper; | |
+use Eccube\Service\CartService; | |
use Eccube\Tests\EccubeTestCase; | |
class OrderHelperTest extends EccubeTestCase | |
@@ -24,10 +25,14 @@ class OrderHelperTest extends EccubeTestCase | |
/** @var OrderHelper */ | |
private $helper; | |
+ /** @var CartService */ | |
+ private $cartService; | |
+ | |
public function setUp() | |
{ | |
parent::setUp(); | |
$this->helper = $this->container->get(OrderHelper::class); | |
+ $this->cartService = $this->container->get(CartService::class); | |
} | |
public function testConvertToCart_new_cart() | |
@@ -58,4 +63,19 @@ class OrderHelperTest extends EccubeTestCase | |
self::assertEquals($Order->getPreOrderId(), $Cart->getPreOrderId()); | |
} | |
+ | |
+ public function testCompareTo() | |
+ { | |
+ $Product = $this->createProduct('test', 1); | |
+ $ProductClasses = $Product->getProductClasses()->toArray(); | |
+ foreach ($ProductClasses as $ProductClass) { | |
+ $this->cartService->addProduct($ProductClass->getId(), 1); | |
+ } | |
+ | |
+ $Customer = $this->createCustomer(); | |
+ $Order = $this->createOrderWithProductClasses($Customer, $ProductClasses); | |
+ $Cart = $this->cartService->getCart(); | |
+ | |
+ $this->assertFalse($this->helper->compareTo($Cart, $Order)); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment