|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright since 2007 PrestaShop SA and Contributors |
| 4 | + * PrestaShop is an International Registered Trademark & Property of PrestaShop SA |
| 5 | + * |
| 6 | + * NOTICE OF LICENSE |
| 7 | + * |
| 8 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 9 | + * that is bundled with this package in the file LICENSE.md. |
| 10 | + * It is also available through the world-wide-web at this URL: |
| 11 | + * https://opensource.org/licenses/OSL-3.0 |
| 12 | + * If you did not receive a copy of the license and are unable to |
| 13 | + * obtain it through the world-wide-web, please send an email |
| 14 | + * to [email protected] so we can send you a copy immediately. |
| 15 | + * |
| 16 | + * DISCLAIMER |
| 17 | + * |
| 18 | + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer |
| 19 | + * versions in the future. If you wish to customize PrestaShop for your |
| 20 | + * needs please refer to https://devdocs.prestashop.com/ for more information. |
| 21 | + * |
| 22 | + * @author PrestaShop SA and Contributors <[email protected]> |
| 23 | + * @copyright Since 2007 PrestaShop SA and Contributors |
| 24 | + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
| 25 | + */ |
| 26 | + |
| 27 | +namespace PrestaShop\PrestaShop\Adapter\Discount\QueryHandler; |
| 28 | + |
| 29 | +use DateTimeImmutable; |
| 30 | +use Exception; |
| 31 | +use PrestaShop\PrestaShop\Adapter\CartRule\Repository\CartRuleRepository; |
| 32 | +use PrestaShop\PrestaShop\Core\CommandBus\Attributes\AsQueryHandler; |
| 33 | +use PrestaShop\PrestaShop\Core\Domain\CartRule\ValueObject\CartRuleId; |
| 34 | +use PrestaShop\PrestaShop\Core\Domain\Discount\Query\GetDiscountForEditing; |
| 35 | +use PrestaShop\PrestaShop\Core\Domain\Discount\QueryHandler\GetDiscountForEditingHandlerInterface; |
| 36 | +use PrestaShop\PrestaShop\Core\Domain\Discount\QueryResult\DiscountForEditing; |
| 37 | + |
| 38 | +#[AsQueryHandler] |
| 39 | +class GetDiscountForEditingHandler implements GetDiscountForEditingHandlerInterface |
| 40 | +{ |
| 41 | + public function __construct( |
| 42 | + protected readonly CartRuleRepository $cartRuleRepository |
| 43 | + ) { |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @throws Exception |
| 48 | + */ |
| 49 | + public function handle(GetDiscountForEditing $query): DiscountForEditing |
| 50 | + { |
| 51 | + $cartRuleId = new CartRuleId($query->discountId->getValue()); |
| 52 | + $cartRule = $this->cartRuleRepository->get($cartRuleId); |
| 53 | + |
| 54 | + return new DiscountForEditing( |
| 55 | + $query->discountId->getValue(), |
| 56 | + $cartRule->priority, |
| 57 | + $cartRule->active, |
| 58 | + new DateTimeImmutable($cartRule->date_from), |
| 59 | + new DateTimeImmutable($cartRule->date_to), |
| 60 | + $cartRule->quantity, |
| 61 | + $cartRule->quantity_per_user, |
| 62 | + $cartRule->description, |
| 63 | + $cartRule->code, |
| 64 | + (int) $cartRule->id_customer, |
| 65 | + $cartRule->highlight, |
| 66 | + $cartRule->partial_use, |
| 67 | + $cartRule->type |
| 68 | + ); |
| 69 | + } |
| 70 | +} |
0 commit comments