-
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 #8798 from magento-lynx/multicoupon
[LYNX] Multicoupon Admin UI
- Loading branch information
Showing
27 changed files
with
733 additions
and
261 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/code/Magento/QuoteGraphQl/Model/CartItem/GetItemsData.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,64 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 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\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; | ||
use Magento\Framework\GraphQl\Query\Uid; | ||
use Magento\Quote\Api\Data\CartItemInterface; | ||
|
||
class GetItemsData | ||
{ | ||
/** | ||
* @param Uid $uidEncoder | ||
*/ | ||
public function __construct( | ||
private readonly Uid $uidEncoder, | ||
) { | ||
} | ||
|
||
/** | ||
* Retrieve cart items data | ||
* | ||
* @param CartItemInterface[] $cartItems | ||
* @return array | ||
*/ | ||
public function execute(array $cartItems): array | ||
{ | ||
$itemsData = []; | ||
foreach ($cartItems as $cartItem) { | ||
$product = $cartItem->getProduct(); | ||
if ($product === null) { | ||
$itemsData[] = new GraphQlNoSuchEntityException( | ||
__("The product that was requested doesn't exist. Verify the product and try again.") | ||
); | ||
continue; | ||
} | ||
$productData = $product->getData(); | ||
$productData['model'] = $product; | ||
$productData['uid'] = $this->uidEncoder->encode((string) $product->getId()); | ||
|
||
$itemsData[] = [ | ||
'id' => $cartItem->getItemId(), | ||
'uid' => $this->uidEncoder->encode((string) $cartItem->getItemId()), | ||
'quantity' => $cartItem->getQty(), | ||
'product' => $productData, | ||
'model' => $cartItem, | ||
]; | ||
} | ||
return $itemsData; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 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; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Quote\Model\Quote; | ||
|
||
class GetDiscounts | ||
{ | ||
/** | ||
* Get Discount Values | ||
* | ||
* @param Quote $quote | ||
* @param array $discounts | ||
* @return array|null | ||
* @throws LocalizedException | ||
*/ | ||
public function execute(Quote $quote, array $discounts): ?array | ||
{ | ||
if (empty($discounts)) { | ||
return null; | ||
} | ||
|
||
$discountValues = []; | ||
foreach ($discounts as $value) { | ||
$discountData = $value->getDiscountData(); | ||
$discountValues[] = [ | ||
'label' => $value->getRuleLabel() ?: __('Discount'), | ||
'applied_to' => $discountData->getAppliedTo(), | ||
'amount' => [ | ||
'value' => $discountData->getAmount(), | ||
'currency' => $quote->getQuoteCurrencyCode() | ||
], | ||
'discount_model' => $value, | ||
'quote_model' => $quote | ||
]; | ||
} | ||
|
||
return $discountValues; | ||
} | ||
} |
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
Oops, something went wrong.