Jump to content

Edit History

PrestashopUser03

PrestashopUser03

Bonjour à tous,

Je migre un site déjà existant possédant déjà ces champs personnalisés rempli pour des milliers de produits, je ne peux donc pas passer par un module pour les intégrer. Les trois champs s'appellent "description_bref", "description_carac" et "description_tailles", ils ont été ajoutés à la table ps_product_lang et importés depuis l'ancienne base jusqu'à la nouvelle.

J'ai suivi la marche à suivre stackoverflow (https://stackoverflow.com/questions/43675696/add-field-in-product-prestashop-1-7)  et j'ai réussi à ajouter les champs qui affichent les informations de la base de donnée que j'ai précédemment migré. Problème : impossible d'enregistrer quoi que ce soit, je reçois le message "Impossible de mettre à jour les paramètres.". Quelqu'un a une idée?

Par la même occasion, quelqu'un sait-il comment ajouter un champ personnalisé booléen?

Merci d'avance pour vos réponses et voici mon code :

Dans override/classes/Product.php:

    public $description_bref;
    public $description_carac;
    public $description_tailles;
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['description_bref'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        self::$definition['fields']['description_carac'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        self::$definition['fields']['description_tailles'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

 

dans src/PrestaShopBundle/Resources/views/admin/product/productpage/panels/essentials.html.twig:

 

            <div class="summary-description-container">
              <ul class="nav nav-tabs bordered">
                <li id="tab_description_short" class="nav-item"><a href="#description_short" data-toggle="tab" class="nav-link description-tab active">{{ 'Summary'|trans({}, 'Admin.Catalog.Feature') }}</a></li>
                <li id="tab_description" class="nav-item"><a href="#description" data-toggle="tab" class="nav-link description-tab">{{ 'Description'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_bref" class="nav-item"><a href="#description_bref" data-toggle="tab" class="nav-link description-tab">{{ 'description_bref'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_carac" class="nav-item"><a href="#description_carac" data-toggle="tab" class="nav-link description-tab">{{ 'description_carac'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_tailles" class="nav-item"><a href="#description_tailles" data-toggle="tab" class="nav-link description-tab">{{ 'description_tailles'|trans({}, 'Admin.Global') }}</a></li>
              </ul>

              <div class="tab-content bordered">
                <div class="tab-pane panel panel-default active" id="description_short">
                  {{ form_widget(formShortDescription) }}
                </div>
                <div class="tab-pane panel panel-default " id="description">
                  {{ form_widget(formDescription) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_bref">
                  {{ form_widget(form.step1.description_bref) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_carac">
                  {{ form_widget(form.step1.description_carac) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_tailles">
                  {{ form_widget(form.step1.description_tailles) }}
                </div>
              </div>
            </div>

dans src/PrestaShopBundle/form/admin/product/productinformation.php à la ligne 213, j'ai ajouté ça :

            ->add('description_bref', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_bref',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_bref', [], 'Admin.Global'),
                'required' => false,
            ])

            ->add('description_carac', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_carac',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_carac', [], 'Admin.Global'),
                'required' => false,
            ])

            ->add('description_tailles', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_tailles',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_tailles', [], 'Admin.Global'),
                'required' => false,
            ])

et dans src/PrestaShopBundle/Model/product/AdminModelAdapter.php à la ligne 213, j'ai ajouté ça vers la ligne 128 :

private $translatableKeys = array(
        'name',
        'description',
        'description_short',
        'description_bref',
        'description_carac',
        'description_tailles',
        'link_rewrite',
        'meta_title',
        'meta_description',
        'available_now',
        'available_later',
        'tags',
        'delivery_in_stock',
        'delivery_out_stock',
    );

    /**
     * Defines unused key for manual binding.
     *
     * @var array
     */
    private $unmapKeys = array(
        'name',
        'description',
        'description_short',
        'description_bref',
        'description_carac',
        'description_tailles',
        'images',
        'related_products',
        'categories',
        'suppliers',
        'display_options',
        'features',
        'specific_price',
        'virtual_product',
        'attachment_product',
    );

et vers la ligne 470 :

    private function mapStep1FromData(Product $product)
    {
        return array(
                'type_product' => $product->getType(),
                'inputPackItems' => [
                    'data' => array_map(
                        function ($p) {
                            return [
                                'id' => $p->id,
                                'id_product_attribute' => isset($p->id_pack_product_attribute)
                                    ? $p->id_pack_product_attribute
                                    : 0,
                                'name' => $p->name,
                                'ref' => $p->reference,
                                'quantity' => $p->pack_quantity,
                                'image' => $p->image,
                            ];
                        },
                        $this->packAdapter->getItems($product->id, $this->locales[0]['id_lang'])
                    ),
                ],
                'name' => $product->name,
                'description' => $product->description,
                'description_short' => $product->description_short,
                'description_bref'=>$product->description_bref,
                'description_carac'=>$product->description_carac,
                'description_tailles'=>$product->description_tailles,
                'active' => $product->active == 0 ? false : true,
                'price_shortcut' => $product->price,
                'qty_0_shortcut' => $product->getQuantity($product->id),
                'categories' => ['tree' => $product->getCategories()],
                'id_category_default' => $product->id_category_default,
                'related_products' => [
                    'data' => array_map(
                        function ($p) {
                            return $p['id_product'];
                        },
                        call_user_func_array(
                            array($product, 'getAccessoriesLight'),
                            array($this->locales[0]['id_lang'], $product->id)
                        )
                    ),
                ],
                'id_manufacturer' => $product->id_manufacturer,
                'features' => $this->getFormFeatures($product),
                'images' => $this->productAdapter->getImages($product->id, $this->locales[0]['id_lang']),
        );
    }

 

PrestashopUser03

PrestashopUser03

Bonjour à tous,

Je migre un site déjà existant possédant déjà ces champs personnalisés rempli pour des milliers de produits, je ne peux donc pas passer par un module pour les intégrer. Les trois champs s'appellent "description_bref", "description_carac" et "description_tailles", ils ont été ajoutés à la table ps_product_lang et importés depuis l'ancienne base jusqu'à la nouvelle.

J'ai suivi la marche à suivre stackoverflow (https://stackoverflow.com/questions/43675696/add-field-in-product-prestashop-1-7)  et j'ai réussi à ajouter les champs qui affichent les informations de la base de donnée que j'ai précédemment migré. Problème : impossible d'enregistrer quoi que ce soit, quelqu'un a une idée?

Par la même occasion, quelqu'un sait-il comment ajouter un champ personnalisé booléen?

Merci d'avance pour vos réponses et voici mon code :

Dans override/classes/Product.php:

    public $description_bref;
    public $description_carac;
    public $description_tailles;
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['description_bref'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        self::$definition['fields']['description_carac'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        self::$definition['fields']['description_tailles'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

 

dans src/PrestaShopBundle/Resources/views/admin/product/productpage/panels/essentials.html.twig:

 

            <div class="summary-description-container">
              <ul class="nav nav-tabs bordered">
                <li id="tab_description_short" class="nav-item"><a href="#description_short" data-toggle="tab" class="nav-link description-tab active">{{ 'Summary'|trans({}, 'Admin.Catalog.Feature') }}</a></li>
                <li id="tab_description" class="nav-item"><a href="#description" data-toggle="tab" class="nav-link description-tab">{{ 'Description'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_bref" class="nav-item"><a href="#description_bref" data-toggle="tab" class="nav-link description-tab">{{ 'description_bref'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_carac" class="nav-item"><a href="#description_carac" data-toggle="tab" class="nav-link description-tab">{{ 'description_carac'|trans({}, 'Admin.Global') }}</a></li>
                <li id="tab_description_tailles" class="nav-item"><a href="#description_tailles" data-toggle="tab" class="nav-link description-tab">{{ 'description_tailles'|trans({}, 'Admin.Global') }}</a></li>
              </ul>

              <div class="tab-content bordered">
                <div class="tab-pane panel panel-default active" id="description_short">
                  {{ form_widget(formShortDescription) }}
                </div>
                <div class="tab-pane panel panel-default " id="description">
                  {{ form_widget(formDescription) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_bref">
                  {{ form_widget(form.step1.description_bref) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_carac">
                  {{ form_widget(form.step1.description_carac) }}
                </div>
                <div class="tab-pane panel panel-default " id="description_tailles">
                  {{ form_widget(form.step1.description_tailles) }}
                </div>
              </div>
            </div>

dans src/PrestaShopBundle/form/admin/product/productinformation.php à la ligne 213, j'ai ajouté ça :

            ->add('description_bref', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_bref',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_bref', [], 'Admin.Global'),
                'required' => false,
            ])

            ->add('description_carac', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_carac',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_carac', [], 'Admin.Global'),
                'required' => false,
            ])

            ->add('description_tailles', TranslateType::class, [
                'type' => FormattedTextareaType::class,
                'options' => [
                    'required' => false,
                    'attr' => [
                        'class' => 'serp-default-description_tailles',
                    ],
                ],
                'locales' => $this->locales,
                'hideTabs' => true,
                'label' => $this->translator->trans('description_tailles', [], 'Admin.Global'),
                'required' => false,
            ])

et dans src/PrestaShopBundle/Model/product/AdminModelAdapter.php à la ligne 213, j'ai ajouté ça vers la ligne 128 :

private $translatableKeys = array(
        'name',
        'description',
        'description_short',
        'description_bref',
        'description_carac',
        'description_tailles',
        'link_rewrite',
        'meta_title',
        'meta_description',
        'available_now',
        'available_later',
        'tags',
        'delivery_in_stock',
        'delivery_out_stock',
    );

    /**
     * Defines unused key for manual binding.
     *
     * @var array
     */
    private $unmapKeys = array(
        'name',
        'description',
        'description_short',
        'description_bref',
        'description_carac',
        'description_tailles',
        'images',
        'related_products',
        'categories',
        'suppliers',
        'display_options',
        'features',
        'specific_price',
        'virtual_product',
        'attachment_product',
    );

et vers la ligne 470 :

    private function mapStep1FromData(Product $product)
    {
        return array(
                'type_product' => $product->getType(),
                'inputPackItems' => [
                    'data' => array_map(
                        function ($p) {
                            return [
                                'id' => $p->id,
                                'id_product_attribute' => isset($p->id_pack_product_attribute)
                                    ? $p->id_pack_product_attribute
                                    : 0,
                                'name' => $p->name,
                                'ref' => $p->reference,
                                'quantity' => $p->pack_quantity,
                                'image' => $p->image,
                            ];
                        },
                        $this->packAdapter->getItems($product->id, $this->locales[0]['id_lang'])
                    ),
                ],
                'name' => $product->name,
                'description' => $product->description,
                'description_short' => $product->description_short,
                'description_bref'=>$product->description_bref,
                'description_carac'=>$product->description_carac,
                'description_tailles'=>$product->description_tailles,
                'active' => $product->active == 0 ? false : true,
                'price_shortcut' => $product->price,
                'qty_0_shortcut' => $product->getQuantity($product->id),
                'categories' => ['tree' => $product->getCategories()],
                'id_category_default' => $product->id_category_default,
                'related_products' => [
                    'data' => array_map(
                        function ($p) {
                            return $p['id_product'];
                        },
                        call_user_func_array(
                            array($product, 'getAccessoriesLight'),
                            array($this->locales[0]['id_lang'], $product->id)
                        )
                    ),
                ],
                'id_manufacturer' => $product->id_manufacturer,
                'features' => $this->getFormFeatures($product),
                'images' => $this->productAdapter->getImages($product->id, $this->locales[0]['id_lang']),
        );
    }

 

×
×
  • Create New...