Skip to content

Commit

Permalink
Merge pull request #8698 from magento-lynx/LYNX-311-DELIVERY
Browse files Browse the repository at this point in the history
[LYNX] Multicoupon delivery PR
  • Loading branch information
sivaschenko authored Feb 12, 2024
2 parents ccaba6d + 9e3bc87 commit 594a590
Show file tree
Hide file tree
Showing 30 changed files with 3,095 additions and 489 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Test/Fixture/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Product implements RevertibleDataFixtureInterface
'media_gallery_entries' => [],
'tier_prices' => [],
'created_at' => null,
'updated_at' => null,
'updated_at' => null
];

private const DEFAULT_PRODUCT_LINK_DATA = [
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Catalog/Test/Fixture/ProductStock.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ProductStock implements DataFixtureInterface
{
private const DEFAULT_DATA = [
'prod_id' => null,
'prod_qty' => 1
'prod_qty' => 1,
'is_in_stock' => 1
];

/**
Expand Down Expand Up @@ -67,8 +68,8 @@ public function apply(array $data = []): ?DataObject
{
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
$stockItem = $this->stockRegistry->getStockItem($data['prod_id']);
$stockItem->setData('is_in_stock', 1);
$stockItem->setData('qty', 90);
$stockItem->setData('is_in_stock', $data['is_in_stock']);
$stockItem->setData('qty', $data['prod_qty']);
$stockItem->setData('manage_stock', 1);
$stockItem->save();

Expand Down
69 changes: 69 additions & 0 deletions app/code/Magento/GiftMessage/Test/Fixture/GiftMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright 2023 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained from
* Adobe.
*/
declare(strict_types=1);

namespace Magento\GiftMessage\Test\Fixture;

use Magento\Framework\DataObject;
use Magento\TestFramework\Fixture\Api\DataMerger;
use Magento\GiftMessage\Model\ResourceModel\Message;
use Magento\GiftMessage\Model\MessageFactory;
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;

class GiftMessage implements RevertibleDataFixtureInterface
{
private const DEFAULT_DATA = [
'sender' => 'Romeo',
'recipient' => 'Mercutio',
'message' => 'Fixture Test message.',
];

/**
* @param MessageFactory $giftMessageFactory
* @param Message $messageResourceModel
* @param DataMerger $dataMerger
*/
public function __construct(
private readonly MessageFactory $giftMessageFactory,
private readonly Message $messageResourceModel,
private readonly DataMerger $dataMerger,
) {
}

/**
* @inheritdoc
*/
public function apply(array $data = []): ?DataObject
{
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
$message = $this->giftMessageFactory->create();
$message
->setSender($data['sender'])
->setRecipient($data['recipient'])
->setMessage($data['message']);

$this->messageResourceModel->save($message);

return $message;
}

/**
* @inheritdoc
*/
public function revert(DataObject $data): void
{
$this->messageResourceModel->delete($data);
}
}
99 changes: 99 additions & 0 deletions app/code/Magento/OfflineShipping/Test/Fixture/TablerateFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Copyright 2023 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained from
* Adobe.
*/
declare(strict_types=1);

namespace Magento\OfflineShipping\Test\Fixture;

use Magento\Framework\DataObject;
use Magento\TestFramework\Fixture\Api\ServiceFactory;
use Magento\TestFramework\Fixture\Api\DataMerger;
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;

class TablerateFixture implements RevertibleDataFixtureInterface
{
private const DEFAULT_DATA = [
'website_id' => 1,
'dest_country_id' => 'US',
'dest_region_id' => 0,
'dest_zip' => '*',
'condition_name' => 'package_qty',
'condition_value' => 1,
'price' => 10,
'cost' => 0
];

/**
* @var AdapterInterface $connection
*/
private AdapterInterface $connection;

/**
* @var ObjectManagerInterface $objectManager
*/
private ObjectManagerInterface $objectManager;

/**
* @param ServiceFactory $serviceFactory
* @param DataMerger $dataMerger
*/
public function __construct(
private ServiceFactory $serviceFactory,
private DataMerger $dataMerger,
) {
$this->objectManager = Bootstrap::getObjectManager();
$this->connection = $this->objectManager->get(ResourceConnection::class)->getConnection();
}

/**
* @inheritDoc
*/
public function apply(array $data = []): ?DataObject
{
$resourceModel = $this->objectManager->create(Tablerate::class);
$data = $this->dataMerger->merge($this::DEFAULT_DATA, $data);
$columns = [
'website_id',
'dest_country_id',
'dest_region_id',
'dest_zip',
'condition_name',
'condition_value',
'price',
'cost'
];
$resourceModel->getConnection()->insertArray(
$resourceModel->getMainTable(),
$columns,
[
$data
]
);
return new DataObject($data);
}

/**
* @inheritDoc
*/
public function revert(DataObject $data): void
{
$resourceModel = $this->objectManager->create(Tablerate::class);
$this->connection->query("DELETE FROM {$resourceModel->getTable('shipping_tablerate')};");
}
}
10 changes: 8 additions & 2 deletions app/code/Magento/Quote/Test/Fixture/CustomerCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
class CustomerCart implements RevertibleDataFixtureInterface
{
private const DEFAULT_DATA = [
'customer_id' => null
'customer_id' => null,
'reserved_order_id' => null
];

/**
Expand Down Expand Up @@ -53,8 +54,13 @@ public function apply(array $data = []): ?DataObject
{
$data = array_merge(self::DEFAULT_DATA, $data);
$cartId = $this->cartManagement->createEmptyCartForCustomer($data['customer_id']);
$cart = $this->cartRepository->get($cartId);
if (isset($data['reserved_order_id'])) {
$cart->setReservedOrderId($data['reserved_order_id']);
$this->cartRepository->save($cart);
}

return $this->cartRepository->get($cartId);
return $cart;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion app/code/Magento/Quote/Test/Fixture/GuestCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ public function apply(array $data = []): ?DataObject
{
$maskId = $this->guestCartManagement->createEmptyCart();
$cartId = $this->maskedQuoteIdToQuoteId->execute($maskId);
$cart = $this->cartRepository->get($cartId);

return $this->cartRepository->get($cartId);
if (!isset($data['reserved_order_id']) && !isset($data['message_id'])) {
return $cart;
}
if (isset($data['reserved_order_id'])) {
$cart->setReservedOrderId($data['reserved_order_id']);
$this->cartRepository->save($cart);
}
if (isset($data['message_id'])) {
$cart->setGiftMessageId($data['message_id']);
$this->cartRepository->save($cart);
}

return $cart;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Copyright 2023 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained from
* Adobe.
*/
declare(strict_types=1);

namespace Magento\QuoteGraphQl\Model\CartItem;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory as ItemCollectionFactory;

/**
* Fetch Cart items and product models corresponding to a cart
*/
class GetPaginatedCartItems
{
/**
* @param ProductCollectionFactory $productCollectionFactory
* @param ItemCollectionFactory $itemCollectionFactory
*/
public function __construct(
private readonly ProductCollectionFactory $productCollectionFactory,
private readonly ItemCollectionFactory $itemCollectionFactory
) {
}

/**
* Get product models based on items in cart
*
* @param array $cartProductsIds
* @return ProductInterface[]
*/
private function getCartProduct(array $cartProductsIds): array
{
if (empty($cartProductsIds)) {
return [];
}
/** @var \Magento\Framework\Data\Collection $productCollection */
$productCollection = $this->productCollectionFactory->create()
->addAttributeToSelect('*')
->addIdFilter($cartProductsIds)
->setFlag('has_stock_status_filter', true);

return $productCollection->getItems();
}

/**
* Get visible cart items and product data for cart items
*
* @param Quote $cart
* @param int $pageSize
* @param int $offset
* @return array
*/
public function execute(Quote $cart, int $pageSize, int $offset): array
{
$result = [];
if (!$cart->getId()) {
return $result;
}
/** @var \Magento\Framework\Data\Collection $itemCollection */
$itemCollection = $this->itemCollectionFactory->create()
->addFieldToFilter('parent_item_id', ['null' => true])
->addFieldToFilter('quote_id', $cart->getId())
->setCurPage($offset)
->setPageSize($pageSize);

$items = [];
$cartProductsIds = [];
$itemDeletedCount = 0;
/** @var \Magento\Quote\Model\Quote\Item $item */
foreach ($itemCollection->getItems() as $item) {
if (!$item->isDeleted()) {
$items[] = $item;
$cartProductsIds[] = $item->getProduct()->getId();
} else {
$itemDeletedCount++;
}
}
$result['total'] = $itemCollection->getSize() - $itemDeletedCount;
$result['items'] = $items;
$result['products'] = $this->getCartProduct($cartProductsIds);
return $result;
}
}
Loading

0 comments on commit 594a590

Please sign in to comment.