From b44477bc70f73a7097f25a6f29a46774b3de2491 Mon Sep 17 00:00:00 2001 From: dnd-rodrigue Date: Mon, 20 May 2019 15:22:02 +0200 Subject: [PATCH] attribute-lowercase: Force attributes id to be lowercase during import in order to prevent magento --- .../Pimgento/Api/Helper/Entities.php | 23 +++++++++++++++++++ .../Pimgento/Api/Helper/Family/Variant.php | 1 + .../community/Pimgento/Api/Helper/Product.php | 1 + 3 files changed, 25 insertions(+) diff --git a/app/code/community/Pimgento/Api/Helper/Entities.php b/app/code/community/Pimgento/Api/Helper/Entities.php index dca2a68..75d9740 100644 --- a/app/code/community/Pimgento/Api/Helper/Entities.php +++ b/app/code/community/Pimgento/Api/Helper/Entities.php @@ -201,4 +201,27 @@ public function getColumnsFromResult(array $result) return (array)$columns; } + + /** + * Set key to lower case + * to avoid problems with values import + * + * @param string $key + * + * @return string + */ + public function keyToLowerCase($key) + { + /** @var string[] $keyParts */ + $keyParts = explode('-', $key, 2); + $keyParts[0] = strtolower($keyParts[0]); + /** @var string $newKey */ + if (count($keyParts) > 1) { + $newKey = $keyParts[0].'-'.$keyParts[1]; + } else { + $newKey = $keyParts[0]; + } + + return $newKey; + } } diff --git a/app/code/community/Pimgento/Api/Helper/Family/Variant.php b/app/code/community/Pimgento/Api/Helper/Family/Variant.php index 4bf9315..20cb9d8 100644 --- a/app/code/community/Pimgento/Api/Helper/Family/Variant.php +++ b/app/code/community/Pimgento/Api/Helper/Family/Variant.php @@ -35,6 +35,7 @@ public function getColumnsFromResult(array $result) * @var mixed $value */ foreach ($result as $key => $value) { + $key = $this->keyToLowerCase($key); if (in_array($key, static::EXCLUDED_COLUMNS)) { continue; } diff --git a/app/code/community/Pimgento/Api/Helper/Product.php b/app/code/community/Pimgento/Api/Helper/Product.php index 35a41e9..7502f0e 100755 --- a/app/code/community/Pimgento/Api/Helper/Product.php +++ b/app/code/community/Pimgento/Api/Helper/Product.php @@ -47,6 +47,7 @@ public function getColumnsFromResult(array $result) * @var mixed $value */ foreach ($result as $key => $value) { + $key = $this->keyToLowerCase($key); if (in_array($key, static::EXCLUDED_COLUMNS)) { continue; }