Reputation: 11
I've added a custom field into Prestashop 1.7 product I'm missing something because I can't save the value of the new field(checkbox)
What did till now:
ps_product
hide_discount_table - tinyint(1) - NOT NULL
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
self::$definition['fields']['hide_discount_table'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');
}
// LINE 238
->add('hidden_discount_table', FormType\CheckboxType::class, [
'label' => $this->translator->trans('Hide discount table', [], 'Admin.Global'),
'required' => false,
])
private $translatableKeys = array(
//...LINE 140
'hidden_discount_table',
);
private $unmapKeys = array(
//... LINE 161
'hidden_discount_table',
);
private function mapStep1FromData(Product $product)
{
return array(
//... LINE 518
'hide_discount_table' => $product->hide_discount_table== 0 ? false : true,
);
}
{# PANEL ESSENTIALS #}
{% block product_panel_essentials %}
{% set formQuantityShortcut = form.step1.qty_0_shortcut is defined ? form.step1.qty_0_shortcut : null %}
{{ include('@Product/ProductPage/Panels/essentials.html.twig', {
'formPackItems': form.step1.inputPackItems,
'productId': id_product,
'images': form.step1.vars.value.images,
'formShortDescription': form.step1.description_short,
'formDescription': form.step1.description,
'formManufacturer': form.step1.id_manufacturer,
'formHiddenDiscount': form.step1.hide_discount_table, // NEW ENTERY
'formFeatures': form.step1.features,
'formManufacturer': form.step1.id_manufacturer,
'formRelatedProducts': form.step1.related_products,
'is_combination_active': is_combination_active,
'has_combinations': has_combinations,
'formReference': form.step6.reference,
'formQuantityShortcut': formQuantityShortcut,
'formPriceShortcut': form.step1.price_shortcut,
'formPriceShortcutTTC': form.step1.price_ttc_shortcut,
'formCategories': form.step1,
})
}}
{% endblock %}
<div class="form-group mb-4">
<h2>Additional features</h2>
{{ form_widget(formHiddenDiscount) }}
</div>
On front-end, I can print the value from DB in product.tpl
{$product->hide_discount_table}
That works fine.
What doesn't work:
Upvotes: 1
Views: 1474
Reputation: 1
You should to add your field in ps_product_lang table not ps_product
Upvotes: -1
Reputation: 948
Try in override/classes/Product.php
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::$definition['fields']['hide_discount_table'] = array('type' =>
parent::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');
parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
}
And delete file /var/cache/{your_environment}/class_index.php
Upvotes: 0