Skip to content

Commit 79bc637

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 979b221 + 2130fe0 commit 79bc637

File tree

37 files changed

+2632
-254
lines changed

37 files changed

+2632
-254
lines changed

app/code/Magento/CatalogGraphQl/Model/Product/Option/DateType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ private function formatValues($values)
4545
{
4646
if (isset($values[$this->getOption()->getId()])) {
4747
$value = $values[$this->getOption()->getId()];
48+
if (isset($value['date']) || isset($value['day'], $value['month'], $value['year'])) {
49+
return $values;
50+
}
4851
$dateTime = \DateTime::createFromFormat(DateTime::DATETIME_PHP_FORMAT, $value);
4952

5053
if ($dateTime === false) {

app/code/Magento/ConfigurableProduct/Test/Mftf/Test/StorefrontGalleryConfigurableProductWithSeveralAttributesTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<group value="catalog"/>
2020
<group value="configurableProduct"/>
2121
<group value="swatch"/>
22+
<skip>
23+
<issueId value="MC-32197"/>
24+
</skip>
2225
</annotations>
2326
<before>
2427
<createData entity="ProductVideoYoutubeApiKeyConfig" stepKey="setupYoutubeApiKey"/>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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\Quote\Model\Cart;
9+
10+
use Magento\Framework\Exception\AlreadyExistsException;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Quote\Api\CartManagementInterface;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\QuoteIdMaskFactory;
15+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
16+
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
17+
18+
/**
19+
* Get customer cart or create empty cart. Ensure mask_id is created
20+
*/
21+
class CustomerCartResolver
22+
{
23+
/**
24+
* @var CartManagementInterface
25+
*/
26+
private $cartManagement;
27+
28+
/**
29+
* @var QuoteIdMaskFactory
30+
*/
31+
private $quoteIdMaskFactory;
32+
33+
/**
34+
* @var QuoteIdMaskResourceModel
35+
*/
36+
private $quoteIdMaskResourceModel;
37+
38+
/**
39+
* @var QuoteIdToMaskedQuoteIdInterface
40+
*/
41+
private $quoteIdToMaskedQuoteId;
42+
43+
/**
44+
* @param CartManagementInterface $cartManagement
45+
* @param QuoteIdMaskFactory $quoteIdMaskFactory
46+
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
47+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
48+
*/
49+
public function __construct(
50+
CartManagementInterface $cartManagement,
51+
QuoteIdMaskFactory $quoteIdMaskFactory,
52+
QuoteIdMaskResourceModel $quoteIdMaskResourceModel,
53+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
54+
) {
55+
$this->cartManagement = $cartManagement;
56+
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
57+
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel;
58+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
59+
}
60+
61+
/**
62+
* Get customer cart by customer id with predefined masked quote id
63+
*
64+
* @param int $customerId
65+
* @param string|null $predefinedMaskedQuoteId
66+
* @return Quote
67+
* @throws NoSuchEntityException
68+
* @throws \Magento\Framework\Exception\CouldNotSaveException
69+
*/
70+
public function resolve(int $customerId, string $predefinedMaskedQuoteId = null): Quote
71+
{
72+
try {
73+
/** @var Quote $cart */
74+
$cart = $this->cartManagement->getCartForCustomer($customerId);
75+
} catch (NoSuchEntityException $e) {
76+
$this->cartManagement->createEmptyCartForCustomer($customerId);
77+
$cart = $this->cartManagement->getCartForCustomer($customerId);
78+
}
79+
try {
80+
$this->ensureQuoteMaskIdExist((int)$cart->getId(), $predefinedMaskedQuoteId);
81+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
82+
} catch (AlreadyExistsException $e) {
83+
// do nothing, we already have masked id
84+
}
85+
86+
return $cart;
87+
}
88+
89+
/**
90+
* Create masked id for customer's active quote if it's not exists
91+
*
92+
* @param int $quoteId
93+
* @param string|null $predefinedMaskedQuoteId
94+
* @return void
95+
* @throws AlreadyExistsException
96+
*/
97+
private function ensureQuoteMaskIdExist(int $quoteId, string $predefinedMaskedQuoteId = null): void
98+
{
99+
try {
100+
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
101+
} catch (NoSuchEntityException $e) {
102+
$maskedId = '';
103+
}
104+
if ($maskedId === '') {
105+
$quoteIdMask = $this->quoteIdMaskFactory->create();
106+
$quoteIdMask->setQuoteId($quoteId);
107+
if (null !== $predefinedMaskedQuoteId) {
108+
$quoteIdMask->setMaskedId($predefinedMaskedQuoteId);
109+
}
110+
$this->quoteIdMaskResourceModel->save($quoteIdMask);
111+
}
112+
}
113+
}

app/code/Magento/Quote/Model/Quote.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,8 @@ public function beforeSave()
865865
}
866866

867867
parent::beforeSave();
868+
869+
return $this;
868870
}
869871

870872
/**
@@ -945,8 +947,8 @@ public function assignCustomerWithAddressChange(
945947
} else {
946948
try {
947949
$defaultBillingAddress = $this->addressRepository->getById($customer->getDefaultBilling());
950+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
948951
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
949-
//
950952
}
951953
if (isset($defaultBillingAddress)) {
952954
/** @var \Magento\Quote\Model\Quote\Address $billingAddress */
@@ -959,8 +961,8 @@ public function assignCustomerWithAddressChange(
959961
if (null === $shippingAddress) {
960962
try {
961963
$defaultShippingAddress = $this->addressRepository->getById($customer->getDefaultShipping());
964+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
962965
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
963-
//
964966
}
965967
if (isset($defaultShippingAddress)) {
966968
/** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
@@ -1679,12 +1681,14 @@ public function addProduct(
16791681

16801682
// collect errors instead of throwing first one
16811683
if ($item->getHasError()) {
1684+
$this->deleteItem($item);
16821685
foreach ($item->getMessage(false) as $message) {
16831686
if (!in_array($message, $errors)) {
16841687
// filter duplicate messages
16851688
$errors[] = $message;
16861689
}
16871690
}
1691+
break;
16881692
}
16891693
}
16901694
if (!empty($errors)) {

app/code/Magento/QuoteGraphQl/Model/Cart/CreateEmptyCartForCustomer.php

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,35 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Quote\Api\CartManagementInterface;
11-
use Magento\Quote\Model\QuoteIdMask;
12-
use Magento\Quote\Model\QuoteIdMaskFactory;
1310
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
14-
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
11+
use Magento\Quote\Model\Cart\CustomerCartResolver;
1512

1613
/**
1714
* Create empty cart for customer
15+
* Masked quote ID will be returned as a result
1816
*/
1917
class CreateEmptyCartForCustomer
2018
{
2119
/**
22-
* @var CartManagementInterface
23-
*/
24-
private $cartManagement;
25-
26-
/**
27-
* @var QuoteIdMaskFactory
28-
*/
29-
private $quoteIdMaskFactory;
30-
31-
/**
32-
* @var QuoteIdMaskResourceModel
20+
* @var QuoteIdToMaskedQuoteIdInterface
3321
*/
34-
private $quoteIdMaskResourceModel;
22+
private $quoteIdToMaskedQuoteId;
3523

3624
/**
37-
* @var QuoteIdToMaskedQuoteIdInterface
25+
* @var CustomerCartResolver
3826
*/
39-
private $quoteIdToMaskedQuoteId;
27+
private $cartResolver;
4028

4129
/**
42-
* @param CartManagementInterface $cartManagement
43-
* @param QuoteIdMaskFactory $quoteIdMaskFactory
44-
* @param QuoteIdMaskResourceModel $quoteIdMaskResourceModel
4530
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
31+
* @param CustomerCartResolver $cartResolver
4632
*/
4733
public function __construct(
48-
CartManagementInterface $cartManagement,
49-
QuoteIdMaskFactory $quoteIdMaskFactory,
50-
QuoteIdMaskResourceModel $quoteIdMaskResourceModel,
51-
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
34+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId,
35+
CustomerCartResolver $cartResolver
5236
) {
53-
$this->cartManagement = $cartManagement;
54-
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
55-
$this->quoteIdMaskResourceModel = $quoteIdMaskResourceModel;
5637
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
38+
$this->cartResolver = $cartResolver;
5739
}
5840

5941
/**
@@ -62,59 +44,14 @@ public function __construct(
6244
* @param int $customerId
6345
* @param string|null $predefinedMaskedQuoteId
6446
* @return string
65-
*/
66-
public function execute(int $customerId, string $predefinedMaskedQuoteId = null): string
67-
{
68-
$quoteId = (int) $this->cartManagement->createEmptyCartForCustomer($customerId);
69-
70-
if ($predefinedMaskedQuoteId !== null) {
71-
$maskedId = $this->createPredefinedMaskId($quoteId, $predefinedMaskedQuoteId);
72-
} else {
73-
$maskedId = $this->getQuoteMaskId($quoteId);
74-
}
75-
76-
return $maskedId;
77-
}
78-
79-
/**
80-
* Create quote masked id from predefined value
81-
*
82-
* @param int $quoteId
83-
* @param string $maskId
84-
* @return string
85-
* @throws \Magento\Framework\Exception\AlreadyExistsException
86-
*/
87-
private function createPredefinedMaskId(int $quoteId, string $maskId): string
88-
{
89-
/** @var QuoteIdMask $quoteIdMask */
90-
$quoteIdMask = $this->quoteIdMaskFactory->create();
91-
$quoteIdMask->setQuoteId($quoteId);
92-
$quoteIdMask->setMaskedId($maskId);
93-
94-
$this->quoteIdMaskResourceModel->save($quoteIdMask);
95-
96-
return $quoteIdMask->getMaskedId();
97-
}
98-
99-
/**
100-
* Fetch or create masked id for customer's active quote
101-
*
102-
* @param int $quoteId
103-
* @return string
104-
* @throws \Magento\Framework\Exception\AlreadyExistsException
47+
* @throws \Magento\Framework\Exception\CouldNotSaveException
10548
* @throws \Magento\Framework\Exception\NoSuchEntityException
10649
*/
107-
private function getQuoteMaskId(int $quoteId): string
50+
public function execute(int $customerId, string $predefinedMaskedQuoteId = null): string
10851
{
109-
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
110-
if ($maskedId === '') {
111-
$quoteIdMask = $this->quoteIdMaskFactory->create();
112-
$quoteIdMask->setQuoteId($quoteId);
113-
114-
$this->quoteIdMaskResourceModel->save($quoteIdMask);
115-
$maskedId = $quoteIdMask->getMaskedId();
116-
}
52+
$cart = $this->cartResolver->resolve($customerId, $predefinedMaskedQuoteId);
53+
$quoteId = (int) $cart->getId();
11754

118-
return $maskedId;
55+
return $this->quoteIdToMaskedQuoteId->execute($quoteId);
11956
}
12057
}

0 commit comments

Comments
 (0)