Google+

Pages

Saturday, June 23, 2012

Magento: How to call static block on phtml file in magento

To call a static block on a phtml file, there are two ways:
i.    To call it with help of  [layout_file].xml
ii.   To call it directly from .phtml file

To call static block directly from .phtml file, use following syntax:

<?php echo $this->getLayout()->createBlock('[your_block_reference]')
->setBlockId('your_block_id')->toHtml() ?>

For example: If your block is a cms block, you can call it by:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-new-block')->toHtml() ?>

or if your block is not a cms block, and it lies in some folder(say: page/html), then you can call it by:

<?php echo $this->getLayout()->createBlock(' page/html')->setBlockId('my-new-block')->toHtml() ?>

To call it with help of  [layout_file].xml, go to:
app > design > frontend > [your package] > [your theme] > layout folder and Open the file that references the page you intend to put the block into.

Find the spot in your .xml where you would like your block to appear and insert the following code:

<block type="[your_block_reference]" name="[your_block_identifier]">
  <action method="setBlockId"><block_id> [your_block_identifier] </block_id></action>
</block>

For example:

If your block file lies in some folder(say: page/html), then you can call it by:

<block type="page/html" name="[your_block_identifier]">
  <action method="setBlockId"><block_id>page/html</block_id></action>
</block>

That's all in this section.. Enjoy.. :)


Friday, June 22, 2012

How to disable user registration in Magento

There are many situations, when we don't want to allow new users to checkout on our website. In such situations, the question arises, how to remove/ disable registration process from front-end. Try below procedure to do this:

i.      Add app\etc\modules\ Mycode_All.xml

       <?xml version="1.0"?>
       <config>
           <modules>
       <Mycode_Registrationremove>
                   <active>true</active>
   <codePool>local</codePool>
       </Mycode_Registrationremove>
   </modules>
       </config>

 ii.     Then create following folder structure:
        app/code/local/Mycode/etc
        app/code/local/Mycode/Helper
        app/code/local/Mycode/controllers

In app/code/local/Mycode/etc folder, create a new file named config.xml:
Paste below code in it

