Skip to content

Commit

Permalink
added: support for BC itemContributions.typeCode Recupel
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijzer committed Oct 30, 2024
1 parent db8f24d commit 3310dab
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 74 deletions.
49 changes: 21 additions & 28 deletions src/Component/Converter/BCItemsApiConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Misery\Component\Reader\ReaderAwareTrait;

/**
* This Converter converts flat product to std data
* We focus on correcting with minimal issues
* This Converter converts BC product Data to std data with Matcher
* We focus on correcting without manipulation the data
* The better the input you give the better the output
* Besides data values, we also map locales and channels
*/
class BCItemsApiConverter implements ConverterInterface, ReaderAwareInterface, RegisteredByNameInterface, OptionsInterface
{
Expand Down Expand Up @@ -75,40 +76,32 @@ public function convert(array $item): array
$tmp
);

// these mappings, link and match the BC data and convert it to std Data Matcher
$mappings = $this->getOption('mappings:list');

foreach ($expand as $expandOption) {
foreach ($item[$expandOption] ?? [] as $itemProp) {
if (in_array($expandOption, ['itemUnitOfMeasuresColli', 'itemUnitOfMeasuresPallet', 'itemUnitOfMeasuresPieces'])) {
$this->processCharacteristics(
$itemProp,
['length', 'width', 'height', 'weight', 'qtyPerUnitOfMeasure'],
$expandOption,
$tmp
);
}

if ($expandOption === 'itemtranslations') {
$this->processCharacteristics(
$itemProp,
['itemDescriptionERP', 'typeName'],
$expandOption,
$tmp
);
}

if ($expandOption === 'itemreferences') {
$this->processCharacteristics(
$itemProp,
['referenceNo'],
$expandOption,
$tmp
);
}

if ($expandOption === 'itemCategories') {
$tmp['categories'] = array_map(function ($cat) {
return $cat['code'] ?? null;
}, $item[$expandOption]);
continue;
}

$bcMappings = $mappings[$expandOption] ?? null;
if (!$bcMappings) {
continue;
}

$bcMappingKeys = array_keys($bcMappings);

$this->processCharacteristics(
$itemProp,
$bcMappingKeys,
$expandOption,
$tmp
);
}
}

Expand Down
106 changes: 60 additions & 46 deletions tests/Component/Converter/BCItemsApiConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,52 @@ public function testConvert()
// Define test data
$converter = new BCItemsApiConverter();
$converter->setOptions([
'expand' => ['itemUnitOfMeasuresPieces', 'itemtranslations', 'itemreferences', 'itemCategories'],
'expand' => ['itemUnitOfMeasuresPieces', 'itemtranslations', 'itemreferences', 'itemCategories', 'itemContributions'],
'mappings:list' => [

'itemtranslations' => [
'typeName' => 'type_name',
'itemDescriptionERP' => 'article_description_erp',
],
'itemContributions' => [
'typeCode' => 'RECUPEL',
],
'itemUnitOfMeasuresPieces' => [
'length' => 'package_length',
'width' => 'package_width',
'height' => 'package_height',
'weight' => 'package_weight',
],
'itemUnitOfMeasuresPallet' => [
'length' => 'package_length',
'width' => 'package_width',
'height' => 'package_height',
'weight' => 'package_weight',
'qtyPerUnitOfMeasure' => 'amount_per_pallet',
],
'itemUnitOfMeasuresColli' => [
'length' => 'package_length',
'width' => 'package_width',
'height' => 'package_height',
'weight' => 'package_weight',
'qtyPerUnitOfMeasure' => 'amount_per_pallet',
],
],
'attributes:list' => [
'sku', 'itemDescriptionERP', 'unitPrice',
'sku', 'article_description_erp', 'unitPrice', 'package_length', 'package_width', 'package_height', 'package_weight', 'RECUPEL',
],
'attribute_types:list' => [
'length' => AkeneoHeaderTypes::METRIC,
'width' => AkeneoHeaderTypes::METRIC,
'height' => AkeneoHeaderTypes::METRIC,
'itemDescriptionERP' => AkeneoHeaderTypes::TEXT,
'package_length' => AkeneoHeaderTypes::METRIC,
'package_width' => AkeneoHeaderTypes::METRIC,
'package_height' => AkeneoHeaderTypes::METRIC,
'article_description_erp' => AkeneoHeaderTypes::TEXT,
'unitPrice' => AkeneoHeaderTypes::TEXT,
'RECUPEL' => AkeneoHeaderTypes::SELECT,
],
'localizable_attribute_codes:list' => [
'itemDescriptionERP'
'article_description_erp'
],
'scopable_attribute_codes:list' => [],
'default_metrics:list' => ['length' => 'METER', 'width' => 'METER', 'height' => 'METER'],
'default_metrics:list' => ['package_length' => 'METER', 'package_width' => 'METER', 'package_height' => 'METER'],
'attribute_option_label_codes:list' => [],
'set_default_metrics' => TRUE,
'default_locale' => 'en_US',
Expand All @@ -42,72 +69,59 @@ public function testConvert()
'option_label' => 'label-nl_BE',
]);

