0

I have some products with 200+ images and the product detail pages become very slow ( depending on the number of images can crash my browser too), probably because of the big amount of html and some js )

I would like to load the images tab with ajax, in this way the problem should be reduces ( any other suggestion is welcome )

How can I accomplish this ?

What I can see it that the tab is loaded by Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs::_prepareLayout()

So I have rewriten this block and modified the _prepareLayout() method so that the tab is not loaded at the first but is set to be ajax:

              if ($group->getAttributeGroupName() == 'Images') {
                    $this->addTab('group_' . $group->getId(), array(
                        'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
                        'url' => $this->getUrl('*/*/images', array('_current' => true)),
                        'class' => 'ajax',
                    ));
                } else {
                    $this->addTab('group_' . $group->getId(), array(
                        'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
                        'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
                            'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                            ->setGroupAttributes($attributes)
                            ->toHtml()),
                    ));
                }

Then I rewrited the controller and created this action

public function imagesAction()
    {
        $product = $this->_initProduct();
        $setId = $product->getAttributeSetId();

        $group = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->setAttributeSetFilter($setId)
            ->addFieldToFilter('attribute_group_name', 'Images')
            ->setSortOrder()
            ->getFirstItem();

        $attributes = $product->getAttributes($group->getId(), true);

        $html = $this->getLayout()->createBlock('burnout_productpart/adminhtml_catalog_product_edit_tabs_images',
            'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
            ->setGroupAttributes($attributes)
            ->toHtml();
        Mage::getSingleton('core/translate_inline')->processResponseBody($html);

        echo $html;
    }

The content loads but I have some js script errors:

Uncaught ReferenceError: media_gallery_contentJsObject is not defined
1

Have you tried to check: Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs::_prepareLayout. In there take a look to how this is done for categories.

Then you can apply the same for the image attribute. Instead doing something like:

$this->addTab('group_'.$group->getId(), array(
    'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
    'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
                    'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                        ->setGroupAttributes($attributes)
                        ->toHtml()),
            ));

inside the loop, you can then add the tab via ajax (like for categories) by adding a custom controller who prints the image block:

$this->getLayout()->createBlock($this->getAttributeTabBlock(),
                    'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
                        ->setGroupAttributes($attributes)
                        ->toHtml()
  • check update ... I managed that but I still have some js errors – Fra Apr 15 '16 at 9:53
  • Try to define that variable when showing the product. I'm pretty sure the content will be populated after you load by ajax the block. – davidmpaz Apr 15 '16 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.