Skip to main content

Posts

Showing posts with the label Show category Image in main Navigation in magento

Redirect A Customer To A Custom Url/Page After Logging In Magento

if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){     $session = Mage::getSingleton('customer/session');     $beforAutoUrl = Mage::getBaseUrl('web').$_SERVER['REQUEST_URI'];     $session->setBeforeAuthUrl($beforAutoUrl);     Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login"));     }else{     echo "Operation Will Perform";    }

How to make Renderer in custom module magento

1)managedesign is my custom module 2) /app/code/local/Managedesign/Managedesign/Block/Adminhtml/Managedesign/Grid.php     call rander method:     "design_id" ia a database attribut;              $this->addColumn("design_id", array(             "header" => Mage::helper("managedesign")->__("Link"),             "index" => "design_id",             'renderer'  => 'managedesign/adminhtml_managedesign_renderer_image'                 ));                  3)crerate a folder Renderer and make a file Image.php     /app/code/local/Managedesign/Managedesign/Block/Adminhtml/Managedesign/Renderer/Image.php               class Managedesign_Managedesign_Block_Adminhtml_Managedesign_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{           public function render(Varien_Object $row)     {         $html = '<img width="105" height="15" ';    

get directory paths, get Base URLs, get URLs in static block, get secure URL in Magento

1) Get Directory paths  Mage::getBaseDir()  //output : /var/www/html/magento Mage::getBaseDir('app')  //output : /var/www/html/magento/app Mage::getBaseDir('media') //output : /var/www/html/magento/media Mage::getBaseDir(‘design’) => Get design directory path Mage::getBaseDir(‘code’) => Gives code directory file path Mage::getBaseDir(‘lib’) => Gives lib directory file path Mage::getBaseDir(‘skin’) => Gives skin directory file path Mage::getBaseDir(‘var’) => Gives var directory file path Mage::getBaseDir(‘cache’) => Gives cache directory file path Mage::getBaseDir(‘log’) => Gives log directory file path       2) Get Base URL  Mage::getBaseUrl() => Get base url path e.g. http://yourwebsite.com/  Mage::getBaseUrl('media') => Get MEDIA folder path e.g. http://yourwebsite.com/media/  Mage::getBaseUrl('js') => Get JS folder path e.g. http://yourwebsite.com/js/  Mage::getBaseUrl('skin') => Get SKIN folder p

programaticaly Insert and select quary In magento

 INSERT QUERY include('../app/Mage.php'); Mage::app(); $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $sql="INSERT INTO opd_uploads SET extension='$extension', sessionId='$sessionId', ip='$ip', status=1, dateTime=now()"; $write->query($sql); //lastInserted ID $imageId = $write->lastInsertId(); SELECT QUERY $read= Mage::getSingleton('core/resource')->getConnection('core_read');                   $value=$read->query("select * from opd_uploads WHERE id='".$imageRowId."'");          $row = $value->fetch();          $orgFilExt=$row['extension'];

Magento programmatically remove product images

/* Remove Product media Image Start*/ $ptoductId=120; $productImgRemov= Mage::getModel('catalog/product')->load($ptoductId); $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId(); $mediaGalleryAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode($entityTypeId, 'media_gallery'); $gallery = $productImgRemov->getMediaGalleryImages(); foreach ($gallery as $image) $mediaGalleryAttribute->getBackend()->removeImage($productImgRemov, $image->getFile()); $productImgRemov->save(); /* Remove Product media Image End*/

Remove assign category from product

/*-----------Remove product From assign category Start------------- */ $productId=5; $product=Mage::getModel("catalog/product")->load($productId); $productIdss=$product->getId(); $all_cats = $product->getCategoryIds($productIdss);   foreach($all_cats as $_catId) { $product=Mage::getSingleton('catalog/category_api')->removeProduct($_catId,$productIdss); } /*-----------Remove product From assign category End------------- */

delete order items in magento

<?php require 'app/Mage.php'; Mage::app('admin')->setUseSessionInUrl(false);                                                                                                                //replace your own orders numbers here: $test_order_ids=array('100000001','100000002','100000003'); foreach($test_order_ids as $id){     try{         Mage::getModel('sales/order')->loadByIncrementId($id)->delete();         echo "order #".$id." is removed".PHP_EOL;     }catch(Exception $e){         echo "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;     } } echo "complete." ?>

How to add tab in Customer Information in Magento Admin

Step 1) Override the file /app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php, Inside _beforeToHtml() method, add the following code: $ this -> addTab ( 'Custom' , array (      'label'   = > Mage :: helper ( 'customer' ) -> __ ( 'Custom' ) ,      'class'   = >     'ajax' ,      'url'     = >     $ this -> getUrl ( '*/*/custom' , array ( '_current' = > true ) ) , ) ) ; Step 2)  Override the file /app/code/core/Mage/Adminhtml/controllers/CustomerController.php, Add the following code: public function customAction() { $this->_initCustomer(); $this->getResponse()->setBody( Mage::app()->getLayout()->createBlock('core/template')->setTemplate('custom/customer/tab/custom.phtml')->setCustomerId(Mage::registry('current_customer')->getId())         ->setUseAjax(true)->toHtml() ); } Step

