1

I am collecting brand specific products based on the brandId in brandproductlist.php as follows.,

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter(array(
        array('attribute' => $sAttributeName, 'eq' => $brandId))
    )
    ->addAttributeToFilter('type_id','configurable')
    ->setCurPage(1)
    ->setPageSize(50);

But the page load time is not as usual., and it takes more time to load.

Also, in brandproductlist.phtml I have used

$_helper = $this->helper('catalog/output');

Because of the above code the page is taking more time to load?? not sure..

Please advise is there any better way to do the same process and quick page turn around time.

Please advise.

Many thanks in advance.,

Update

filename : brandproductlist.phtml

<?php
// Init ===========================================================================================

$_helper = $this->helper('catalog/output');
$_productCollection = $this->getBrandproductcollection();
$_collectionSize = $_productCollection->count();

$_config = Mage::getStoreConfig('milanoconfig/product_list');

$_columnCount = $_config['column_count'];
if(($_currentCategory = Mage::registry('current_category')) && ($_customColumnCount = $_currentCategory->getProductsColumnCount()) && $_customColumnCount) $_columnCount = $_customColumnCount;

$this->setColumnCount($_columnCount);

$_pictureAspect = $_config['picture_aspect'];
if(($_currentCategory = Mage::registry('current_category')) && ($_customPicAspect = $_currentCategory->getProductsPicAspect()) && $_customPicAspect) $_pictureAspect = $_customPicAspect;

$_hoverSwap = $_config['hover_swap'] == 1;
$_showGallery = $_config['showgallery'] == 1;
$_addToWishlist = $_config['addto_wishlist'] == 1;
$_addToCompare = $_config['addto_compare'] == 1;
$_quickView = $_config['quick_view'] == 1;
$_ajaxAddToCart =  $_config['ajax_addtocart'] == 1;
$_ajaxWishlist =  $_config['ajax_wishlist'] == 1;
$_infiniteScroll =  $_config['infinite_scroll'] == 1;

if($_hoverSwap || $_showGallery) $_listMedia = $this->getLayout()->createBlock("ajax/listmedia");
if($this->getData('singleColumnMode') == 1) $_singleColumnMode = true;

$brand_info = $this->getBranddetails();
$logowidth = Mage::getStoreConfig('netsol_brand/settings/logo_width');
$logoheight = Mage::getStoreConfig('netsol_brand/settings/logo_height');
$baseimagewidth = Mage::getStoreConfig('netsol_brand/settings/brand_image_width');
$baseimageheight = Mage::getStoreConfig('netsol_brand/settings/brand_image_height');
$defaultlogo = Mage::getStoreConfig('netsol_brand/settings/default_logo');
$defaultlogo = str_replace("default/","",$defaultlogo);
$baseimage = $brand_info->getBaseImage();

// Layout ===========================================================================================
if(!$_collectionSize): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div id="brand_detail">
    <h1 class="brand-name"><?php echo $brand_info->getName(); ?></h1>
    <div class="brand-info">
        <span class="brandinfo_baseimage">
            <?php if(($baseimage != '') || ($defaultlogo != '')): ?>
                <img class="brand_baseimage" src="<?php echo ($brand_info->getBaseImage() != '') ? $this->resize('brand/','brand/resize/',$brand_info->getBaseImage(),$baseimagewidth,$baseimageheight) : $this->resize('brand/default/','brand/default/resize/',$defaultlogo,$logowidth,$logoheight); ?>" />
            <?php else:
                $defaultlogo = 'small_image.jpg';
             ?>
                <img class="brand_logo" src="<?php echo $this->resize('brand/default/','brand/default/resize/',$defaultlogo,$logowidth,$logoheight); ?>" />
            <?php endif; ?>
        </span>
        <p class="brand-description"><?php echo $brand_info->getDescription(); ?></p>
    </div>