$item = [
'@odata.etag' => 'etag_value',
'no' => 'SKU123',
'unitPrice' => 25.5,
'tariffNo' => '123456',
'standard_delivery_time' => 3,
'itemUnitOfMeasuresPieces' => [
['length' => 10, 'width' => 5, 'height' => 2, 'qtyPerUnitOfMeasure' => 1],
],
'itemtranslations' => [
['itemDescriptionERP' => 'Product Description', 'typeName' => 'Product Type'],
],
'itemreferences' => [
['referenceNo' => 'REF123'],
],
'itemCategories' => [
['code' => 'category1'],
['code' => 'category2'],
],
];
$item = json_decode(file_get_contents(__DIR__ . '/data/bc_article.json'), true);

// Perform the conversion
$result = $converter->convert($item);

// Define the expected result
$expectedResult = [
'sku' => 'SKU123',
'categories' => ['category1','category2'],
'sku' => '1001000023',
'categories' => ['1001'],
'values|unitPrice' => [
'locale' => null,
'scope' => null,
'data' => 25.5,
'data' => 73.6,
'matcher' => Matcher::create('values|unitPrice'),
],
'values|length' => [
'values|article_description_erp' => [
'locale' => 'en_US',
'scope' => null,
'data' => 'Badkamerventilator met timer',
'matcher' => Matcher::create('values|article_description_erp'),
],
'values|package_length' => [
'locale' => null,
'scope' => null,
'data' => [
'amount' => 10,
'unit' => 'METER',
'amount' => 0,
'unit' => 'METER',
],
'matcher' => Matcher::create('values|length'),
'matcher' => Matcher::create('values|package_length'),
],
'values|width' => [
'values|package_width' => [
'locale' => null,
'scope' => null,
'data' => [
'amount' => 5,
'amount' => 0,
'unit' => 'METER',
],
'matcher' => Matcher::create('values|width'),
'matcher' => Matcher::create('values|package_width'),
],
'values|height' => [
'values|package_height' => [
'locale' => null,
'scope' => null,
'data' => [
'amount' => 2,
'amount' => 0,
'unit' => 'METER',
],
'matcher' => Matcher::create('values|height'),
'matcher' => Matcher::create('values|package_height'),
],
'values|itemDescriptionERP' => [
'locale' => 'en_US',
'values|RECUPEL' => [
'locale' => null,
'scope' => null,
'data' => 'Product Description',
'matcher' => Matcher::create('values|itemDescriptionERP'),
'data' => 'RECUPEL',
'matcher' => Matcher::create('values|RECUPEL'),
],
];

Expand Down
72 changes: 72 additions & 0 deletions tests/Component/Converter/data/bc_article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"@odata.etag": "W\/\"JzIwOzEyMTAyMjIzMTI4MDAxNzQ4MDI3MTswMDsn\"",
"id": "37e78da7-dbeb-ed11-9f71-002248a3d52c",
"number": "1001000023",
"unitPrice": 73.6,
"tariffNumber": "84145100",
"leadTimeCalculation": "2W",
"gtin": "5015135451622",
"blocked": false,
"lastModifiedDateTime": "2024-09-13T06:22:23.62Z",
"itemtranslations": [{
"@odata.etag": "W\/\"JzIwOzE1MDc0Mzk3NjkzMjk3MjEyMDAzMTswMDsn\"",
"id": "1b32d7a5-dbeb-ed11-9f71-002248a3d52c",
"description": "Silhouette 125T \/ Extracteur pr SDB-WC Tempo",
"typeName": "Silhouette 125T",
"itemDescriptionERP": "Extracteur pr SDB-WC Tempo",
"lastModifiedDateTime": "2024-02-02T12:34:41.857Z"
}, {
"@odata.etag": "W\/\"JzE5OzczNzk0ODU3ODUxNTgyMjM2MTgxOzAwOyc=\"",
"id": "1c32d7a5-dbeb-ed11-9f71-002248a3d52c",
"description": "Silhouette 125T \/ Badkamerventilator met timer",
"typeName": "Silhouette 125T",
"itemDescriptionERP": "Badkamerventilator met timer",
"lastModifiedDateTime": "0001-01-01T00:00:00Z"
}],
"itemreferences": [{
"@odata.etag": "W\/\"JzE5Ozk3NjEwMDY4MjY3NTE0OTA3MDQxOzAwOyc=\"",
"id": "f23e41a2-dbeb-ed11-9f71-002248a3d52c",
"lastModifiedDateTime": "2023-05-06T09:14:11.973Z",
"referenceNumber": "1001000023"
}, {
"@odata.etag": "W\/\"JzE5OzczMzY3NzU1ODI1NjcxOTYzMTgxOzAwOyc=\"",
"id": "f33e41a2-dbeb-ed11-9f71-002248a3d52c",
"lastModifiedDateTime": "2023-05-06T09:14:11.977Z",
"referenceNumber": "5015135451622"
}],
"itemUnitOfMeasuresColli": [],
"itemUnitOfMeasuresPallet": [],
"itemUnitOfMeasuresPieces": [{
"@odata.etag": "W\/\"JzE5OzIzNzIwMDk0ODc4OTg0Mjg5MTUxOzAwOyc=\"",
"id": "e9d8f2a6-dbeb-ed11-9f71-002248a3d52c",
"lastModifiedDateTime": "2024-09-19T12:41:38.933Z",
"height": 0,
"length": 0,
"weight": 0.9,
"width": 0
}],
"itemCategories": [{
"@odata.etag": "W\/\"JzE4OzQ3NDAwMTc1MzU4NTA3NzI1NzE7MDA7Jw==\"",
"id": "763e41a2-dbeb-ed11-9f71-002248a3d52c",
"lastModifiedDateTime": "2024-04-15T08:51:33.4Z",
"code": "1001",
"description": "Residential individual fans without heat recovery",
"hasChildren": true,
"indentation": 1,
"parentCategory": "10",
"presentationOrder": 20000
}],
"itemContributions": [{
"@odata.etag": "W\/\"JzE5Ozk1MTI5MDAyMDIyNjI3OTA1MzQxOzAwOyc=\"",
"id": "d3265afa-0c4f-ef11-bfe4-7c1e52213fce",
"lastModifiedDateTime": "2024-07-31T07:17:44.067Z",
"itemNo": "1001000023",
"variantCode": "",
"typeCode": "RECUPEL",
"categoryCode": "5.3.2",
"baseUnitOfMeasure": "PCS",
"noOfCorrespondingTariffs": 1,
"quantityCalculationType": "Base_x0020_Unit_x0020_of_x0020_Measure",
"quantityFactor": 1
}]
}

0 comments on commit 3310dab

Please sign in to comment.