Closed jycamier closed 7 years ago
The problem is rised up when your CustomEntity is a Reference Data and extends the class AbstractTranslatableCustomEntity. This one implements TranslatableInterface and the TranslationNormalizer to get a json format from the route pim_enrich_product_rest_get isn't compatible with the waiting format for select2 element.
I have fix it not properly because I don't know how I can fix it without broke every logic around the normalizers.
Hello @eheuje,
Thank you for raising this issue. Unfortunately, I have some difficulties for reproducing it.
Can you post the code of your fix here in order to allow us to investigate on the behavior you observed ?
Thank you in advance for your feedback !
Of course.
Here's a piece of my Custom Entity Color.
class Color extends AbstractTranslatableCustomEntity
{
/** @var boolean */
protected $isInkColor;
/** @var boolean */
protected $isBodyColor;
/** @var boolean */
protected $isSuperColor;
/** @var ArrayCollection */
protected $associatedSuperColors;
/** @var FileInfoInterface */
protected $image;
/**
* Color constructor.
*/
public function __construct()
{
parent::__construct();
$this->associatedSuperColors = new ArrayCollection();
}
/**
* @return string
*/
public function getTranslationFQCN()
{
return 'My\Pim\ColorBundle\Entity\ColorTranslation';
}
...
And here's my hack.
class TranslationNormalizer extends BaseTranslationNormalizer implements SerializerAwareInterface
{
/** @var SerializerInterface */
protected $serializer;
/**
* @param object $object
* @param null $format
* @param array $context
*
* @return array|bool|float|int|null|string
*/
public function normalize($object, $format = null, array $context = [])
{
if ($object instanceof Color) {
return $object->getCode();
}
return parent::normalize($object, $format, $context);
}
/**
* Sets the owning Serializer object.
*
* @param SerializerInterface $serializer
*/
public function setSerializer(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}
}
Hello @eheuje,
I'm sorry for my late reply. I discussed about your issue with our team in charge of the PIM customization. We think you don't have to do this kind of hack, there is for sure something broken somewhere else.
Here is a checklist:
If you have doubts, you can send me your ProductValue.orm.yml and I will try to take a look at it.
Regards
Hello @fabienlem,
- Have you well upgraded the CustomEntityBundle to 1.8.* version?
Yes, it is. Here's my composer.json require.
"require": {
"akeneo/pim-community-dev": "~1.6.2",
"akeneo-labs/custom-entity-bundle": "1.8.*",
"clever-age/akeneo-csv-fixtures-converter-bundle": "dev-master"
},
- Is everything OK in your mapping files? Especialy in you ProductValue mapping?
It seams to be OK.
$ php app/console pim:reference-data:check
Checking configuration of "color"...
[OK] Reference data names must use only letters and be camel-cased.
[OK] Reference data models must implement "Pim\Component\ReferenceData\Model\ReferenceDataInterface".
[OK] Reference Data mapping must have a unique "code" field.
[OK] Product Value model must implement the required accessors.
[OK] Relation between the "My\Pim\CatalogBundle\Entity\ProductValue" and the Reference Data must be configured.
Checking configuration of "colors"...
[OK] Reference data names must use only letters and be camel-cased.
[OK] Reference data models must implement "Pim\Component\ReferenceData\Model\ReferenceDataInterface".
[OK] Reference Data mapping must have a unique "code" field.
[OK] Product Value model must implement the required accessors.
[OK] Relation between the "My\Pim\CatalogBundle\Entity\ProductValue" and the Reference Data must be configured.
$ php app/console doctrine:schema:validate
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
- Is everything OK with your "pim_reference_data" and "akeneo_storage_utils.mapping_overrides" parameters in the app/config/config.yml" file?
Here's my mapping.
akeneo_storage_utils:
mapping_overrides:
-
original: Pim\Component\Catalog\Model\Product
override: My\Pim\ProductBundle\Entity\Product
-
original: Pim\Bundle\CatalogBundle\Entity\Category
override: My\Pim\CatalogBundle\Entity\Category
-
original: Pim\Bundle\CatalogBundle\Entity\CategoryTranslation
override: My\Pim\CatalogBundle\Entity\CategoryTranslation
-
original: Pim\Bundle\CatalogBundle\Entity\Attribute
override: My\Pim\CatalogBundle\Entity\Attribute
-
original: Pim\Component\Catalog\Model\ProductValue
override: My\Pim\CatalogBundle\Entity\ProductValue
-
original: Pim\Bundle\CatalogBundle\Entity\Family
override: My\Pim\CatalogBundle\Entity\Family
-
original: Pim\Bundle\CatalogBundle\Entity\FamilyTranslation
override: My\Pim\CatalogBundle\Entity\FamilyTranslation
I think there isn't any trouble on my ProductValue.orm.yml but here's it.
My\Pim\CatalogBundle\Entity\ProductValue:
type: entity
table: pim_catalog_product_value
changeTrackingPolicy: DEFERRED_EXPLICIT
indexes:
value_idx:
columns:
- attribute_id
- locale_code
- scope_code
varchar_idx:
columns:
- value_string
integer_idx:
columns:
- value_integer
fields:
overridden:
type: boolean
nullable: true
column: is_overridden
manyToOne:
color:
targetEntity: My\Pim\ColorBundle\Entity\Color
joinColumn:
name: color_id
referencedColumnName: id
manyToMany:
colors:
targetEntity: My\Pim\ColorBundle\Entity\Color
joinTable:
name: product_value_super_colors
joinColumns:
product_value_id:
referencedColumnName: id
inverseJoinColumns:
super_color_id:
referencedColumnName: id
cascade:
- persist
- detach
and my pim_reference_data configuration
pim_reference_data:
color:
class: My\Pim\ColorBundle\Entity\Color
type: simple
colors:
class: My\Pim\ColorBundle\Entity\Color
type: multi
Hi @fabienlem,
I have update to v1.6.4. All works fine without my fix now. Thank you so much.
@eheuje good news!
Don't hesitate if you encounter any other issue, these feedback are very valuable for us :)
I'm reporting a Bug
Since the migration of 1.5 to 1.6, all Reference Data with a persisted value in pim_catalog_product_value aren't displayed in the select2 element :