|
| 1 | +<?php |
| 2 | +/************************************************************************ |
| 3 | + * |
| 4 | + * Copyright 2023 Adobe |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * NOTICE: All information contained herein is, and remains |
| 8 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 9 | + * and technical concepts contained herein are proprietary to Adobe |
| 10 | + * and its suppliers and are protected by all applicable intellectual |
| 11 | + * property laws, including trade secret and copyright laws. |
| 12 | + * Dissemination of this information or reproduction of this material |
| 13 | + * is strictly forbidden unless prior written permission is obtained |
| 14 | + * from Adobe. |
| 15 | + * ************************************************************************ |
| 16 | + */ |
| 17 | +declare(strict_types=1); |
| 18 | + |
| 19 | +namespace Magento\Quote\Test\Fixture; |
| 20 | + |
| 21 | +use Magento\Framework\DataObject; |
| 22 | +use Magento\Framework\Exception\InvalidArgumentException; |
| 23 | +use Magento\Quote\Api\CartRepositoryInterface; |
| 24 | +use Magento\Quote\Model\QuoteFactory; |
| 25 | +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; |
| 26 | +use Magento\TestFramework\Fixture\DataFixtureInterface; |
| 27 | + |
| 28 | +/** |
| 29 | + * Mark cart as inactive |
| 30 | + */ |
| 31 | +class MakeCartInactive implements DataFixtureInterface |
| 32 | +{ |
| 33 | + private const FIELD_CART_ID = 'cart_id'; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var CartRepositoryInterface |
| 37 | + */ |
| 38 | + private CartRepositoryInterface $cartRepository; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var QuoteFactory |
| 42 | + */ |
| 43 | + private QuoteFactory $quoteFactory; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var QuoteResource |
| 47 | + */ |
| 48 | + private QuoteResource $quoteResource; |
| 49 | + |
| 50 | + /** |
| 51 | + * @param CartRepositoryInterface $cartRepository |
| 52 | + * @param QuoteFactory $quoteFactory |
| 53 | + * @param QuoteResource $quoteResource |
| 54 | + */ |
| 55 | + public function __construct( |
| 56 | + CartRepositoryInterface $cartRepository, |
| 57 | + QuoteFactory $quoteFactory, |
| 58 | + QuoteResource $quoteResource |
| 59 | + ) { |
| 60 | + $this->cartRepository = $cartRepository; |
| 61 | + $this->quoteFactory = $quoteFactory; |
| 62 | + $this->quoteResource = $quoteResource; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @param array $data |
| 67 | + * @return void |
| 68 | + * @throws InvalidArgumentException |
| 69 | + */ |
| 70 | + public function apply(array $data = []): ?DataObject |
| 71 | + { |
| 72 | + if (empty($data[self::FIELD_CART_ID])) { |
| 73 | + throw new InvalidArgumentException(__('"%field" is required', ['field' => self::FIELD_CART_ID])); |
| 74 | + } |
| 75 | + |
| 76 | + $quote = $this->quoteFactory->create(); |
| 77 | + $this->quoteResource->load($quote, $data[self::FIELD_CART_ID]); |
| 78 | + $quote->setIsActive(false); |
| 79 | + $this->cartRepository->save($quote); |
| 80 | + |
| 81 | + return $quote; |
| 82 | + } |
| 83 | +} |
0 commit comments