Create custom attribute in magento category

HI friends to create custom attribute for product is to easy , but for a category its tricky. For creating attribute in category general tab use this code and create a new file, place it in root folder like http://localhost/magento-1.6.2.0/magento/attribute.php and run it. its All done enjoy:)  +ankur rai   <?php require_once ( 'app/Mage.php' ); Mage :: app () -> setCurrentStore (Mage :: getModel ( 'core/store' ) -> load (Mage_Core_Model_App :: ADMIN_STORE_ID )); $installer = new Mage_Sales_Model_Mysql4_Setup; $attribute = array ( 'type' => 'int' , 'label' => 'Is Open' , 'input' => 'select' , 'source' => 'eav/entity_attribute_source_boolean' , 'global' => Mage_Catalog_Model_Resource_Eav_Attribute :: SCOPE_GLOBAL , 'visible' => true , 'required' => false , 'user_defined' => true , '

Improve Your YSlow Grade Using .htaccess

Put these lines in you .htaccess and see magic :)                                                                           < FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$" > Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT" < / FilesMatch > <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"> Header unset ETag FileETag None </FilesMatch> <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"> Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT" Header unset ETag FileETag None </FilesMatch>

How to configure Magento to work with a new domain

Select your Magento database from the  left menu, find the table called  core_config_data and click on it.  Click the Browse tab and edit the first two fields: web/unsecure/base_url web/secure/base_url by clicking the pen icon in front of each of them. Replace your old domain name with your new one and click the Go button to save the change. Clear the Magento cache. The Magento cache folder is located in your Magento installation directory > /var/cache. To clear the cache, simply delete the folder.  Many Magento issues can be fixed just by deleting the cache.

Get best seller,newarrivals ,most viewed product collection

//Get most sold product collection <?php $visibility = array ( Mage_Catalog_Model_Product_Visibility :: VISIBILITY_BOTH , Mage_Catalog_Model_Product_Visibility :: VISIBILITY_IN_CATALOG ); $_productCollection2 = Mage :: getResourceModel ( 'reports/product_collection' ) -> addAttributeToSelect ( '*' ) -> addOrderedQty () -> addAttributeToFilter ( 'visibility' , $visibility ) -> setOrder ( 'ordered_qty' , 'desc' ); //Get most viewed product collection $_productCollection1 = Mage :: getResourceModel ( 'reports/product_collection' ) -> addAttributeToSelect ( '*' ) -> setStoreId ( $storeId ) -> addStoreFilter ( $storeId ) -> addViewsCount (); //->setPageSize($productCount); Mage :: getSingleton ( 'catalog/product_status' ) -> addVisibleFilterToCollection ( $_productCollection1 ); Mage :: getSingleton ( 'catalog/product_visi