Jump to content

How to add new attribute to product images?


DARLEI FERNANDO ZILL

Recommended Posts

I recently created a module to add a new attribute to product images

 

It works perfectly with the field added by the module, however the native field "cover" has stopped working (the value is not saved while the module is active).

 

In addition to the module files and overrides (Image.php and AdminProductsController.php), i changed some files from the "src" folder.

 

 src/PrestaShopBundle/Controller/Admin/ProductImageController.php
->add('infografico', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(
    'label' => $translator->trans('Infográfico', array(), 'Admin.Catalog.Feature'),
    'required' => false,
))
src/Adapter/Product/AdminProductWrapper.php (ajaxProcessUpdateImage)
$img->infografico = $data['infografico'];
src/Adapter/Product/ProductDataProvider.php (getImage)
'infografico' => $imageData->infografico ? true : false,
src/PrestaShopBundle/Resources/views/Admin/ProductImage/form.html.twig
[spam-filter] form_widget(form.infografico) [spam-filter] 

Am I forgetting something or doing something wrong?

 

Thank you in advance for any help you can give me.

 

My Prestashop version - 1.7.2.1

 

Link to comment
Share on other sites

  • 1 month later...

 

If you have override the methode ajaxProcessUpdateImage in AdminProductWrapper you need add the update of cover image!

Quote

 $img = new Image((int)$idImage);
        if ($data['cover']) {
            Image::deleteCover((int)$img->id_product);
            $img->cover = 1;
        }
        $img->legend = $data['legend'];
        $img->update();

 

Link to comment
Share on other sites

Yes Nassnus...my function:

 

public function ajaxProcessUpdateImage($idImage, $data)
    {
        $img = new Image((int)$idImage);
        if ($data['cover']) {
            Image::deleteCover((int)$img->id_product);
            $img->cover = 1;
        }
        $img->legend = $data['legend'];
		if ($data['infografico']) {
			$img->infografico = 1;
        }
        $img->update();
        return $img;
    }

 

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...