From 260870df26d6fe1afeebbd644fc2976a6bc388cd Mon Sep 17 00:00:00 2001 From: johnny1991 Date: Thu, 30 Apr 2015 12:19:09 +0200 Subject: [PATCH] Fixed a bug on formatting metrics columns If metric attribute was global scope (is_scopable => 0), there was no channel whereof the result was wrong (Ex : 'weight' was transform to 'weight-') --- Writer/File/CsvProductWriter.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Writer/File/CsvProductWriter.php b/Writer/File/CsvProductWriter.php index ce37f79..6f87e0c 100644 --- a/Writer/File/CsvProductWriter.php +++ b/Writer/File/CsvProductWriter.php @@ -270,11 +270,17 @@ protected function formatMetricsColumns($item){ $attributeEntity = $this->entityManager->getRepository('Pim\Bundle\CatalogBundle\Entity\Attribute'); $attributes = $attributeEntity->getNonIdentifierAttributes(); foreach($attributes as $attribute){ - if($attribute->getBackendType() == 'metric'){ - if(array_key_exists($attribute->getCode(), $item)){ - $item[$attribute->getCode() . '-' . $this->getChannel()] = $item[$attribute->getCode()]; - unset($item[$attribute->getCode()]); - } + /** @var \Pim\Bundle\CatalogBundle\Entity\Attribute $attribute */ + + /** + * If it is a metric attribute, a scopable attribute and attribute exists in product item + */ + if ($attribute->getBackendType() == 'metric' + && array_key_exists($attribute->getCode(), $item) + && $attribute->isScopable() + ) { + $item[$attribute->getCode() . '-' . $this->getChannel()] = $item[$attribute->getCode()]; + unset($item[$attribute->getCode()]); } } return $item;