Skip to content

Commit 62db9c1

Browse files
authored
Merge pull request #8117 from magento-lynx/purchase-order-graphql
2 parents fc4d9cc + ca895f2 commit 62db9c1

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Fixture;
9+
10+
use Magento\Catalog\Api\CategoryLinkManagementInterface;
11+
use Magento\Framework\Exception\InvalidArgumentException;
12+
use Magento\Framework\DataObject;
13+
use Magento\TestFramework\Fixture\DataFixtureInterface;
14+
15+
/**
16+
* Assigning products to catalog
17+
*/
18+
class AssignProducts implements DataFixtureInterface
19+
{
20+
private const PRODUCTS = 'products';
21+
private const CATEGORY = 'category';
22+
23+
/**
24+
* @var CategoryLinkManagementInterface
25+
*/
26+
private categoryLinkManagementInterface $categoryLinkManagement;
27+
28+
/**
29+
* @param CategoryLinkManagementInterface $categoryLinkManagement
30+
*/
31+
public function __construct(CategoryLinkManagementInterface $categoryLinkManagement)
32+
{
33+
$this->categoryLinkManagement = $categoryLinkManagement;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
* @throws InvalidArgumentException
39+
*/
40+
public function apply(array $data = []): ?DataObject
41+
{
42+
if (empty($data[self::CATEGORY])) {
43+
throw new InvalidArgumentException(__('"%field" is required', ['field' => self::CATEGORY]));
44+
}
45+
46+
if (empty($data[self::PRODUCTS])) {
47+
throw new InvalidArgumentException(__('"%field" is required', ['field' => self::PRODUCTS]));
48+
}
49+
50+
if (!is_array($data[self::PRODUCTS])) {
51+
throw new InvalidArgumentException(__('"%field" must be an array', ['field' => self::PRODUCTS]));
52+
}
53+
54+
foreach ($data[self::PRODUCTS] as $product) {
55+
$this->categoryLinkManagement->assignProductToCategories(
56+
$product->getSku(),
57+
[$data[self::CATEGORY]->getId()]
58+
);
59+
}
60+
61+
return null;
62+
}
63+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Test\Fixture;
10+
11+
use Magento\Customer\Api\Data\GroupInterface;
12+
use Magento\Customer\Api\GroupRepositoryInterface;
13+
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Framework\DataObject;
15+
use Magento\Framework\EntityManager\Hydrator;
16+
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Magento\Tax\Api\TaxClassRepositoryInterface;
19+
use Magento\TestFramework\Fixture\Api\ServiceFactory;
20+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
21+
22+
/**
23+
* Data fixture for customer group
24+
*/
25+
class CustomerGroup implements RevertibleDataFixtureInterface
26+
{
27+
private const DEFAULT_DATA = [
28+
GroupInterface::CODE => 'Customergroup%uniqid%',
29+
GroupInterface::TAX_CLASS_ID => 3,
30+
];
31+
32+
/**
33+
* @var ServiceFactory
34+
*/
35+
private ServiceFactory $serviceFactory;
36+
37+
/**
38+
* @var TaxClassRepositoryInterface
39+
*/
40+
private TaxClassRepositoryInterface $taxClassRepository;
41+
42+
/** @var Hydrator */
43+
private Hydrator $hydrator;
44+
45+
/**
46+
* @param ServiceFactory $serviceFactory
47+
* @param TaxClassRepositoryInterface $taxClassRepository
48+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
49+
* @param Hydrator $hydrator
50+
*/
51+
public function __construct(
52+
ServiceFactory $serviceFactory,
53+
TaxClassRepositoryInterface $taxClassRepository,
54+
Hydrator $hydrator
55+
) {
56+
$this->serviceFactory = $serviceFactory;
57+
$this->taxClassRepository = $taxClassRepository;
58+
$this->hydrator = $hydrator;
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
* @param array $data Parameters. Same format as Customer::DEFAULT_DATA.
64+
* @return DataObject|null
65+
* @throws LocalizedException
66+
* @throws NoSuchEntityException
67+
*/
68+
public function apply(array $data = []): ?DataObject
69+
{
70+
$customerGroupSaveService = $this->serviceFactory->create(
71+
GroupRepositoryInterface::class,
72+
'save'
73+
);
74+
$data = self::DEFAULT_DATA;
75+
if (!empty($data['tax_class_id'])) {
76+
$data[GroupInterface::TAX_CLASS_ID] = $this->taxClassRepository->get($data['tax_class_id'])->getClassId();
77+
}
78+
79+
$customerGroup = $customerGroupSaveService->execute(
80+
[
81+
'group' => $data,
82+
]
83+
);
84+
85+
return new DataObject($this->hydrator->extract($customerGroup));
86+
}
87+
88+
/**
89+
* @inheritdoc
90+
*/
91+
public function revert(DataObject $data): void
92+
{
93+
$service = $this->serviceFactory->create(GroupRepositoryInterface::class, 'deleteById');
94+
$service->execute(
95+
[
96+
'id' => $data->getId()
97+
]
98+
);
99+
}
100+
}

0 commit comments

Comments
 (0)