Skip to content

Commit

Permalink
Merge pull request #3 from snowio/fix/sanitize-fh-attr-id
Browse files Browse the repository at this point in the history
Sanitise attribute code so it matches attribute definition
  • Loading branch information
qrz-io authored Feb 18, 2021
2 parents 73db62a + 52aa622 commit 0d5c5a2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/SimpleAttributeValueMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SnowIO\Akeneo3DataModel\AttributeValueSet as AkeneoAttributeValueSet;
use SnowIO\Akeneo3DataModel\PriceCollection;
use SnowIO\FredhopperDataModel\AttributeData;
use SnowIO\FredhopperDataModel\AttributeValueSet as FredhopperAttributeValueSet;
use SnowIO\FredhopperDataModel\AttributeValue as FredhopperAttributeValue;
use SnowIO\Akeneo3DataModel\AttributeValue as AkeneoAttributeValue;
Expand All @@ -25,7 +26,7 @@ public function __invoke(AkeneoAttributeValueSet $akeneoAttributeValues): Fredho
$attributeValues = FredhopperAttributeValueSet::create();
/** @var AkeneoAttributeValue $akeneoAttributeValue */
foreach ($akeneoAttributeValues as $akeneoAttributeValue) {
$attributeCode = $akeneoAttributeValue->getAttributeCode();
$attributeCode = ($this->attributeIdMapper)($akeneoAttributeValue->getAttributeCode());
$value = $akeneoAttributeValue->getValue();
$locale = $akeneoAttributeValue->getScope()->getLocale();
$fredhopperAttributeValue = FredhopperAttributeValue::of($attributeCode, $value)->withLocale($locale);
Expand All @@ -34,8 +35,10 @@ public function __invoke(AkeneoAttributeValueSet $akeneoAttributeValues): Fredho
return $attributeValues;
}

private $attributeIdMapper;

private function __construct()
{

$this->attributeIdMapper = [AttributeData::class, 'sanitizeId'];
}
}

0 comments on commit 0d5c5a2

Please sign in to comment.