Skip to content

Commit 9b8e3fd

Browse files
merge magento-commerce/2.4-develop into magento-tsg/2.4-develop-pr131
2 parents 1c3af20 + 1b4ecb5 commit 9b8e3fd

File tree

6 files changed

+559
-24
lines changed

6 files changed

+559
-24
lines changed

app/code/Magento/Bundle/Model/Product/BundleOptionDataProvider.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Bundle\Model\Option;
1212
use Magento\Catalog\Model\Product;
1313
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
14+
use Magento\Framework\GraphQl\Query\Uid;
1415
use Magento\Framework\Pricing\Helper\Data;
1516
use Magento\Framework\Serialize\SerializerInterface;
1617

@@ -19,6 +20,11 @@
1920
*/
2021
class BundleOptionDataProvider
2122
{
23+
/**
24+
* Option type name
25+
*/
26+
private const OPTION_TYPE = 'bundle';
27+
2228
/**
2329
* @var Data
2430
*/
@@ -34,19 +40,27 @@ class BundleOptionDataProvider
3440
*/
3541
private $configuration;
3642

43+
/**
44+
* @var Uid
45+
*/
46+
private $uidEncoder;
47+
3748
/**
3849
* @param Data $pricingHelper
3950
* @param SerializerInterface $serializer
4051
* @param Configuration $configuration
52+
* @param Uid $uidEncoder
4153
*/
4254
public function __construct(
4355
Data $pricingHelper,
4456
SerializerInterface $serializer,
45-
Configuration $configuration
57+
Configuration $configuration,
58+
Uid $uidEncoder
4659
) {
4760
$this->pricingHelper = $pricingHelper;
4861
$this->serializer = $serializer;
4962
$this->configuration = $configuration;
63+
$this->uidEncoder = $uidEncoder;
5064
}
5165

5266
/**
@@ -100,8 +114,15 @@ private function buildBundleOptions(array $bundleOptions, ItemInterface $item):
100114
continue;
101115
}
102116

117+
$optionDetails = [
118+
self::OPTION_TYPE,
119+
$bundleOption->getOptionId()
120+
];
121+
$uidString = implode('/', $optionDetails);
122+
103123
$options[] = [
104124
'id' => $bundleOption->getId(),
125+
'uid' => $this->uidEncoder->encode($uidString),
105126
'label' => $bundleOption->getTitle(),
106127
'type' => $bundleOption->getType(),
107128
'values' => $this->buildBundleOptionValues($bundleOption->getSelections(), $item),
@@ -130,10 +151,19 @@ private function buildBundleOptionValues(array $selections, ItemInterface $item)
130151
continue;
131152
}
132153

154+
$optionValueDetails = [
155+
self::OPTION_TYPE,
156+
$selection->getOptionId(),
157+
$selection->getSelectionId(),
158+
(int) $selection->getSelectionQty()
159+
];
160+
$uidString = implode('/', $optionValueDetails);
161+
133162
$selectionPrice = $this->configuration->getSelectionFinalPrice($item, $selection);
134163
$values[] = [
135-
'label' => $selection->getName(),
136164
'id' => $selection->getSelectionId(),
165+
'uid' => $this->uidEncoder->encode($uidString),
166+
'label' => $selection->getName(),
137167
'quantity' => $qty,
138168
'price' => $this->pricingHelper->currency($selectionPrice, false, false),
139169
];

app/code/Magento/QuoteGraphQl/Model/Resolver/PlaceOrder.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717
use Magento\Quote\Api\CartManagementInterface;
18+
use Magento\Quote\Api\PaymentMethodManagementInterface;
1819
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
1920
use Magento\Sales\Api\OrderRepositoryInterface;
2021
use Magento\QuoteGraphQl\Model\Cart\CheckCartCheckoutAllowance;
@@ -44,22 +45,30 @@ class PlaceOrder implements ResolverInterface
4445
*/
4546
private $checkCartCheckoutAllowance;
4647

48+
/**
49+
* @var PaymentMethodManagementInterface
50+
*/
51+
private $paymentMethodManagement;
52+
4753
/**
4854
* @param GetCartForUser $getCartForUser
4955
* @param CartManagementInterface $cartManagement
5056
* @param OrderRepositoryInterface $orderRepository
5157
* @param CheckCartCheckoutAllowance $checkCartCheckoutAllowance
58+
* @param PaymentMethodManagementInterface $paymentMethodManagement
5259
*/
5360
public function __construct(
5461
GetCartForUser $getCartForUser,
5562
CartManagementInterface $cartManagement,
5663
OrderRepositoryInterface $orderRepository,
57-
CheckCartCheckoutAllowance $checkCartCheckoutAllowance
64+
CheckCartCheckoutAllowance $checkCartCheckoutAllowance,
65+
PaymentMethodManagementInterface $paymentMethodManagement
5866
) {
5967
$this->getCartForUser = $getCartForUser;
6068
$this->cartManagement = $cartManagement;
6169
$this->orderRepository = $orderRepository;
6270
$this->checkCartCheckoutAllowance = $checkCartCheckoutAllowance;
71+
$this->paymentMethodManagement = $paymentMethodManagement;
6372
}
6473

6574
/**
@@ -84,7 +93,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8493
}
8594

8695
try {
87-
$orderId = $this->cartManagement->placeOrder($cart->getId());
96+
$cartId = $cart->getId();
97+
$orderId = $this->cartManagement->placeOrder($cartId, $this->paymentMethodManagement->get($cartId));
8898
$order = $this->orderRepository->get($orderId);
8999

90100
return [

app/code/Magento/WishlistGraphQl/Model/Resolver/UpdateProductsInWishlist.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
use Magento\Framework\GraphQl\Config\Element\Field;
1111
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1314
use Magento\Framework\GraphQl\Query\ResolverInterface;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
1617
use Magento\Wishlist\Model\Wishlist;
1718
use Magento\Wishlist\Model\Wishlist\Config as WishlistConfig;
1819
use Magento\Wishlist\Model\Wishlist\Data\Error;
1920
use Magento\Wishlist\Model\Wishlist\Data\WishlistItemFactory;
20-
use Magento\Wishlist\Model\Wishlist\UpdateProductsInWishlist as UpdateProductsInWishlistModel;
2121
use Magento\Wishlist\Model\WishlistFactory;
2222
use Magento\WishlistGraphQl\Mapper\WishlistDataMapper;
23+
use Magento\WishlistGraphQl\Model\UpdateWishlistItem;
2324

2425
/**
2526
* Update wishlist items resolver
2627
*/
2728
class UpdateProductsInWishlist implements ResolverInterface
2829
{
2930
/**
30-
* @var UpdateProductsInWishlistModel
31+
* @var UpdateWishlistItem
3132
*/
32-
private $updateProductsInWishlist;
33+
private $updateWishlistItem;
3334

3435
/**
3536
* @var WishlistDataMapper
@@ -55,20 +56,20 @@ class UpdateProductsInWishlist implements ResolverInterface
5556
* @param WishlistResourceModel $wishlistResource
5657
* @param WishlistFactory $wishlistFactory
5758
* @param WishlistConfig $wishlistConfig
58-
* @param UpdateProductsInWishlistModel $updateProductsInWishlist
59+
* @param UpdateWishlistItem $updateWishlistItem
5960
* @param WishlistDataMapper $wishlistDataMapper
6061
*/
6162
public function __construct(
6263
WishlistResourceModel $wishlistResource,
6364
WishlistFactory $wishlistFactory,
6465
WishlistConfig $wishlistConfig,
65-
UpdateProductsInWishlistModel $updateProductsInWishlist,
66+
UpdateWishlistItem $updateWishlistItem,
6667
WishlistDataMapper $wishlistDataMapper
6768
) {
6869
$this->wishlistResource = $wishlistResource;
6970
$this->wishlistFactory = $wishlistFactory;
7071
$this->wishlistConfig = $wishlistConfig;
71-
$this->updateProductsInWishlist = $updateProductsInWishlist;
72+
$this->updateWishlistItem = $updateWishlistItem;
7273
$this->wishlistDataMapper = $wishlistDataMapper;
7374
}
7475

@@ -83,34 +84,32 @@ public function resolve(
8384
array $args = null
8485
) {
8586
if (!$this->wishlistConfig->isEnabled()) {
86-
throw new GraphQlInputException(__('The wishlist configuration is currently disabled.'));
87+
throw new GraphQlInputException(__('The wishlist configuration is currently disabled'));
8788
}
8889

8990
$customerId = $context->getUserId();
9091

91-
/* Guest checking */
9292
if (null === $customerId || $customerId === 0) {
9393
throw new GraphQlAuthorizationException(__('The current user cannot perform operations on wishlist'));
9494
}
9595

96-
$wishlistId = ((int) $args['wishlistId']) ?: null;
97-
$wishlist = $this->getWishlist($wishlistId, $customerId);
96+
$wishlist = $this->getWishlist((int) $args['wishlistId'], $customerId);
9897

9998
if (null === $wishlist->getId() || $customerId !== (int) $wishlist->getCustomerId()) {
100-
throw new GraphQlInputException(__('The wishlist was not found.'));
99+
throw new GraphQlInputException(__('Could not find the specified wishlist'));
101100
}
102101

103-
$wishlistItems = $args['wishlistItems'];
104-
$wishlistItems = $this->getWishlistItems($wishlistItems, $wishlist);
105-
$wishlistOutput = $this->updateProductsInWishlist->execute($wishlist, $wishlistItems);
102+
$wishlistItems = $this->getWishlistItems($args['wishlistItems'], $wishlist);
106103

107-
if (count($wishlistOutput->getErrors()) !== count($wishlistItems)) {
108-
$this->wishlistResource->save($wishlist);
104+
foreach ($wishlistItems as $wishlistItem) {
105+
$this->updateWishlistItem->execute($wishlistItem, $wishlist);
109106
}
110107

108+
$wishlistOutput = $this->updateWishlistItem->prepareOutput($wishlist);
109+
111110
return [
112111
'wishlist' => $this->wishlistDataMapper->map($wishlistOutput->getWishlist()),
113-
'user_errors' => \array_map(
112+
'user_errors' => array_map(
114113
function (Error $error) {
115114
return [
116115
'code' => $error->getCode(),
@@ -133,7 +132,6 @@ function (Error $error) {
133132
private function getWishlistItems(array $wishlistItemsData, Wishlist $wishlist): array
134133
{
135134
$wishlistItems = [];
136-
137135
foreach ($wishlistItemsData as $wishlistItemData) {
138136
if (!isset($wishlistItemData['quantity'])) {
139137
$wishlistItem = $wishlist->getItem($wishlistItemData['wishlist_item_id']);
@@ -149,7 +147,6 @@ private function getWishlistItems(array $wishlistItemsData, Wishlist $wishlist):
149147
}
150148
$wishlistItems[] = (new WishlistItemFactory())->create($wishlistItemData);
151149
}
152-
153150
return $wishlistItems;
154151
}
155152

0 commit comments

Comments
 (0)