-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8698 from magento-lynx/LYNX-311-DELIVERY
[LYNX] Multicoupon delivery PR
- Loading branch information
Showing
30 changed files
with
3,095 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
99
app/code/Magento/OfflineShipping/Test/Fixture/TablerateFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')};"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/code/Magento/QuoteGraphQl/Model/CartItem/GetPaginatedCartItems.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.