1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MIT License |
||
5 | * For full license information, please view the LICENSE file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\CmsSlotBlockDataImport; |
||
9 | |||
10 | use ArrayObject; |
||
11 | use Codeception\Actor; |
||
12 | use Generated\Shared\Transfer\CategoryTransfer; |
||
13 | use Generated\Shared\Transfer\CmsSlotBlockConditionTransfer; |
||
14 | use Generated\Shared\Transfer\CmsSlotBlockTransfer; |
||
15 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
16 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
17 | use Generated\Shared\Transfer\ProductAbstractTransfer; |
||
18 | use Orm\Zed\CmsBlock\Persistence\SpyCmsBlockQuery; |
||
19 | use Orm\Zed\CmsSlotBlock\Persistence\SpyCmsSlotBlockQuery; |
||
20 | |||
21 | /** |
||
22 | * @method void wantToTest($text) |
||
23 | * @method void wantTo($text) |
||
24 | * @method void execute($callable) |
||
25 | * @method void expectTo($prediction) |
||
26 | * @method void expect($prediction) |
||
27 | * @method void amGoingTo($argumentation) |
||
28 | * @method void am($role) |
||
29 | * @method void lookForwardTo($achieveValue) |
||
30 | * @method void comment($description) |
||
31 | * @method void pause() |
||
32 | * |
||
33 | * @SuppressWarnings(PHPMD) |
||
34 | */ |
||
35 | class CmsSlotBlockDataImportCommunicationTester extends Actor |
||
36 | { |
||
37 | use _generated\CmsSlotBlockDataImportCommunicationTesterActions; |
||
38 | |||
39 | /** |
||
40 | * @param string $fileName |
||
41 | * |
||
42 | * @return \Generated\Shared\Transfer\DataImporterConfigurationTransfer |
||
43 | */ |
||
44 | public function createDataImporterConfigurationTransfer(string $fileName): DataImporterConfigurationTransfer |
||
45 | { |
||
46 | $dataImporterReaderConfigurationTransfer = new DataImporterReaderConfigurationTransfer(); |
||
47 | $dataImporterReaderConfigurationTransfer->setFileName($fileName); |
||
48 | |||
49 | $dataImportConfigurationTransfer = new DataImporterConfigurationTransfer(); |
||
50 | $dataImportConfigurationTransfer->setReaderConfiguration($dataImporterReaderConfigurationTransfer) |
||
51 | ->setThrowException(true); |
||
52 | |||
53 | return $dataImportConfigurationTransfer; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param int $idCmsSlotTemplate |
||
58 | * @param int $idCmsSlot |
||
59 | * |
||
60 | * @return \Generated\Shared\Transfer\CmsSlotBlockTransfer|null |
||
61 | */ |
||
62 | public function findCmsSlotBlock(int $idCmsSlotTemplate, int $idCmsSlot): ?CmsSlotBlockTransfer |
||
63 | { |
||
64 | $cmsSlotBlockEntity = SpyCmsSlotBlockQuery::create() |
||
65 | ->filterByFkCmsSlot($idCmsSlot) |
||
66 | ->filterByFkCmsSlotTemplate($idCmsSlotTemplate) |
||
67 | ->findOne(); |
||
68 | |||
69 | if (!$cmsSlotBlockEntity) { |
||
70 | return null; |
||
71 | } |
||
72 | |||
73 | $cmsSlotBlockTransfer = (new CmsSlotBlockTransfer()) |
||
74 | ->setIdSlotTemplate($cmsSlotBlockEntity->getFkCmsSlotTemplate()) |
||
75 | ->setIdSlot($cmsSlotBlockEntity->getFkCmsSlot()) |
||
76 | ->setIdCmsBlock($cmsSlotBlockEntity->getFkCmsBlock()) |
||
77 | ->setPosition($cmsSlotBlockEntity->getPosition()); |
||
78 | |||
79 | if ($cmsSlotBlockEntity->getConditions()) { |
||
80 | $conditions = json_decode($cmsSlotBlockEntity->getConditions(), true); |
||
81 | $cmsSlotBlockConditionTransfers = new ArrayObject(); |
||
82 | |||
83 | foreach ($conditions as $condition) { |
||
84 | if ($condition) { |
||
85 | $cmsSlotBlockConditionTransfers->append((new CmsSlotBlockConditionTransfer())->fromArray($condition, true)); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | if ($cmsSlotBlockConditionTransfers) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
90 | $cmsSlotBlockTransfer->setConditions($cmsSlotBlockConditionTransfers); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | return $cmsSlotBlockTransfer; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param \Generated\Shared\Transfer\CategoryTransfer $categoryTransfer |
||
99 | * @param \Generated\Shared\Transfer\ProductAbstractTransfer $productAbstractTransfer |
||
100 | * |
||
101 | * @return \ArrayObject<int, \Generated\Shared\Transfer\CmsSlotBlockConditionTransfer> |
||
102 | */ |
||
103 | public function getCmsSlotBlockConditions( |
||
104 | CategoryTransfer $categoryTransfer, |
||
105 | ProductAbstractTransfer $productAbstractTransfer |
||
106 | ): ArrayObject { |
||
107 | $conditions = new ArrayObject(); |
||
108 | |||
109 | $conditionCategory = (new CmsSlotBlockConditionTransfer())->fromArray([ |
||
110 | 'all' => false, |
||
111 | 'categoryIds' => [$categoryTransfer->getIdCategory()], |
||
112 | ], true); |
||
113 | |||
114 | $conditionProductCategory = (new CmsSlotBlockConditionTransfer())->fromArray([ |
||
115 | 'all' => false, |
||
116 | 'productIds' => [$productAbstractTransfer->getIdProductAbstract()], |
||
117 | 'categoryIds' => [$categoryTransfer->getIdCategory()], |
||
118 | ], true); |
||
119 | |||
120 | $conditionCmsPage = (new CmsSlotBlockConditionTransfer())->fromArray([ |
||
121 | 'all' => true, |
||
122 | 'cmsPageIds' => [], |
||
123 | ], true); |
||
124 | |||
125 | $conditions->append($conditionCategory); |
||
126 | $conditions->append($conditionProductCategory); |
||
127 | $conditions->append($conditionCmsPage); |
||
128 | |||
129 | return $conditions; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param string $key |
||
134 | * |
||
135 | * @return void |
||
136 | */ |
||
137 | public function removeCmsBlockByKey(string $key): void |
||
138 | { |
||
139 | SpyCmsBlockQuery::create()->filterByKey($key)->delete(); |
||
140 | } |
||
141 | } |
||
142 |