Skip to content

Commit 042acf3

Browse files
committed
ACP2E-497: Inventory Reservation Issue for refunds created via REST API
1 parent 97eb9ae commit 042acf3

File tree

18 files changed

+959
-602
lines changed

18 files changed

+959
-602
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartManagementInterface;
12+
use Magento\Quote\Api\PaymentMethodManagementInterface;
13+
use Magento\Sales\Api\OrderManagementInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
16+
17+
class PlaceOrder implements RevertibleDataFixtureInterface
18+
{
19+
/**
20+
* @var PaymentMethodManagementInterface
21+
*/
22+
private $paymentManagement;
23+
24+
/**
25+
* @var CartManagementInterface
26+
*/
27+
private $cartManagement;
28+
29+
/**
30+
* @var OrderRepositoryInterface
31+
*/
32+
private $orderRepository;
33+
34+
/**
35+
* @var OrderManagementInterface
36+
*/
37+
private $orderManagement;
38+
39+
/**
40+
* @param PaymentMethodManagementInterface $paymentManagement
41+
* @param CartManagementInterface $cartManagement
42+
* @param OrderRepositoryInterface $orderRepository
43+
* @param OrderManagementInterface $orderManagement
44+
*/
45+
public function __construct(
46+
PaymentMethodManagementInterface $paymentManagement,
47+
CartManagementInterface $cartManagement,
48+
OrderRepositoryInterface $orderRepository,
49+
OrderManagementInterface $orderManagement
50+
) {
51+
$this->paymentManagement = $paymentManagement;
52+
$this->cartManagement = $cartManagement;
53+
$this->orderRepository = $orderRepository;
54+
$this->orderManagement = $orderManagement;
55+
}
56+
57+
/**
58+
* {@inheritdoc}
59+
* @param array $data Parameters
60+
* <pre>
61+
* $data = [
62+
* 'cart_id' => (int) Cart ID. Required
63+
* ]
64+
* </pre>
65+
*/
66+
public function apply(array $data = []): ?DataObject
67+
{
68+
$cartId = (int)$data['cart_id'];
69+
$paymentMethod = $this->paymentManagement->get($cartId);
70+
71+
$orderId = (int) $this->cartManagement->placeOrder($cartId, $paymentMethod);
72+
73+
return $this->orderRepository->get($orderId);
74+
}
75+
76+
/**
77+
* @inheritdoc
78+
*/
79+
public function revert(DataObject $data): void
80+
{
81+
$order = $this->orderRepository->get($data->getId());
82+
if ($order) {
83+
$this->orderManagement->cancel($order->getId());
84+
$this->orderRepository->delete($order);
85+
}
86+
}
87+
}

app/code/Magento/Quote/Test/Fixture/SetBillingAddress.php renamed to app/code/Magento/Checkout/Test/Fixture/SetBillingAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Quote\Test\Fixture;
8+
namespace Magento\Checkout\Test\Fixture;
99