<?xml version="1.0"?>
<config>
  <modules>
    <Mycode_Registrationremove>
      <version>0.1.0</version>
    </Mycode_Registrationremove>
  </modules>
  <global>
    <rewrite>
      <mycode_registrationremove_account_create>
        <from><![CDATA[#^/customer/account/create$#]]></from>
        <to>/registrationremove/account/create</to>
      </mycode_registrationremove_account_create>
      <mycode_registrationremove_account_createPost>
        <from><![CDATA[#^/customer/account/create/$#]]></from>
        <to>/registrationremove/account/create</to>
      </mycode_registrationremove_account_createPost>
    </rewrite>
  </global>
  <frontend>
    <routers>
      <registrationremove>
        <use>standard</use>
          <args>
            <module>Mycode_Registrationremove</module>
            <frontName>registrationremove</frontName>
          </args>
      </registrationremove>
    </routers>
  </frontend>
</config>
Now create a new file (Data.php) in app/code/local/Mycode/Helper 
folder, and paste below code in it:

<?php 
class Mycode_Registrationremove_Helper_Data extends Mage_Core_Helper_Abstract
{
} ?>
Now create a new file (AccountController.php) in
app/code/local/Mycode/controllers folder:
and paste below code in it:
<?php 
require_once 'Mage/Customer/controllers/AccountController.php';

class Mycode_Registrationremove_AccountController extends
Mage_Customer_AccountController
{
    public function createAction()
    {
      $this->_redirect('*/*');
    }
} ?>





That's all..
It will disable registration process from your website, and when some one will try to go to User Registration page, he/ she will be re-directed to Login page.

But still some things to remove it from every where from your site.
There are two places where you can see button or radio button for 
user registration, which mislead a user that user registration is 
possible.

These two places are:

Login page: Here you see a button named Register

On onepage checkout page: Here you can see a radio button with 
label Register.

You need to hide or remove these also, to completely remove the 
registration process. To do this, go to:

app/design/frontend/[package]/[theme]/template/persistent/checkout/onepage/login.phtml


and comment out following code:

<div class="col-1">
  <h3><?php if( $this->getQuote()->isAllowedGuestCheckout() ): ?>
<?php echo $this->__('Checkout as a Guest or Register') ?>
<?php else: ?>
<?php echo $this->__('Register to Create an Account') ?>
<?php endif; ?>
  </h3>
  <?php if( $this->getQuote()->isAllowedGuestCheckout() ): ?>
    <p>
      <?php echo $this->__('Register with us for future convenience:') ?>
    </p>
  <?php else: ?>
    <p>
      <strong><?php echo $this->__('Register and save time!') ?></strong>
      <br />
      <?php echo $this->__('Register with us for future convenience:') ?>
    </p>
    <ul>
      <li><?php echo $this->__('Fast and easy check out') ?></li>
      <li>
<?php echo $this->__('Easy access to your order history and status')?>
      </li>
    </ul>
  <?php endif; ?>
  <?php if( $this->getQuote()->isAllowedGuestCheckout() ): ?>
   <ul class="form-list">
     <?php if( $this->getQuote()->isAllowedGuestCheckout() ): ?>
       <li class="control">
        <input type="radio" name="checkout_method" id="login:guest" value="guest"<?php if($this->getQuote()->getCheckoutMethod()==Mage_Checkout_Model_Type_Onepage::METHOD_GUEST): ?> checked="checked"<?php endif; ?> class="radio" />
<label for="login:guest"><?php echo $this->__('Checkout as Guest') ?></label>
       </li>
     <?php endif; ?>
     <li class="control">
       <input type="radio" name="checkout_method" id="login:register" value="register"<?php if($this->getQuote()->getCheckoutMethod()==Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER || !$this->getQuote()->isAllowedGuestCheckout()): ?> checked="checked"<?php endif ?> class="radio" /><label for="login:register"><?php echo $this->__('Register') ?></label>
     </li>
   </ul>
   <h4><?php echo $this->__('Register and save time!') ?></h4>
     <p><?php echo $this->__('Register with us for future convenience:') ?></p>
       <ul class="ul">
         <li><?php echo $this->__('Fast and easy check out') ?></li>
         <li><?php echo $this->__('Easy access to your order history and status') ?></li>
       </ul>
  <?php else: ?>
    <input type="hidden" name="checkout_method" id="login:register" value="register" checked="checked" />
  <?php endif; ?>
</div>

and

<div class="col-1">
  <div class="buttons-set">
    <p class="required">&nbsp;</p>
      <?php if ($this->getQuote()->isAllowedGuestCheckout()): ?>
        <button id="onepage-guest-register-button" type="button" class="button" onclick="checkout.setMethod();">
            <span><span><?php echo $this->__('Continue') ?></span></span>
        </button>
      <?php else: ?>
        <form action="<?php echo $this->getUrl('persistent/index/saveMethod'); ?>">
          <button id="onepage-guest-register-button" type="submit" class="button">
            <span><span><?php echo $this->__('Register') ?></span></span>
          </button>
        </form>
      <?php endif; ?>
  </div>
</div>

Now go to app/design/frontend/[package]/[theme]/template/persistent/customer/form/login.phtml

and comment out following lines:
<div class="col-1 new-users">
    <div class="content">
        <h2><?php echo $this->__('New Customers') ?></h2>
          <p><?php echo $this->__('By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.') ?></p>
    </div>
</div>

and

<div class="col-1 new-users">
    <div class="buttons-set">
        <button type="button" title="<?php echo $this->__('Create an Account') ?>" class="button" onclick="window.location='<?php echo Mage::helper('persistent')->getCreateAccountUrl($this->getCreateAccountUrl()) ?>';"><span><span><?php echo $this->__('Create an Account') ?></span></span></button>
   </div>
</div>

That's all.. It will disable user registration from your website.




Magento: Transactional Email Template Preview Showing HTML code

In some magento installations(like: Magento 1.6.1, Magento 1.6.2 etc), when we try to see preview of any transactional email template, it shows html only.
 To fix this problem, here is an easy fix :
Go to:
  app/code/core/Mage/Adminhtml/Block/System/Email/Template
and copy preview.php, and override it in your local folder.
Find:
$template->setTemplateText(
$this->escapeHtml($template->getTemplateText())

);

and comment out these three lines, like below:

//$template->setTemplateText(
//$this->escapeHtml($template->getTemplateText())
//);

That's all..
Now clear your Magento's Cache and enjoy.. :)

Magento: How to delete test orders in magento

To delete test order from magento:
  1. Login to Admin Panel and go to Sales-->Orders.
  2. Note down your test order ids, for example: 100000001,100000002,100000003,100000111,100000112,100000199
  3. Now create a php file in magento root directory and name it: deleteOrders.php
  4. Now copy below code and paste it in your file:


    <?php
    require 'app/Mage.php';
    Mage::app('admin')->setUseSessionInUrl(false);                                                                                                                 //replace your own orders numbers here:
    $test_order_ids
    =array(
     
    '100000001',
     
    '100000002',
     
    '100000003',
     
    '100000109',
     
    '100000112',
     
    '100000134'
    );
    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."
     ?>
     
  5. Now go to your browsers address bar and run file from here like:
    [Your_Magento_Base_URL] /deleteOrders.php


  6. At the end, delete deleteOrders.php.

    That's All.. Cheers :)