Skip to content

Commit 99f3426

Browse files
authored
Merge branch '2.4-develop' into 247beta3_jan
2 parents 47cf97b + 7e0fc6b commit 99f3426

File tree

33 files changed

+1631
-606
lines changed

33 files changed

+1631
-606
lines changed

app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,25 @@
1111
use Magento\OfflineShipping\Model\SalesRule\ExtendedCalculator;
1212
use Magento\Quote\Model\Quote\Address\FreeShippingInterface;
1313
use Magento\Quote\Model\Quote\Item\AbstractItem;
14-
use Magento\Store\Model\StoreManagerInterface;
1514

1615
class FreeShipping implements FreeShippingInterface
1716
{
1817
/**
19-
* @var ExtendedCalculator
18+
* @var Calculator
2019
*/
2120
protected $calculator;
2221

2322
/**
24-
* @var StoreManagerInterface
25-
*/
26-
protected $storeManager;
27-
28-
/**
29-
* @param StoreManagerInterface $storeManager
3023
* @param Calculator $calculator
3124
*/
3225
public function __construct(
33-
StoreManagerInterface $storeManager,
3426
Calculator $calculator
3527
) {
36-
$this->storeManager = $storeManager;
3728
$this->calculator = $calculator;
3829
}
3930

4031
/**
41-
* {@inheritDoc}
32+
* @inheritdoc
4233
*/
4334
public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
4435
{
@@ -49,12 +40,7 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
4940

5041
$result = false;
5142
$addressFreeShipping = true;
52-
$store = $this->storeManager->getStore($quote->getStoreId());
53-
$this->calculator->init(
54-
$store->getWebsiteId(),
55-
$quote->getCustomerGroupId(),
56-
$quote->getCouponCode()
57-
);
43+
$this->calculator->initFromQuote($quote);
5844
$shippingAddress = $quote->getShippingAddress();
5945
$shippingAddress->setFreeShipping(0);
6046
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
@@ -88,6 +74,8 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
8874
}
8975

9076
/**
77+
* Apply free shipping to quote item child items
78+
*
9179
* @param AbstractItem $item
9280
* @param bool $isFreeShipping
9381
* @return void

app/code/Magento/OfflineShipping/Model/SalesRule/Calculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function processFreeShipping(\Magento\Quote\Model\Quote\Item\AbstractItem
3232
$address = $item->getAddress();
3333
$item->setFreeShipping(false);
3434

35-
foreach ($this->_getRules($address) as $rule) {
35+
foreach ($this->getRules($address) as $rule) {
3636
/* @var $rule \Magento\SalesRule\Model\Rule */
3737
if (!$this->validatorUtility->canProcessRule($rule, $address)) {
3838
continue;

app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Quote\Model\Quote\Address;
1414
use Magento\Quote\Model\Quote\Item;
1515
use Magento\Store\Api\Data\StoreInterface;
16-
use Magento\Store\Model\StoreManagerInterface;
1716
use PHPUnit\Framework\MockObject\MockObject;
1817
use PHPUnit\Framework\TestCase;
1918

@@ -22,36 +21,41 @@
2221
*/
2322
class FreeShippingTest extends TestCase
2423
{
24+
/**
25+
* @var int
26+
*/
2527
private static $websiteId = 1;
2628

29+
/**
30+
* @var int
31+
*/
2732
private static $customerGroupId = 2;
2833

34+
/**
35+
* @var int
36+
*/
2937
private static $couponCode = 3;
3038

39+
/**
40+
* @var int
41+
*/
3142
private static $storeId = 1;
3243

3344
/**
3445
* @var FreeShipping
3546
*/
3647
private $model;
3748

38-
/**
39-
* @var MockObject|StoreManagerInterface
40-
*/
41-
private $storeManager;
42-
4349
/**
4450
* @var MockObject|Calculator
4551
*/
4652
private $calculator;
4753

4854
protected function setUp(): void
4955
{
50-
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
5156
$this->calculator = $this->createMock(Calculator::class);
5257

5358
$this->model = new FreeShipping(
54-
$this->storeManager,
5559
$this->calculator
5660
);
5761
}
@@ -74,8 +78,8 @@ public function testIsFreeShipping(int $addressFree, int $fItemFree, int $sItemF
7478
$sItem = $this->getItem($quote);
7579
$items = [$fItem, $sItem];
7680

77-
$this->calculator->method('init')
78-
->with(self::$websiteId, self::$customerGroupId, self::$couponCode);
81+
$this->calculator->method('initFromQuote')
82+
->with($this->getQuote($this->getShippingAddress()));
7983
$this->calculator->method('processFreeShipping')
8084
->withConsecutive(
8185
[$fItem],
@@ -118,9 +122,6 @@ private function withStore()
118122
$store = $this->getMockBuilder(StoreInterface::class)
119123
->disableOriginalConstructor()
120124
->getMockForAbstractClass();
121-
$this->storeManager->method('getStore')
122-
->with(self::$storeId)
123-
->willReturn($store);
124125

125126
$store->method('getWebsiteId')
126127
->willReturn(self::$websiteId);

app/code/Magento/OfflineShipping/Test/Unit/Model/SalesRule/CalculatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function setUp(): void
2424
{
2525
$this->_model = $this->createPartialMock(
2626
Calculator::class,
27-
['_getRules', '__wakeup']
27+
['getRules', '__wakeup']
2828
);
2929
}
3030

@@ -40,7 +40,7 @@ public function testProcessFreeShipping()
4040
$item->expects($this->once())->method('getAddress')->willReturn($addressMock);
4141

4242
$this->_model->expects($this->once())
43-
->method('_getRules')
43+
->method('getRules')
4444
->with($addressMock)
4545
->willReturn([]);
4646

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

Lines changed: 0 additions & 60 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/CartItem/GetPaginatedCartItems.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ private function getCartProduct(array $cartProductsIds): array
6262
* @param Quote $cart
6363
* @param int $pageSize
6464
* @param int $offset
65+
* @param string $orderBy
66+
* @param string $order
6567
* @return array
6668
*/
67-
public function execute(Quote $cart, int $pageSize, int $offset): array
69+
public function execute(Quote $cart, int $pageSize, int $offset, string $orderBy, string $order): array
6870
{
6971
$result = [];
7072
if (!$cart->getId()) {
@@ -74,6 +76,7 @@ public function execute(Quote $cart, int $pageSize, int $offset): array
7476
$itemCollection = $this->itemCollectionFactory->create()
7577
->addFieldToFilter('parent_item_id', ['null' => true])
7678
->addFieldToFilter('quote_id', $cart->getId())
79+
->setOrder($orderBy, $order)
7780
->setCurPage($offset)
7881
->setPageSize($pageSize);
7982

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

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,23 @@
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1312
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use Magento\Framework\GraphQl\Query\Uid;
1615
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Magento\Quote\Model\Quote;
1816
use Magento\Quote\Model\Quote\Item as QuoteItem;
19-
use Magento\QuoteGraphQl\Model\Cart\GetCartProducts;
2017

2118
/**
2219
* @inheritdoc
2320
*/
2421
class CartItems implements ResolverInterface
2522
{
2623
/**
27-
* @var GetCartProducts
28-
*/
29-
private $getCartProducts;
30-
31-
/** @var Uid */
32-
private $uidEncoder;
33-
34-
/**
35-
* @param GetCartProducts $getCartProducts
3624
* @param Uid $uidEncoder
3725
*/
3826
public function __construct(
39-
GetCartProducts $getCartProducts,
40-
Uid $uidEncoder
27+
private readonly Uid $uidEncoder,
4128
) {
42-
$this->getCartProducts = $getCartProducts;
43-
$this->uidEncoder = $uidEncoder;
4429
}
4530

4631
/**
@@ -54,18 +39,20 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5439
$cart = $value['model'];
5540

5641
$itemsData = [];
57-
$cartProductsData = $this->getCartProductsData($cart);
5842
$cartItems = $cart->getAllVisibleItems();
43+
5944
/** @var QuoteItem $cartItem */
6045
foreach ($cartItems as $cartItem) {
61-
$productId = $cartItem->getProduct()->getId();
62-
if (!isset($cartProductsData[$productId])) {
46+
$product = $cartItem->getProduct();
47+
if ($product === null) {
6348
$itemsData[] = new GraphQlNoSuchEntityException(
6449
__("The product that was requested doesn't exist. Verify the product and try again.")
6550
);
6651
continue;
6752
}
68-
$productData = $cartProductsData[$productId];
53+
$productData = $product->getData();
54+
$productData['model'] = $product;
55+
$productData['uid'] = $this->uidEncoder->encode((string) $product->getId());
6956

7057
$itemsData[] = [
7158
'id' => $cartItem->getItemId(),
@@ -77,23 +64,4 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7764
}
7865
return $itemsData;
7966
}
80-
81-
/**
82-
* Get product data for cart items
83-
*
84-
* @param Quote $cart
85-
* @return array
86-
*/
87-
private function getCartProductsData(Quote $cart): array
88-
{
89-
$products = $this->getCartProducts->execute($cart);
90-
$productsData = [];
91-
foreach ($products as $product) {
92-
$productsData[$product->getId()] = $product->getData();
93-
$productsData[$product->getId()]['model'] = $product;
94-
$productsData[$product->getId()]['uid'] = $this->uidEncoder->encode((string) $product->getId());
95-
}
96-
97-
return $productsData;
98-
}
9967
}

0 commit comments

Comments
 (0)