Friday 28 March 2014

Magento: Resize category image and thumbnail


<?php
$mediaPath=Mage::getBaseDir('media')."/catalog/category/resized/";
                        if(!is_dir($mediaPath)) mkdir($mediaPath,0777);
 foreach($collections as $subcate){

                                 
                                    $_curCat_sub = Mage::getModel('catalog/category')->load($subcate->getId());
                                    $count_sub = $_curCat_sub->getProductCount();
                                    $_subimage=$subcate->getThumbnail();
                                    if($_subimage!=''){
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail(); //Real path
                                 
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail();
                                 
                                    $imageResized=Mage::getBaseDir('media')."/catalog/category/resized/".$subcate->getThumbnail();
                                    $imageObj = new Varien_Image($_imageUrl);
                                    $imageObj->constrainOnly(TRUE);
                                    $imageObj->keepAspectRatio(TRUE);
                                    $imageObj->keepFrame(FALSE);
                                    $imageObj->resize(null,300);
                                    $imageObj->save($imageResized);
                                    $mediaurl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
                                    $imageResized = $mediaurl."/catalog/category/resized/".$subcate->getThumbnail();
?>
<img src="<?php echo $imageResized;?>"/>
<?php } ?>

Tuesday 25 March 2014

How to detect the width of a web browser using jQuery


<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(window).resize(function(){

         var current_width = jQuery(window).width();
   
   
            if(current_width < 400){
           
           
            }
});
  });
</script>

Monday 10 March 2014

Magento cart update on key up

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" /> 

Magento Product Attribute value


<?php
                   $attributeInterests = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand');
                   $InterestsSize=$attributeInterests->getSource()->getAllOptions(true, true);
                   $InterestsSizeCount = count($InterestsSize);
                   $InterestsColumnCount = 6;
                   $ii=0;?>
                    <ul>
                   <?php
                   foreach ($attributeInterests->getSource()->getAllOptions(true, true) as $option){ ?>
                   <?php if($option['value'] > 0) { ?>
                 
                 
                 
                           <li><a href="<?php echo $this->getUrl();?>catalogsearch/advanced/result/?flag=adv&description=&brand=<?php echo  $option['value']; ?>"><span><?php echo $option['label']; ?></span> <img src="<?php echo $this->getSkinUrl();?>images/bg.png" alt="bg" width="188" height="28" /></a></li>
                         
                 
                   <?php  }  } ?>
                    </ul>