Describe the bug
Localized extra product attributes can't be accessed in accessories
To Reproduce
Steps to reproduce the behavior:
self::$definition['fields']['subtitle'] = array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString');
It should be pl.* instead of fixed list of pl.something attribute.
Additional information
PrestaShop version: develop
PHP version: all
Hi @jf-viguier,
Thanks for your report.
Could you please provide the exact override did you use?
Thanks!
Add subtitle to product_lang table and use this Product.php override :
<?php
class Product extends ProductCore
{
public $subtitle;
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
self::$definition['fields']['subtitle'] = array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString', 'size' => 128);
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
}
@jf-viguier, thanks for your feedback.
The subtitle is not available in Product::getAccessories, see
https://github.com/PrestaShop/PrestaShop/blob/85f982c4feb7d5f88f8f4532ab6f46cdd8255ba1/classes/Product.php#L4024
It should be pl.* instead of fixed list of pl.something attribute.
Ping @PrestaShop/prestashop-core-developers what do you think?
Thanks!
@jf-viguier, as discussed with our developer, it is an improvement more than a bug.
So, we thought about an alternative solution that you could offer them.
Thanks!
hi @jf-viguier !
We are not sure object models should be overriden like this. We'll try to suggest a better alternative, I'll get opinions from other core developers 馃憤
@matthieu-rolland seriously ? I override objets models since years like that.
It's in the doc https://devdocs.prestashop.com/1.7/modules/concepts/overrides/#overriding-a-class
We can discuss if column should be in a separate mysql table by the issue is the same : we need a way to extends the mysql query, maybe by adding a hook.
@jf-viguier
We can't use a wildcard in this query, the reason is that wildcards are very costly in sql queries, and if we were to add a wildcard in this sql query, then we would have to do it everywhere, because we can't know in advance what objectModels will be overriden by users.
If you add a field to an ObjectModel then you will have to override every queries that are supposed to return your new field, and be careful existing code responds well to the existence of this new field...
But in the end, overriding an ObjectModel to add a field doesn't seem to be a good practice, depending on your usecase, you should be able to find another way, if a new kind of data needs to be stored, then it should probably be stored in a new table.
The overriding of an object model is indeed mentioned in the documention, so I'll still wait for some input from other developers:
@PrestaShop/prestashop-core-developers . what do you think ?
overriding an ObjectModel to add a field doesn't seem to be a good practice
There is no other way now to have extra fields available in front and in back.
Just try to add a product field in a module and tell me.
Prestashop has to be as customizable as possible, thanks.
If you add a field to an ObjectModel then you will have to override every queries that are supposed to return your new field,
Yes, we do it every day ans it works, except here and in some presenters.
Check this article from @nenes25 https://www.h-hennes.fr/blog/2017/10/19/prestashop-1-7-ajouter-des-champs-produit/
Ok @jf-viguier , I understand your concern, we will come back to you in this issue shortly.
@jf-viguier i ve faced the same issue with attribute in cart as you can see here
https://www.h-hennes.fr/blog/2018/04/24/recuperer-des-informations-personnalisees-dans-le-panier/
I ve already think about a generic hook to alter dbQuery objects but it will needs lot of changes.
But in some case it could be usefull