</div>
<div class="category-products">

    <?php echo $this->getToolbarHtml();

    // List Mode ====================================================================================
    if($this->getMode()!='grid'):
        $_i = 0;
        $imgSize = 225;
    ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <li class="item<?php if($_config['product_list_style'] == 1) echo" boxed"; if(++$_i==$_collectionSize) echo " last"; if($_i==1) echo " first"; if($_i%2) echo " odd"; else echo " even"; ?>" id="item-id-<?php echo $_product->getId()?>">

            <?php if($_showGallery): 
                $_thumbs = $_listMedia->setTemplate("catalog/product/list/mediaall.phtml")->setData('product', $_product)->toHtml();
                if($_thumbs != 'null' && $_thumbs): ?>
                    <div class="gallery-display"><div class="gallery-display-overlay"><?php echo $_thumbs; ?></div></div>
                <?php endif; 
            endif; ?>
            <?php $mainImg = $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgSize); ?>
            <?php if($_hoverSwap): $backImg = $_listMedia->setTemplate("catalog/product/list/media.phtml")->setData('size', $imgSize)->setData('product', $_product)->toHtml(); endif; ?>               
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                <?php if($backImg != 'null' && $backImg): ?><img src="<?php echo $backImg ?>" class="hover-image" width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /><?php endif; ?>
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgSize) ?>" <?php if($backImg != 'null' && $backImg): ?>class="hover-main-image" <?php endif; ?> width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
            </a>

            <div class="product-shop">
                <div class="f-fix">
                    <?php include('view/labels.phtml')  ?>
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <div class="desc std">
                        <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
                    </div>
                    <?php if($_addToWishlist || $_addToCompare): ?>
                        <ul class="add-to-links">
                            <?php if ($_addToWishlist && $this->helper('wishlist')->isAllow()) : ?>
                                <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                            <?php endif; ?>
                            <?php if($_addToCompare && $_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                            <?php endif; ?>
                        </ul>
                    <?php endif; ?>
                </div>
                <div style="clear: both;"></div>
            </div>

            <div class="addtocont">
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->isSaleable()): ?>
                    <?php if (!($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped())) { ?>
                        <a href="<?php echo $this->getAddToCartUrl($_product); ?>" title="<?php echo $this->__('Add to Cart') ?>" class="btn-cart<?php if($_ajaxAddToCart) echo " ajax-addtocart" ?>"<?php if($_ajaxAddToCart): ?> data-id="<?php echo $_product->getId(); ?>"<?php endif; ?>><?php echo $this->__('Add to Cart') ?></a>
                    <?php } else { ?>
                        <a href="<?php if($_ajaxAddToCart) echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId())); else echo $this->getAddToCartUrl($_product); ?>" title="<?php echo $this->__('Add to Cart') ?>" class="btn-cart<?php if($_ajaxAddToCart) echo " btn-quickview" ?>"<?php if($_ajaxAddToCart): ?> data-id="<?php echo $_product->getId(); ?>"<?php endif; ?>><?php echo $this->__('Add to Cart') ?></a>
                    <?php }  ?>
                    <?php if($_quickView){ ?>
                        <a href="<?php echo $this->getUrl('ajax/index/options', array('product_id'=>$_product->getId())); ?>" title="<?php echo $this->__('Quick View') ?>" class="btn-quickview" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Quick View') ?></a>
                    <?php } ?>
                <?php else: ?>
                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?>            
            </div>

        </li>
    <?php endforeach; ?>
    </ol>
    <?php if($_infiniteScroll): ?>
    <script type="text/javascript">
    //<![CDATA[
            jQuery(function($){
                var $container = $('#products-list');
                $container.infinitescroll({
                      navSelector: '.pages',
                      nextSelector: '.pages a.next',
                      itemSelector: '#products-list li.item',
                      maxPage: isTotalPages,
                      loading: { msgText: isMsgText, finishedMsg: isFinishedMsg, img: loaderBckImg }
                  },
                  function(newElements) {
                    var $newElems = $(newElements).css({opacity: 0});
                    $newElems.imagesLoaded(function(){
                        $newElems.animate({opacity: 1});
                        $newElems.attachItemScripts();
                    });
                  }
                );
            });
    //]]>
    </script>
    <?php endif; ?>

    <?php else: // Grid Mode ===========================================================================================



    if(!$_singleColumnMode){ 

        //Left Column Mode
        switch($_columnCount){
            case 3:
                $imgSize = 200;
                $trimSize = 35;
                break;
            case 4:
                $imgSize = 145;
                $trimSize = 25;
                break;
            case 5:
                $imgSize = $smallImgSize = 145;
                $bigImgSize = 340;
                $trimSize = $smallImgTrimSize = 25;
                $bigImgTrimSize = 45;
                break;
        }

    } else { 

        //Single Column Mode
        switch($_columnCount){
            case 3:
                $imgSize = 275;
                $trimSize = 35;
                break;
            case 4:
                $imgSize = 195;
                $trimSize = 30;
                break;
            case 5:
                $imgSize = $smallImgSize = 195;
                $bigImgSize = 435;
                $trimSize = $smallImgTrimSize = 30;
                $bigImgTrimSize = 45;
                break;
        }

    }

    switch($_pictureAspect){
        case 1:
            $imgHeight = $imgSize;
            $smallImgHeight = $smallImgSize;
            $bigImgHeight = $bigImgSize;
            break;
        case 2:
            $imgHeight = floor($imgSize * 1.5);
            $smallImgHeight = floor($smallImgSize * 1.5);
            $bigImgHeight = (abs($smallImgHeight-$smallImgSize)*2)+$bigImgSize;
            break;
        case 3:
            $imgHeight = floor($imgSize * 1.75);
            $smallImgHeight = floor($smallImgSize * 1.75);
            $bigImgHeight = (abs($smallImgHeight-$smallImgSize)*2)+$bigImgSize;
            break;
        case 4:
            $imgHeight = floor($imgSize * 2);
            $smallImgHeight = floor($smallImgSize * 2);
            $bigImgHeight = (abs($smallImgHeight-$smallImgSize)*2)+$bigImgSize;
            break;
        default:
            $imgHeight = $imgSize;
            $smallImgHeight = $smallImgSize;
            $bigImgHeight = $bigImgSize;
            break;
    }

    $i=0; ?>
    <div id="products-grid">
    <?php foreach ($_productCollection as $_product): ?>        
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid columns<?php echo $_columnCount; if($_config['product_list_style'] == 1) echo " boxed"; if((($i-1)/$_columnCount)%2) echo " even"; else echo " odd"; if($i==1) echo " first"; if($i+$_columnCount > $_collectionSize) echo " last"; ?>">
        <?php endif ?>

            <li class="item<?php if($_config['product_list_style'] == 1) echo" boxed"; if($_columnCount == 5) { $imgSize = $smallImgSize; $trimSize = $smallImgTrimSize; $imgHeight = $smallImgHeight; } if(($i-1)%$_columnCount==0): if($_columnCount == 5) { $imgSize = $bigImgSize; $trimSize = $bigImgTrimSize; $imgHeight = $bigImgHeight; } ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>" id="item-id-<?php echo $_product->getId()?>">
                <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php if($_showGallery): 
                        $_thumbs = $_listMedia->setTemplate("catalog/product/list/mediaall.phtml")->setData('product', $_product)->toHtml();
                            if($_thumbs != 'null' && $_thumbs): ?>
                                <div class="gallery-display"><div class="gallery-display-overlay"><?php echo $_thumbs; ?></div></div>
                        <?php endif; 
                endif; ?>
                <?php $mainImg = $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgSize, $imgHeight); ?>
                <?php if($_hoverSwap): $backImg = $_listMedia->setTemplate("catalog/product/list/media.phtml")->setData('size', $imgSize)->setData('height', $imgHeight)->setData('product', $_product)->toHtml(); endif; ?>            

                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <?php if($backImg != 'null' && $backImg): ?><img src="<?php echo $backImg ?>" class="hover-image" width="<?php echo $imgSize ?>" height="<?php echo $imgHeight ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /><?php endif; ?>
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($imgSize, $imgHeight) ?>" <?php if($backImg != 'null' && $backImg): ?>class="hover-main-image" <?php endif; ?> width="<?php echo $imgSize ?>" height="<?php echo $imgHeight ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                </a>

                <div class="moreinfo">
                    <?php /*
                    <div class="addto">
                        <?php if($_product->isSaleable()): ?>
                            <?php if (!($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped())) { ?>
                                <a href="<?php echo $this->getAddToCartUrl($_product); ?>" title="<?php echo $this->__('Add to Cart') ?>" class="btn-cart<?php if($_ajaxAddToCart) echo " ajax-addtocart" ?>"<?php if($_ajaxAddToCart): ?> data-id="<?php echo $_product->getId(); ?>"<?php endif; ?>><?php echo $this->__('Add to Cart') ?></a>
                            <?php } else { ?>
                                <a href="<?php if($_ajaxAddToCart) echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId())); else echo $this->getAddToCartUrl($_product); ?>" title="<?php echo $this->__('Add to Cart') ?>" class="btn-cart<?php if($_ajaxAddToCart) echo " btn-quickview" ?>"<?php if($_ajaxAddToCart): ?> data-id="<?php echo $_product->getId(); ?>"<?php endif; ?>><?php echo $this->__('Add to Cart') ?></a>
                            <?php }  ?>
                        <?php else: ?>
                            <span class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></span>
                        <?php endif; ?>
                        <?php if($_addToWishlist || $_addToCompare || $_quickView){ $_i = 0; ?>
                            <ul class="add-to-links">
                                <?php if ($_addToWishlist && $this->helper('wishlist')->isAllow()) : ?>
                                    <li<?php if(!$_i++): ?> class="last"<?php endif; ?>><a title="<?php echo $this->__('Add to Wishlist') ?>" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                                <?php endif; ?>
                                <?php if($_addToCompare && $_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                    <li<?php if(!$_i++): ?> class="last"<?php endif; ?>><a title="<?php echo $this->__('Add to Compare') ?>" href="<?php echo $_compareUrl ?>" class="link-compare" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                                <?php endif; ?>
                                <?php if($_quickView): ?>
                                    <li<?php if(!$_i++): ?> class="last"<?php endif; ?>><a href="<?php echo $this->getUrl('ajax/index/options', array('product_id'=>$_product->getId())); ?>" title="<?php echo $this->__('Quick View') ?>" class="btn-quickview" data-id="<?php echo $_product->getId(); ?>"><?php echo $this->__('Quick View') ?></a></li>
                                <?php endif; ?>
                            </ul>
                        <?php } ?>
                            <div class="clear"></div>
                    </div>
                    */?>
                    <div class="moreinfo-labels"><?php include('view/labels.phtml'); ?></div>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo Mage::helper('core/string')->truncate($_helper->productAttribute($_product, $_product->getName(), 'name'), $length = $trimSize, $etc = '...', $remainder = '', $breakWords = true); ?></a></h2>
                    <div id='productname<?php echo $_product->getId()?>' style='display:none'><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></div>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <div class="clear"></div>
                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif; ?>        
    <?php endforeach; ?>
    </div>
        <?php if($_infiniteScroll): ?>
        <script type="text/javascript">
        //<![CDATA[ 
            jQuery(function($){
                var $container = $('#products-grid');
                $container.infinitescroll({
                      navSelector: '.pages',
                      nextSelector: '.pages a.next',
                      itemSelector: '.products-grid',
                      maxPage: isTotalPages,
                      loading: { msgText: isMsgText, finishedMsg: isFinishedMsg, img: loaderBckImg }
                  },
                  function(newElements) {
                    var $newElems = $(newElements).css({opacity: 0});
                    $newElems.imagesLoaded(function(){
                        $newElems.animate({opacity: 1});
                        $newElems.find('li.item').attachItemScripts();
                    });
                  }
                );
            });
        //]]>
        </script>
        <?php endif; ?>
    <?php endif; ?>
        <script type="text/javascript">
        //<![CDATA[
            var loaderBckImg = '<?php echo $this->getSkinUrl('images/loading.gif')?>';
            var successMsg = '<?php echo $this->__(' fue añadido a la bolsa de compra.') ?>';
            var continueMsg = '<?php echo $this->__('Seguir comprando') ?>';
            var cartUrl = '<?php echo $this->getUrl('checkout/cart')?>';
            var cartMsg = '<?php echo $this->__('Realizar pedido') ?>';

            <?php if($_infiniteScroll): ?>
            var isTotalPages = <?php echo $_productCollection->getLastPageNumber(); ?>;
            var isCurrentPage = 1;
            var isFinishedMsg = '<?php echo $this->__('No more products to load.'); ?>';
            var isMsgText = '<?php echo $this->__('Loading more products...'); ?>';
            <?php endif; ?>

            (function($){
                $.fn.attachItemScripts = function(){
                    <?php if($this->getMode()=='grid'): ?>$(this).attachAddToActions();<?php endif; ?>
                    <?php if($_showGallery): ?>$(this).find(".gallery-display").attachGalleryDisplay();<?php endif; ?>
                    <?php if($_ajaxAddToCart): ?>$(this).find('.ajax-addtocart').attachAddToCart();<?php endif; ?>
                    <?php if($_quickView): ?>$(this).find('.btn-quickview').attachQuickView();<?php endif; ?>
                    <?php if ($_ajaxWishlist && $_addToWishlist && $this->helper('wishlist')->isAllow()) : ?>$(this).find('.link-wishlist').attachAjaxWhishlist();<?php endif; ?>
                    <?php if($_ajaxWishlist && $_addToCompare): ?>$(this).find('.link-compare').attachAjaxCompare();<?php endif; ?>
                };
            })(jQuery);

            jQuery(function($){ 
                $('.toolbar').jqTransform({imgPath:'<?php echo $this->getSkinUrl('images/jqforms/'); ?>'});
                $('.category-products li.item').attachItemScripts();
                $("a[rel^='prettyPhoto']").prettyPhoto({default_width: 820, default_height: 600, social_tools: ''});
            });
        //]]>
        </script>
    <?php echo $this->getToolbarHtml() ?>
