Jump to content

How to add new field in product table of prestashop 1.7.4.4?


VikashChaudhary

Recommended Posts

I want to add point field in my product table. I have alter product table and add point field in database.

Then Override product class as 

<?php

class Product extends ProductCore
{

    /** @var int point */
    public $point;


    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        Product::$definition['fields']['point'] = array(
            'type' => self::TYPE_FLOAT,
            'shop' => true,
            'validate' => 'isUnsignedInt',
            'required' => true
        );
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

}

Changed in buildForm method of \PrestaShopBundle\Form\Admin\ProductPrice class

 

->add(
    'point',
    FormType\MoneyType::class,
    array(
        'required' => false,
        'mapped' => false,
        'label' => $this->translator->trans('Point (tax incl.)', [], 'Admin.Catalog.Feature'),
        'currency' => $this->currency->iso_code,
    )
)

Also changed getFormData method of \PrestaShopBundle\Model\Product\AdminModelAdapter class

 

'step2' => [
    'price' => $this->product->price,
    'point' => $this->product->point,

Also changed in src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/pricing.html.twig view file

 

<div class="col-xl-2 col-lg-3">
  <label class="form-control-label">{{ pricingForm.price.vars.label }}</label>
  {{ form_errors(pricingForm.price) }}
  {{ form_widget(pricingForm.price) }}
</div>

 

After doing this I am able to see field in admin section of product update form within price tab but I am not able to save value in database.

I want to know what is the best practice for adding new field in product table of prestashop 1.7.4.4 or what I am missing. Please help thanks in advance

 

  • Like 1
Link to comment
Share on other sites

  • 9 months later...

Hello, I had following a tutorial to try to add a new field to admin, but could not save to BD. After testing some modifications I was able to save by modifying the information below, see if it doesn't work for you or others who have the same problem:

'regal' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),

Change to:

'regal' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 64),

 

I followed the same as the default reference field.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...