Skip to content

Commit a8cf637

Browse files
authored
Merge pull request #10156 from magento-gl/spartans_pr_27102025
[Spartans] BugFixes Delivery
2 parents 7fa400a + 6287d95 commit a8cf637

File tree

19 files changed

+2465
-317
lines changed

19 files changed

+2465
-317
lines changed

app/code/Magento/Catalog/Model/ProductLink/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function save(\Magento\Catalog\Api\Data\ProductLinkInterface $entity)
139139
. 'Please ensure the parent product SKU is provided and try again.'
140140
));
141141
}
142-
if (!$entity->getLinkedProductSku()) {
142+
if ($entity->getLinkedProductSku() === null || $entity->getLinkedProductSku() === '') {
143143
throw new CouldNotSaveException(__('The linked product SKU is invalid. Verify the data and try again.'));
144144
}
145145
$linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());

app/code/Magento/Catalog/Test/Unit/Model/ProductLink/RepositoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,16 @@ public function testDeleteWithNoSuchEntityException()
298298

299299
$this->model->delete($entityMock);
300300
}
301+
302+
public function testSaveWithNullLinkedProductSku()
303+
{
304+
$this->expectException('Magento\Framework\Exception\CouldNotSaveException');
305+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
306+
307+
$entityMock = $this->createMock(\Magento\Catalog\Model\ProductLink\Link::class);
308+
$entityMock->expects($this->any())->method('getSku')->willReturn('sku1');
309+
$entityMock->expects($this->any())->method('getLinkedProductSku')->willReturn(null);
310+
311+
$this->model->save($entityMock);
312+
}
301313
}

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Sort/Position.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function build(AttributeAdapter $attribute, string $direction, RequestInt
6969
$fieldName = $this->fieldNameResolver->getFieldName($attribute);
7070
}
7171

72+
if ($fieldName !== '_script') {
73+
$sortParams['unmapped_type'] = 'integer';
74+
}
75+
7276
return [$fieldName => $sortParams];
7377
}
7478

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/Sort/PositionTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public function testBuildWithoutCategoryIds(): void
6060
->willReturn('position_category_2');
6161

6262
$result = $this->position->build($attributeMock, 'desc', $requestMock);
63-
self::assertEquals(['position_category_2' => ['order' => 'desc']], $result);
63+
self::assertEquals(
64+
['position_category_2' => ['order' => 'desc', 'unmapped_type' => 'integer']],
65+
$result
66+
);
6467
}
6568

6669
/**
@@ -90,7 +93,10 @@ public function testBuildWithSingleCategoryId(): void
9093
->willReturn('position_category_5');
9194

9295
$result = $this->position->build($attributeMock, 'desc', $requestMock);
93-
self::assertEquals(['position_category_5' => ['order' => 'desc']], $result);
96+
self::assertEquals(
97+
['position_category_5' => ['order' => 'desc', 'unmapped_type' => 'integer']],
98+
$result
99+
);
94100
}
95101

96102
/**
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Plugin\Quote;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Payment\Helper\Data as PaymentHelper;
12+
use Magento\Quote\Api\CartRepositoryInterface;
13+
use Magento\Quote\Api\Data\PaymentInterface;
14+
use Magento\Quote\Model\QuoteManagement;
15+
16+
class ValidatePaymentOnPlaceOrder
17+
{
18+
/**
19+
* @param CartRepositoryInterface $cartRepository
20+
* @param PaymentHelper $paymentHelper
21+
*/
22+
public function __construct(
23+
private CartRepositoryInterface $cartRepository,
24+
private PaymentHelper $paymentHelper
25+
) {
26+
}
27+
28+
/**
29+
* Validate payment method
30+
*
31+
* @param QuoteManagement $subject
32+
* @param int $cartId
33+
* @param PaymentInterface|null $paymentMethod
34+
* @return array
35+
* @throws LocalizedException
36+
* @throws \Magento\Framework\Exception\NoSuchEntityException
37+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
38+
*/
39+
public function beforePlaceOrder(
40+
QuoteManagement $subject,
41+
$cartId,
42+
?PaymentInterface $paymentMethod = null
43+
): array {
44+
$quote = $this->cartRepository->getActive((int)$cartId);
45+
46+
$payment = $quote->getPayment();
47+
$code = $paymentMethod?->getMethod() ?: $payment->getMethod();
48+
49+
if (!$code) {
50+
return [$cartId, $paymentMethod];
51+
}
52+
53+
$methodInstance = $this->paymentHelper->getMethodInstance($code);
54+
$methodInstance->setInfoInstance($payment);
55+
56+
if (!$methodInstance->isAvailable($quote)) {
57+
throw new LocalizedException(__('The requested Payment Method is not available.'));
58+
}
59+
60+
return [$cartId, $paymentMethod];
61+
}
62+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\QuoteGraphQl\Plugin;
9+
10+
use Magento\Quote\Model\ValidationRules\ShippingMethodValidationRule;
11+
use Magento\Quote\Model\Quote;
12+
use Magento\Framework\Validation\ValidationResult;
13+
use Magento\Framework\Validation\ValidationResultFactory;
14+
15+
class ShippingMethodValidationRulePlugin
16+
{
17+
/**
18+
* @var ValidationResultFactory
19+
*/
20+
private $validationResultFactory;
21+
22+
/**
23+
* @param ValidationResultFactory $validationResultFactory
24+
*/
25+
public function __construct(ValidationResultFactory $validationResultFactory)
26+
{
27+
$this->validationResultFactory = $validationResultFactory;
28+
}
29+
30+
/**
31+
* After plugin for validate method to ensure shipping method validity.
32+
*
33+
* @param ShippingMethodValidationRule $subject
34+
* @param ValidationResult[] $result
35+
* @param Quote $quote
36+
* @return ValidationResult[]
37+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
38+
*/
39+
public function afterValidate(
40+
ShippingMethodValidationRule $subject,
41+
array $result,
42+
Quote $quote
43+
): array {
44+
$shippingAddress = $quote->getShippingAddress();
45+
if (!$shippingAddress || $quote->isVirtual()) {
46+
return $result;
47+
}
48+
49+
$shippingMethod = $shippingAddress->getShippingMethod();
50+
$shippingRate = $shippingMethod ? $shippingAddress->getShippingRateByCode($shippingMethod) : null;
51+
$validationResult = $shippingMethod && $shippingRate && $shippingAddress->requestShippingRates();
52+
53+
if ($validationResult) {
54+
return $result;
55+
}
56+
57+
$existing = $result[0] ?? null;
58+
if ($existing instanceof ValidationResult && $existing->isValid()) {
59+
$result[0] = $this->validationResultFactory->create([
60+
'errors' => [__('The shipping method is missing. Select the shipping method and try again')]
61+
]);
62+
}
63+
64+
return $result;
65+
}
66+
}

0 commit comments

Comments
 (0)