Add a check mark to the product image gallery (for example, "Disable / Exclude")

I am trying to copy a new checkbox that will be added to the columns in the image gallery, next to โ€œDisableโ€. Its behavior will be the same as "Disable / Exclude" = Yes / No with a record in the database.

The idea is to add the โ€œUse as pageโ€ checkbox for each image in the image gallery. The goal is to make a JS carousel with all the photos checked as "Use as page".

I have a few things, but I canโ€™t:

  • update data in the database => set 0 or 1 in the "page" field (see below)
  • retrieve data from the database, and then check / uncheck the box depending on the page field.

-> So, my question is: how to update data in the database and retrieve it in the field (0 or 1 depending on the value of the field)?

Thank you all for your very valuable help.


Here is what I did (1.4.1.0):

1- Update table catalog_product_entity_media_gallery_value

A new field has been added (whose name is "page"):

  • tinyint (4) UNSIGNED page No 0

2- The following changes have been made to the Mage_Catalog_Model_Product_Attribute_Backend_Media class

Line 49:

from

$localAttributes = array('label', 'position', 'disabled'); 

to

 $localAttributes = array('label', 'position', 'disabled', 'page'); 

Line 223:

of

 $data['disabled'] = (int) $image['disabled']; 

to

 $data['disabled'] = (int) $image['disabled']; $data['page'] = (int) $image['page']; 

Line 301

from

 $mediaGalleryData['images'][] = array( 'file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude ); 

to

 $mediaGalleryData['images'][] = array( 'file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude, 'page' => (int) $exclude, ); 

Line 328

from

 $fieldsMap = array( 'label' => 'label', 'position' => 'position', 'disabled' => 'disabled', 'exclude' => 'disabled', ); 

to

 $fieldsMap = array( 'label' => 'label', 'position' => 'position', 'disabled' => 'disabled', 'exclude' => 'disabled', 'page' => 'disabled', ); 

3- The following changes were made in the adminhtml / default / default / template / catalog / product / helper / gallery.phtml template

Line 64

of

  <th><?php echo Mage::helper('catalog')->__('Exclude') ?></th> 

to

  <th><?php echo Mage::helper('catalog')->__('Exclude') ?></th> <th><?php echo Mage::helper('catalog')->__('Is Page') ?></th> 

Line 77

from

 <td class="cell-disable a-center"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif;?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td> 

to

 <td class="cell-disable a-center"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif;?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td> <td class="cell-page a-center"><input type="checkbox" <?php if($_block->getElement()->getReadonly()):?> disabled="disabled"<?php endif;?> onclick="<?php echo $_block->getJsObjectName(); ?>.updateImage('__file__')" /></td> 

Line 105

from

to

  <td class="cell-disable"><input type="hidden" />&nbsp;</td> <td class="cell-page last"><input type="hidden" />&nbsp;</td> 
+7
magento
source share
4 answers

This is how I solved the problem and works great. Besides your changes, that too.

1. In Mage_Catalog_Model_Product_Attribute_Backend_Media

change

 public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true) 

to

 public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true, $page = false) 

change

 public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product, $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true) 

to

 public function addImagesWithDifferentMediaAttributes(Mage_Catalog_Model_Product $product, $fileAndAttributesArray, $filePath = '', $move = false, $exclude = true, $page = true) 

change

 $savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude); 

to

 $savedFileName = $this->addImage($product, $filePath . $value['file'], null, $move, $exclude, $page ); 

2. Go to Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media

change

 array('label','position','disabled') 

to

 array('label','position','disabled','page') 

change

  array( 'label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled', ) 

to

  array( 'label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled', 'page_default' => 'page' ) 

3. In js / mage / adminhtml / product.js

change

  this.getFileElement(file, 'cell-label input').value = image.label; this.getFileElement(file, 'cell-position input').value = image.position; this.getFileElement(file, 'cell-remove input').checked = (image.removed == 1); this.getFileElement(file, 'cell-disable input').checked = (image.disabled == 1); 

to

  this.getFileElement(file, 'cell-label input').value = image.label; this.getFileElement(file, 'cell-position input').value = image.position; this.getFileElement(file, 'cell-remove input').checked = (image.removed == 1); this.getFileElement(file, 'cell-disable input').checked = (image.disabled == 1); this.getFileElement(file, 'cell-page input').checked = (image.page == 1); 

change

  this.images[index].label = this .getFileElement(file, 'cell-label input').value; this.images[index].position = this.getFileElement(file, 'cell-position input').value; this.images[index].removed = (this.getFileElement(file, 'cell-remove input').checked ? 1 : 0); this.images[index].disabled = (this.getFileElement(file, 'cell-disable input').checked ? 1 : 0); 

to

  this.images[index].label = this .getFileElement(file, 'cell-label input').value; this.images[index].position = this.getFileElement(file, 'cell-position input').value; this.images[index].removed = (this.getFileElement(file, 'cell-remove input').checked ? 1 : 0); this.images[index].page = (this.getFileElement(file, 'cell-page input').checked ? 1 : 0); this.images[index].disabled = (this.getFileElement(file, 'cell-disable input').checked ? 1 : 0); 

Just use the search text to find where you can change the code. Hope this helps.

+6
source share

After many difficulties, I found that in addition to the initial messages and recommendations of the second poster, you also need to open /app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php , go to line 2023 , where it starts with this:

 $installer->getTable('catalog/product_attribute_media_gallery_value') => array( 

Change this:

 'disabled' => array( 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, 'default' => '0', 'comment' => 'Is Disabled' ) 

For this:

 'disabled' => array( 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, 'default' => '0', 'comment' => 'Is Disabled' ), 'page' => array( 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, 'default' => '0', 'comment' => 'Page' ) 

When Magento saves it, it checks this file to make sure that the received fields match the values โ€‹โ€‹in these arrays.

+1
source share

I got an error

Note: Undefined index 'page'

in the class

Mage_Catalog_Model_Product_Attribute_Backend_Media

on line 224.

I had to change

Js / mage / adminhtml / product.js

 newImage.position = this.getNextPosition(); 

to

 newImage.position = this.getNextPosition(); newImage.page = 0; 

Now it works great.

Thanks.

+1
source share

I recently worked on something similar and found that this piece of code is part of the solution:

 $fieldset->addField('entire_range', 'checkbox', array( 'checked' => $this->getEntireRange()==1 ? 'true' : 'false', 'onclick' => 'this.value = this.checked ? 1 : 0;' 

));

I could not get it to store the value in the database. This is something with the Varien_Data_Form_Element_Checkbox class.

Hope this helps, please post your solution if you find it!

Cheers, JD

0
source share

All Articles