Thursday 30 June 2011

Send Every Store Activity Email To Store Owner In Magento

We can do this by editiing Templete.php file at the location given below
app\code\core\Mage\Core\Model\Email
search for code below
$this->setSentSuccess($this->send($email, $name, $vars));
and just below the searched code paste the code given.
$this->setSentSuccess($this->send('owner@store.com', $name, $vars));
now every email that shoots from Magento store it will deliverd to owner also.

Get Customer GroupId in Magento

firstly you need to check if customer is loged in or not
$logged_in = Mage::getSingleton( 'customer/session' )->isLoggedIn();
now use the code below to check CustomerGroupID
$group = Mage::getSingleton('customer/session')->getCustomerGroupId();

Magento Custom Form With Notification

Step1: you need to creat a XML file same at location given below, if folder does not exist please create it
/app/etc/modules/MageWorks_Contact.xml
and paste the content below in MageWorks_Contact.xml
 
    
        
            true
            local
        
        

Step 2: Now create Confix.xml at the location below
app/code/local/MageWorks/Contact/etc/config.xml 
and paste the content below to config.xml file
 

    
        
            0.1.0
        
       
 
    
        
            
                standard
                
                    MageWorks_Contact
                    MageWorks_Contact
                
            
        
        

Step 3: Now create controller at the folloing location
app/code/local/MageWorks/Contact/controllers/IndexController.php
now paste the content below to controller
class MageWorks_Contact_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        //Get current layout state
        $this->loadLayout();   
 
        $block = $this->getLayout()->createBlock(
            'Mage_Core_Block_Template',
            'mageworks.contact',
            array(
                'template' => 'mageworks/contact.phtml'
            )
        );
 
        $this->getLayout()->getBlock('content')->append($block);
        //$this->getLayout()->getBlock('right')->insert($block, 'catalog.compare.sidebar', true);
 
        $this->_initLayoutMessages('core/session');
 
        $this->renderLayout();
    }
 
    public function sendemailAction()
    {
        //Fetch submited params
        $params = $this->getRequest()->getParams();
 
        $mail = new Zend_Mail();
        $mail->setBodyText($params['comment']);
        $mail->setFrom($params['email'], $params['name']);
        $mail->addTo('somebody_else@example.com', 'Some Recipient');
        $mail->setSubject('Test MageWorks_Contact Module for Magento');
        try {
            $mail->send();
        }        
        catch(Exception $ex) {
            Mage::getSingleton('core/session')->addError('Unable to send email. Sample of a custom notification error from MageWorks_Contact.');
 
        }
 
        //Redirect back to index action of (this) mageworks-contact controller
        $this->_redirect('mageworks-contact/');
    }
}
 
Step 4: Create view
app/design/frontend/default/default/template/mageworks/contact.phtml
paste content below to contact.phtml

MageWorks_Contact module sample












  •  



* Required Fields

Tuesday 28 June 2011

Get Nicely Formated Final Price In Magento


$_coreHelper = $this->helper('core');
$_taxHelper = $this->helper(’tax’);
$_finalPriceInclTax = $_taxHelper->getPrice($_product, $_product->getFinalPrice(), true);
$_finalPriceFormated = $_coreHelper->currency($_finalPriceInclTax,true,false);
echo $_finalPriceFormated;

Magento Image Switcher On MouseOver

Step1. open file on location given below

app/design/frontend/default/default/template/catalog/product/view/media.phtml

Step2. Search the code in media.phtml file
<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;">
   <!--nested img tag stays the same-->
</a>

Step 3. Replace searched code with code below.

<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $_product->getName();?>" onmouseover="$('image').src = this.href; return false;">
   <!--nested img tag stays the same-->
</a>

Sunday 26 June 2011

How To Set Magento Base Currency Programmatically

open index.php on root and paste the code
Mage::app()->getStore()->setCurrentCurrencyCode('USD');

just above this code

Mage::run($mageRunCode, $mageRunType);

Magento LogIn with Facebook Account extension

Step 1.

Create Facebook App.

For Facebook Connect to work you need to Setup Application on Facebook and obtain its API Key and Application Secret.

Use your store name as application name and read and accept terms of service. On second screen switch to Web Site tab and set Site URL to the store domain where you plan to implement Facebook Connect. Save Changes. Other Connect settings are optional, but you might want to add store logo for example.

Step 2.
Download extension from link below:
Works_Facebook_Login
unzip folder and copy app folder from Works_Facebook_Login and paste it to you magento folder it will ask to overwrite click ok.

Step 3.
Magento Setup

Once you obtain two keys navigate to Magento Administration, copy/paste them to appropriate fields under Configuration->Customer->Facebook Connect, set Enabled to Yes and you’re good to go. If you’re updating from previous releases, you also need to Enable it to work.

Default template files (frontend/default/default/template/facebook/*) and layout (layout/facebook.xml) makes Facebook Connect work out of the box with default theme, but we tried to make customizations as easy as possible so all you need to do is add button or link with “facebook-connect” rel attribute set anywhere in the theme, static block or cms page, for example:

<button rel=”facebook-connect” class=”form-button” type=”submit”><span>Connect with Facebook</span></button>
<a rel=”facebook-connect”>Connect with Facebook</a>