Skip to content

Commit 690e01a

Browse files
committed
Created lookup for Category, Collection and Family
1 parent 3b06593 commit 690e01a

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

src/CategoryLookup.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Flow\Magento2;
6+
7+
use Kiboko\Component\Bucket\ComplexResultBucket;
8+
use Kiboko\Contract\Pipeline\TransformerInterface;
9+
10+
final class CategoryLookup implements TransformerInterface
11+
{
12+
public function __construct(
13+
private \Psr\Log\LoggerInterface $logger,
14+
private \Kiboko\Magento\V2_1\Client|\Kiboko\Magento\V2_2\Client|\Kiboko\Magento\V2_3\Client|\Kiboko\Magento\V2_4\Client $client,
15+
) {
16+
}
17+
18+
public function transform(): \Generator
19+
{
20+
$line = yield;
21+
do {
22+
$bucket = new ComplexResultBucket();
23+
$output = $line;
24+
25+
(function ($input, $bucket) use ($output) {
26+
try {
27+
$lookup = $this->client->catalogCategoryAttributeOptionManagementV1GetItemsGet(
28+
attributeCode: $input["Product_Category"],
29+
);
30+
31+
if (!$lookup instanceof \Kiboko\Magento\V2_1\Model\EavDataAttributeOptionInterface
32+
&& !$lookup instanceof \Kiboko\Magento\V2_2\Model\EavDataAttributeOptionInterface
33+
&& !$lookup instanceof \Kiboko\Magento\V2_3\Model\EavDataAttributeOptionInterface
34+
&& !$lookup instanceof \Kiboko\Magento\V2_4\Model\EavDataAttributeOptionInterface
35+
) {
36+
return;
37+
}
38+
} catch (\RuntimeException $exception) {
39+
$this->logger->warning($exception->getMessage(), ['exception' => $exception, 'item' => $input]);
40+
$bucket->reject($input);
41+
return;
42+
}
43+
44+
$output = (function () use ($lookup, $output) {
45+
$output['Product_Category'] = $lookup->getLabel();
46+
return $output;
47+
})();
48+
49+
$bucket->accept($output);
50+
})($line, $bucket);
51+
} while ($line = (yield $bucket));
52+
}
53+
}

src/CollectionLookup.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Flow\Magento2;
6+
7+
use Kiboko\Component\Bucket\ComplexResultBucket;
8+
use Kiboko\Contract\Pipeline\TransformerInterface;
9+
10+
final class CollectionLookup implements TransformerInterface
11+
{
12+
public function __construct(
13+
private \Psr\Log\LoggerInterface $logger,
14+
private \Kiboko\Magento\V2_1\Client|\Kiboko\Magento\V2_2\Client|\Kiboko\Magento\V2_3\Client|\Kiboko\Magento\V2_4\Client $client,
15+
) {
16+
}
17+
18+
public function transform(): \Generator
19+
{
20+
$line = yield;
21+
do {
22+
$bucket = new ComplexResultBucket();
23+
$output = $line;
24+
25+
(function ($input, $bucket) use ($output) {
26+
try {
27+
$lookup = $this->client->catalogCategoryAttributeOptionManagementV1GetItemsGet(
28+
attributeCode: $input["Collection"],
29+
);
30+
31+
if (!$lookup instanceof \Kiboko\Magento\V2_1\Model\EavDataAttributeOptionInterface
32+
&& !$lookup instanceof \Kiboko\Magento\V2_2\Model\EavDataAttributeOptionInterface
33+
&& !$lookup instanceof \Kiboko\Magento\V2_3\Model\EavDataAttributeOptionInterface
34+
&& !$lookup instanceof \Kiboko\Magento\V2_4\Model\EavDataAttributeOptionInterface
35+
) {
36+
return;
37+
}
38+
} catch (\RuntimeException $exception) {
39+
$this->logger->warning($exception->getMessage(), ['exception' => $exception, 'item' => $input]);
40+
$bucket->reject($input);
41+
return;
42+
}
43+
44+
$output = (function () use ($lookup, $output) {
45+
$output['Collection'] = $lookup->getLabel();
46+
return $output;
47+
})();
48+
49+
$bucket->accept($output);
50+
})($line, $bucket);
51+
} while ($line = (yield $bucket));
52+
}
53+
}

src/FamilyLookup.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Flow\Magento2;
6+
7+
use Kiboko\Component\Bucket\ComplexResultBucket;
8+
use Kiboko\Contract\Pipeline\TransformerInterface;
9+
10+
final class FamilyLookup implements TransformerInterface
11+
{
12+
public function __construct(
13+
private \Psr\Log\LoggerInterface $logger,
14+
private \Kiboko\Magento\V2_1\Client|\Kiboko\Magento\V2_2\Client|\Kiboko\Magento\V2_3\Client|\Kiboko\Magento\V2_4\Client $client,
15+
) {
16+
}
17+
18+
public function transform(): \Generator
19+
{
20+
$line = yield;
21+
do {
22+
$bucket = new ComplexResultBucket();
23+
$output = $line;
24+
25+
(function ($input, $bucket) use ($output) {
26+
try {
27+
$lookup = $this->client->catalogCategoryAttributeOptionManagementV1GetItemsGet(
28+
attributeCode: $input["Famille_de_Produit"],
29+
);
30+
31+
if (!$lookup instanceof \Kiboko\Magento\V2_1\Model\EavDataAttributeOptionInterface
32+
&& !$lookup instanceof \Kiboko\Magento\V2_2\Model\EavDataAttributeOptionInterface
33+
&& !$lookup instanceof \Kiboko\Magento\V2_3\Model\EavDataAttributeOptionInterface
34+
&& !$lookup instanceof \Kiboko\Magento\V2_4\Model\EavDataAttributeOptionInterface
35+
) {
36+
return;
37+
}
38+
} catch (\RuntimeException $exception) {
39+
$this->logger->warning($exception->getMessage(), ['exception' => $exception, 'item' => $input]);
40+
$bucket->reject($input);
41+
return;
42+
}
43+
44+
$output = (function () use ($lookup, $output) {
45+
$output['Famille_de_Produit'] = $lookup->getLabel();
46+
return $output;
47+
})();
48+
49+
$bucket->accept($output);
50+
})($line, $bucket);
51+
} while ($line = (yield $bucket));
52+
}
53+
}

0 commit comments

Comments
 (0)