1010
use Magento\Framework\DataObject;
1111
use Magento\Quote\Api\BillingAddressManagementInterface;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Test\Fixture;
9+
10+
use Magento\Checkout\Api\Data\ShippingInformationInterface;
11+
use Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory;
12+
use Magento\Checkout\Api\ShippingInformationManagementInterface;
13+
use Magento\Framework\DataObject;
14+
use Magento\Quote\Api\CartRepositoryInterface;
15+
use Magento\TestFramework\Fixture\DataFixtureInterface;
16+
17+
class SetDeliveryMethod implements DataFixtureInterface
18+
{
19+
private const DEFAULT_DATA = [
20+
'cart_id' => null,
21+
'carrier_code' => 'flatrate',
22+
'method_code' => 'flatrate'
23+
];
24+
25+
/**
26+
* @var CartRepositoryInterface
27+
*/
28+
private $cartRepository;
29+
30+
/**
31+
* @var ShippingInformationInterfaceFactory
32+
*/
33+
private $shippingInformationFactory;
34+
35+
/**
36+
* @var ShippingInformationManagementInterface
37+
*/
38+
private $shippingInformationManagement;
39+
40+
/**
41+
* @param CartRepositoryInterface $cartRepository
42+
* @param ShippingInformationInterfaceFactory $shippingInformationFactory
43+
* @param ShippingInformationManagementInterface $shippingInformationManagement
44+
*/
45+
public function __construct(
46+
CartRepositoryInterface $cartRepository,
47+
ShippingInformationInterfaceFactory $shippingInformationFactory,
48+
ShippingInformationManagementInterface $shippingInformationManagement
49+
) {
50+
$this->cartRepository = $cartRepository;
51+
$this->shippingInformationFactory = $shippingInformationFactory;
52+
$this->shippingInformationManagement = $shippingInformationManagement;
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
* @param array $data Parameters
58+
* <pre>
59+
* $data = [
60+
* 'cart_id' => (int) Cart ID. Required
61+
* 'carrier_code' => (string) Carrier Code. Optional
62+
* 'method_code' => (string) Method Code. Optional
63+
* ]
64+
* </pre>
65+
*/
66+
public function apply(array $data = []): ?DataObject
67+
{
68+
$data = array_merge(self::DEFAULT_DATA, $data);
69+
$cart = $this->cartRepository->get($data['cart_id']);
70+
/** @var ShippingInformationInterface $shippingInformation */
71+
$shippingInformation = $this->shippingInformationFactory->create([
72+
'data' => [
73+
ShippingInformationInterface::SHIPPING_ADDRESS => $cart->getShippingAddress(),
74+
ShippingInformationInterface::SHIPPING_CARRIER_CODE => $data['carrier_code'],
75+
ShippingInformationInterface::SHIPPING_METHOD_CODE => $data['method_code'],
76+
],
77+
]);
78+
$this->shippingInformationManagement->saveAddressInformation($cart->getId(), $shippingInformation);
79+
80+
return null;
81+
}
82+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class SetGuestEmail implements DataFixtureInterface
16+
{
17+
private const DEFAULT_DATA = [
18+
'cart_id' => null,
19+
'email' => 'guestuser%uniqid%@example.com'
20+
];
21+
22+
/**
23+
* @var CartRepositoryInterface
24+
*/
25+
private $cartRepository;
26+
27+
/**
28+
* @var ProcessorInterface
29+
*/
30+
private $dataProcessor;
31+
32+
/**
33+
* @param CartRepositoryInterface $cartRepository
34+
* @param ProcessorInterface $dataProcessor
35+
*/
36+
public function __construct(
37+
CartRepositoryInterface $cartRepository,
38+
ProcessorInterface $dataProcessor
39+
) {
40+
41+
$this->cartRepository = $cartRepository;
42+
$this->dataProcessor = $dataProcessor;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
* @param array $data Parameters
48+
* <pre>
49+
* $data = [
50+
* 'cart_id' => (int) Cart ID. Required
51+
* 'email' => (string) Guest Email. Optional
52+
* ]
53+
* </pre>
54+
*/
55+
public function apply(array $data = []): ?DataObject
56+
{
57+
$cart = $this->cartRepository->get($data['cart_id']);
58+
$data = $this->dataProcessor->process($this, array_merge(self::DEFAULT_DATA, $data));
59+
$cart->setCustomerEmail($data['email']);
60+
$this->cartRepository->save($cart);
61+
62+
return null;
63+
}
64+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\PaymentMethodManagementInterface;
12+
use Magento\TestFramework\Fixture\Api\ServiceFactory;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
class SetPaymentMethod implements DataFixtureInterface
16+
{
17+
private const DEFAULT_DATA = [
18+
'cart_id' => null,
19+
'method' => [
20+
'method' => 'checkmo',
21+
'po_number' => null,
22+
'additional_data' => null,
23+
],
24+
];
25+
/**
26+
* @var ServiceFactory
27+
*/
28+
private $serviceFactory;
29+
30+
/**
31+
* @param ServiceFactory $serviceFactory
32+
*/
33+
public function __construct(
34+
ServiceFactory $serviceFactory
35+
) {
36+
$this->serviceFactory = $serviceFactory;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
* @param array $data Parameters
42+
* <pre>
43+
* $data = [
44+
* 'cart_id' => (int) Cart ID. Required
45+
* 'method' => (array) Payment method. Optional
46+
* ]
47+
* </pre>
48+
*/
49+
public function apply(array $data = []): ?DataObject
50+
{
51+
$data = array_merge(self::DEFAULT_DATA, $data);
52+
$service = $this->serviceFactory->create(PaymentMethodManagementInterface::class, 'set');
53+
$service->execute(
54+
[
55+
'cart_id' => $data['cart_id'],
56+
'method' => $data['method'],
57+
]
58+
);
59+
60+
return null;
61+
}
62+
}

app/code/Magento/Quote/Test/Fixture/SetShippingAddress.php renamed to app/code/Magento/Checkout/Test/Fixture/SetShippingAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Quote\Test\Fixture;
8+
namespace Magento\Checkout\Test\Fixture;
99

1010
use Magento\Framework\DataObject;
1111
use Magento\Quote\Api\Data\AddressInterface;

0 commit comments

Comments
 (0)