</div>
<?php endif; ?>
  • try to select necessary attribute in addAttributeToSelect('*') – Gopal Patel May 25 '17 at 13:50
  • Yes., I checked the page load time by adding the necessary fields only.. no luck.. still it takes more time to load the pages.. – sathish May 25 '17 at 14:10
0

You can use this way to get the product collection with the default attributes in the configuration:

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
    ->addFieldToFilter('type_id', array('eq'=>'configurable'))
    ->addAttributeToFilter('brand_id', array('eq'=>$brandId))
    ->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
    ->setPageSize(50)
    ->setCurPage(1);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);

Put the attribute code Brand instead of brand_id

  • I tried this solution works well but i am getting duplicate product name, price, images on the brand list product page.. any idea to resolve this? – sathish May 29 '17 at 12:15
  • You can try adding the filter only for configurable products with addFieldToFilter('type_id', array('eq'=>'configurable')) because it could be showing simple products that are visible individually – Andres Rojas Orozco May 30 '17 at 1:28
  • Ok., If I add this code - addFieldToFilter('type_id', array('eq'=>'configurable')) is taking more time to load the page.. that's what my main concern. Please advise is there any other alternative way to get configurable records without duplicated records?? for quick page load time. – sathish May 30 '17 at 6:26
  • You can add the code of how you are loading the product collection in view, because in my case this code loads a page with a collection of 50 products in less than 3 seconds. – Andres Rojas Orozco May 30 '17 at 15:36
  • I have added the full brandproductlist.phtml view file for your reference. Please help me resolve the page load issue.. – sathish May 30 '17 at 17:15

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.