Skip to content

Commit 594a590

Browse files
authored
Merge pull request #8698 from magento-lynx/LYNX-311-DELIVERY
[LYNX] Multicoupon delivery PR
2 parents ccaba6d + 9e3bc87 commit 594a590

30 files changed

+3095
-489
lines changed

app/code/Magento/Catalog/Test/Fixture/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Product implements RevertibleDataFixtureInterface
5353
'media_gallery_entries' => [],
5454
'tier_prices' => [],
5555
'created_at' => null,
56-
'updated_at' => null,
56+
'updated_at' => null
5757
];
5858

5959
private const DEFAULT_PRODUCT_LINK_DATA = [

app/code/Magento/Catalog/Test/Fixture/ProductStock.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class ProductStock implements DataFixtureInterface
2626
{
2727
private const DEFAULT_DATA = [
2828
'prod_id' => null,
29-
'prod_qty' => 1
29+
'prod_qty' => 1,
30+
'is_in_stock' => 1
3031
];
3132

3233
/**
@@ -67,8 +68,8 @@ public function apply(array $data = []): ?DataObject
6768
{
6869
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
6970
$stockItem = $this->stockRegistry->getStockItem($data['prod_id']);
70-
$stockItem->setData('is_in_stock', 1);
71-
$stockItem->setData('qty', 90);
71+
$stockItem->setData('is_in_stock', $data['is_in_stock']);
72+
$stockItem->setData('qty', $data['prod_qty']);
7273
$stockItem->setData('manage_stock', 1);
7374
$stockItem->save();
7475

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\GiftMessage\Test\Fixture;
18+
19+
use Magento\Framework\DataObject;
20+
use Magento\TestFramework\Fixture\Api\DataMerger;
21+
use Magento\GiftMessage\Model\ResourceModel\Message;
22+
use Magento\GiftMessage\Model\MessageFactory;
23+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
24+
25+
class GiftMessage implements RevertibleDataFixtureInterface
26+
{
27+
private const DEFAULT_DATA = [
28+
'sender' => 'Romeo',
29+
'recipient' => 'Mercutio',
30+
'message' => 'Fixture Test message.',
31+
];
32+
33+
/**
34+
* @param MessageFactory $giftMessageFactory
35+
* @param Message $messageResourceModel
36+
* @param DataMerger $dataMerger
37+
*/
38+
public function __construct(
39+
private readonly MessageFactory $giftMessageFactory,
40+
private readonly Message $messageResourceModel,
41+
private readonly DataMerger $dataMerger,
42+
) {
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function apply(array $data = []): ?DataObject
49+
{
50+
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
51+
$message = $this->giftMessageFactory->create();
52+
$message
53+
->setSender($data['sender'])
54+
->setRecipient($data['recipient'])
55+
->setMessage($data['message']);
56+
57+
$this->messageResourceModel->save($message);
58+
59+
return $message;
60+
}
61+
62+
/**
63+
* @inheritdoc
64+
*/
65+
public function revert(DataObject $data): void
66+
{
67+
$this->messageResourceModel->delete($data);
68+
}
69+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\OfflineShipping\Test\Fixture;
18+
19+
use Magento\Framework\DataObject;
20+
use Magento\TestFramework\Fixture\Api\ServiceFactory;
21+
use Magento\TestFramework\Fixture\Api\DataMerger;
22+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
use Magento\Framework\ObjectManagerInterface;
25+
use Magento\Framework\App\ResourceConnection;
26+
use Magento\Framework\DB\Adapter\AdapterInterface;
27+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
28+
29+
class TablerateFixture implements RevertibleDataFixtureInterface
30+
{
31+
private const DEFAULT_DATA = [
32+
'website_id' => 1,
33+
'dest_country_id' => 'US',
34+
'dest_region_id' => 0,
35+
'dest_zip' => '*',
36+
'condition_name' => 'package_qty',
37+
'condition_value' => 1,
38+
'price' => 10,
39+
'cost' => 0
40+
];
41+
42+
/**
43+
* @var AdapterInterface $connection
44+
*/
45+
private AdapterInterface $connection;
46+
47+
/**
48+
* @var ObjectManagerInterface $objectManager
49+
*/
50+
private ObjectManagerInterface $objectManager;
51+
52+
/**
53+
* @param ServiceFactory $serviceFactory
54+
* @param DataMerger $dataMerger
55+
*/
56+
public function __construct(
57+
private ServiceFactory $serviceFactory,
58+
private DataMerger $dataMerger,
59+
) {
60+
$this->objectManager = Bootstrap::getObjectManager();
61+
$this->connection = $this->objectManager->get(ResourceConnection::class)->getConnection();
62+
}
63+
64+
/**
65+
* @inheritDoc
66+
*/
67+
public function apply(array $data = []): ?DataObject
68+
{
69+
$resourceModel = $this->objectManager->create(Tablerate::class);
70+
$data = $this->dataMerger->merge($this::DEFAULT_DATA, $data);
71+
$columns = [
72+
'website_id',
73+
'dest_country_id',
74+
'dest_region_id',
75+
'dest_zip',
76+
'condition_name',
77+
'condition_value',
78+
'price',
79+
'cost'
80+
];
81+
$resourceModel->getConnection()->insertArray(
82+
$resourceModel->getMainTable(),
83+
$columns,
84+
[
85+
$data
86+
]
87+
);
88+
return new DataObject($data);
89+
}
90+
91+
/**
92+
* @inheritDoc
93+
*/
94+
public function revert(DataObject $data): void
95+
{
96+
$resourceModel = $this->objectManager->create(Tablerate::class);
97+
$this->connection->query("DELETE FROM {$resourceModel->getTable('shipping_tablerate')};");
98+
}
99+
}

app/code/Magento/Quote/Test/Fixture/CustomerCart.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
class CustomerCart implements RevertibleDataFixtureInterface
1616
{
1717
private const DEFAULT_DATA = [
18-
'customer_id' => null
18+
'customer_id' => null,
19+
'reserved_order_id' => null
1920
];
2021

2122
/**
@@ -53,8 +54,13 @@ public function apply(array $data = []): ?DataObject
5354
{
5455
$data = array_merge(self::DEFAULT_DATA, $data);
5556
$cartId = $this->cartManagement->createEmptyCartForCustomer($data['customer_id']);
57+
$cart = $this->cartRepository->get($cartId);
58+
if (isset($data['reserved_order_id'])) {
59+
$cart->setReservedOrderId($data['reserved_order_id']);
60+
$this->cartRepository->save($cart);
61+
}
5662

57-
return $this->cartRepository->get($cartId);
63+
return $cart;
5864
}
5965

6066
/**

app/code/Magento/Quote/Test/Fixture/GuestCart.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,21 @@ public function apply(array $data = []): ?DataObject
7171
{
7272
$maskId = $this->guestCartManagement->createEmptyCart();
7373
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskId);
74+
$cart = $this->cartRepository->get($cartId);
7475

75-
return $this->cartRepository->get($cartId);
76+
if (!isset($data['reserved_order_id']) && !isset($data['message_id'])) {
77+
return $cart;
78+
}
79+
if (isset($data['reserved_order_id'])) {
80+
$cart->setReservedOrderId($data['reserved_order_id']);
81+
$this->cartRepository->save($cart);
82+
}
83+
if (isset($data['message_id'])) {
84+
$cart->setGiftMessageId($data['message_id']);
85+
$this->cartRepository->save($cart);
86+
}
87+
88+
return $cart;
7689
}
7790

7891
/**
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\QuoteGraphQl\Model\CartItem;
18+
19+
use Magento\Catalog\Api\Data\ProductInterface;
20+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
21+
use Magento\Quote\Model\Quote;
22+
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory as ItemCollectionFactory;
23+
24+
/**
25+
* Fetch Cart items and product models corresponding to a cart
26+
*/
27+
class GetPaginatedCartItems
28+
{
29+
/**
30+
* @param ProductCollectionFactory $productCollectionFactory
31+
* @param ItemCollectionFactory $itemCollectionFactory
32+
*/
33+
public function __construct(
34+
private readonly ProductCollectionFactory $productCollectionFactory,
35+
private readonly ItemCollectionFactory $itemCollectionFactory
36+
) {
37+
}
38+
39+
/**
40+
* Get product models based on items in cart
41+
*
42+
* @param array $cartProductsIds
43+
* @return ProductInterface[]
44+
*/
45+
private function getCartProduct(array $cartProductsIds): array
46+
{
47+
if (empty($cartProductsIds)) {
48+
return [];
49+
}
50+
/** @var \Magento\Framework\Data\Collection $productCollection */
51+
$productCollection = $this->productCollectionFactory->create()
52+
->addAttributeToSelect('*')
53+
->addIdFilter($cartProductsIds)
54+
->setFlag('has_stock_status_filter', true);
55+
56+
return $productCollection->getItems();
57+
}
58+
59+
/**
60+
* Get visible cart items and product data for cart items
61+
*
62+
* @param Quote $cart
63+
* @param int $pageSize
64+
* @param int $offset
65+
* @return array
66+
*/
67+
public function execute(Quote $cart, int $pageSize, int $offset): array
68+
{
69+
$result = [];
70+
if (!$cart->getId()) {
71+
return $result;
72+
}
73+
/** @var \Magento\Framework\Data\Collection $itemCollection */
74+
$itemCollection = $this->itemCollectionFactory->create()
75+
->addFieldToFilter('parent_item_id', ['null' => true])
76+
->addFieldToFilter('quote_id', $cart->getId())
77+
->setCurPage($offset)
78+
->setPageSize($pageSize);
79+
80+
$items = [];
81+
$cartProductsIds = [];
82+
$itemDeletedCount = 0;
83+
/** @var \Magento\Quote\Model\Quote\Item $item */
84+
foreach ($itemCollection->getItems() as $item) {
85+
if (!$item->isDeleted()) {
86+
$items[] = $item;
87+
$cartProductsIds[] = $item->getProduct()->getId();
88+
} else {
89+
$itemDeletedCount++;
90+
}
91+
}
92+
$result['total'] = $itemCollection->getSize() - $itemDeletedCount;
93+
$result['items'] = $items;
94+
$result['products'] = $this->getCartProduct($cartProductsIds);
95+
return $result;
96+
}
97+
}

0 commit comments

Comments
 (0)