Add code

Friday 29 April 2016

How to Add the list of cities in states to Magento.


Adding the list of cities in states to Magento.
 I have tested this and worked for me on my server.
 I have used the Region & City Manager extension.
Region & City Manager extension allows you to add regions and cities for any countries in the world.

Check once the extension from here :

https://www.magentocommerce.com/magento-connect/catalog/product/view/id/30552/s/region-city-manager/

Monday 21 March 2016

Hide Magento Attributes with no Value

This can be done with a small piece of code. Find and open the attributes.phtml file. This file can be found here:/app/design/frontend/[theme name]/[package name]/template/catalog/product/view/attribute.phtml
Open the file and search for the following lines:


<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>

Replace the entire foreach loop with the following lines of code:

<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

Friday 19 February 2016

How to move magento search bar from header to sidebar?

Edit "app/design/frontend/<your theme>/<your theme>/layout/catalogsearch.xml"

Fine the line:


<reference name="header">
    <block as="topSearch" name="top.search" template="catalogsearch/form.mini.phtml" type="core/template">
</block>
</reference>

Replace the reference name to left or right.

<reference name="left or right(your wish)">
    <block as="topSearch" name="top.search" template="catalogsearch/form.mini.phtml" type="core/template">
</block>
</reference>

Maximum execution time of 30 seconds exceeded

To fix it, open your php.ini and replace the value for 'max_execution_time' and 'max_input_time' as per below.


max_execution_time = 3600
max_input_time = 3600

How to show only first name in magento welcome message?

Comment the welcome message code in "template/page/html/header.phtml" and Use the below code to show first name only.



$customer = Mage::getSingleton('customer/session')->getCustomer()->getData();
if(Mage::getSingleton('customer/session')->isLoggedIn()){
   echo $this->__('Welcome, %s!', $customer['firstname']);
}else{
   echo $this->__('Welcome Guest');
}

How do I change SHOP BY text in left sidebar Magento?

Are you trying to replace the "SHOP BY" text? And failed to replace the text? Don't worry, that is not actually a text. That is Image.

Solution 1: You will need to replace the image under

"skin/frontend/default/default/images/bkg_block-layered-title.gif";


Solution 2: Locate a file

"app/design/frontend/default/YOURTHEME/template/catalog/layer/view.phtml" Change the class name "block-title" to something else.

Wednesday 10 February 2016

How to remove my account,my wishlist in magento account link on home page?

To remove My Account link :

Open the file /app/design/frontend/package/theme/layout/customer.xml and comment these lines
 
<!--<action method="addLink" translate="label title" module="customer">
<label>My Account</label>
<url helper="customer/getAccountUrl"/>
<title>My Account</title><prepare/><urlParams/>
<position>10</position>
</action>-->

To Remove Wishlist link :

Open the file /app/design/frontend/package/theme/layout/wishlist.xml and comment these lines.
<!--<reference name="top.links">
    <block type="wishlist/links" name="wishlist_link"/>
    <action method="addLinkBlock">
<blockName>wishlist_link</blockName>
</action>
</reference>--> 

To Remove My Cart link :

Open the file /app/design/frontend/package/theme/layout/checkout.xml and comment these lines
<!-- <action method="addCartLink"></action> -->

To Remove Checkout link :

Open same file, /app/design/frontend/package/theme/layout/checkout.xml and comment the lines
<!-- <action method="addCheckoutLink"></action>-->

Thursday 4 February 2016

How to remove the index.php in magento?

To remove index.php from URLs follow the below steps :
  1. Log-in Magento Admin.
  2. Go to System -> Configuration -> Web.
  3. From Search Engine Optimisation tab Use Web Server Rewrites select YES.
  4. Make sure your Secure and Unsecure base urls should end with “/”.
  5. And in System -> Configuration -> Web -> Secure -> Use secure URLs in the frontend, select YES.  
  6. now edit your .htaccess ( will be in magento root folder ) and pate the below code and save:   

1<IfModule mod_rewrite.c>
2RewriteEngine On
3RewriteBase /
4RewriteRule ^index\.php$ - [L]
5RewriteCond %{REQUEST_FILENAME} !-f
6RewriteCond %{REQUEST_FILENAME} !-d
7RewriteRule . /index.php [L]
8</IfModule>


now your index.php issue will be solved.
** if that still does not work, then make sure you have mod_rewrite enabled / installed on your server.

Monday 1 February 2016

New order email confirmation not being sent

Avoid cron:

 Transactional emails will be sent instantly.


goto following path: 

//app/code/core/Mage/Sales/Model/Order.php Line#1356,1450 
  //$mailer->setQueue($emailQueue)->send(); Change To 

          $mailer->send();

app/design/frontend/base/default/template/checkout/success.phtml
 //add following line Top success page for sending mail direct
 // Start Send Email Here......
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
$order->loadByIncrementId($incrementId);

    try{ $order->sendNewOrderEmail();} 
    catch (Exception $ex) { echo "Email Not Sent..."; }
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $email = $customer->getEmail();//End Email Sending



Thursday 28 January 2016

How can we find Magento version through code?

We may find the Magento website which version is using is now easy to find out.

Just open the path from your root folder /app/Mage.php

Near 168 line, you can find the following code :

   public static function getVersionInfo()
    {
        return array(
            'major'     => '1',
            'minor'     => '8',
            'revision'  => '1',
            'patch'     => '2',
            'stability' => '',
            'number'    => '',
        );
    }

It means we are using the 1.8.1.2 version.

How to find the difference between Mage::getModel() and Mage::getSingletone() in Magento

To know about Mage::getSingletone():

It is used for Always finds for an existing object if not then create that a new object.


To know about Mage::getModel():

It is used for Always creates a new object.


Wednesday 27 January 2016

Magento Static Blocks – The Definitive Guide


Magento Static Block:

There is more than one way to skin a hippo and adding CMS static blocks in Magento is no exception.
In case you are unfamiliar with CMS static blocks, they are powerful little buggers in Magento’s admin that allows the site is the administrator to add and control chunks of HTML that can be displayed throughout the site. They are perfect for seasonal banners, sale blocks, return policies, size charts, and anything that would make sense to modularize to make maintaining your site easier.
But wait, aren’t there already ‘callouts’ in Magento? Well, if you’re talking about those annoying graphics of the dog and chalkboard that take editing multiple files to update then yes. Magento’s built-in callouts are a terrible way of handling regularly updated content.
Your Magento website should be as updatable as possible to keep you from getting phone calls every time a client wants to advertise a new sale. Which is exactly why we want to control these blocks from the admin. Keep in mind Magento’s upcoming release of 1.4 will be implementing a WYSIWIG editor so clients can handle their own changes instead of pestering you.

Creating a Static Block

  1. Log into your Magento store’s admin
  2. Navigate to CMS>Static Blocks
  3. Click Add New Block in the top right corner
  4. Give your block a recognizable Block Title such as Social Media Links or “Fall Sale Banner”
  5. Give your block an Identifier which will be used to call the block. Make sure the Identifier is all lowercase and separated by underscores to follow Magento’s nomenclature i.e. your_block_id
  6. Choose what store view the block belongs to. Just leave as All Store Views unless you have a good reason not to
  7. Set Status to Enabled
  8. Enter your HTML in the Content field. The editor is currently a raw HTML editor, but 1.4 will support a WYSIWIG editor. Alternately, there is a Magento WYSIWIG extension to help out.
  9. Click Save Block or Save and Continue Edit to save your settings.
You’ve set up your block, so how do you plug it into your site? Well it depends on how you need it to function, but you have several options at your disposal:


1. XML 

Adding a static block to a page template is a great way to control global elements of your site, such as footer links, custom callouts in the sidebar (ultimately replacing that damn dog) and more. You can embed this code in app > design > frontend > default > your_theme > layout. Open the appropriate the file, lets say catalog.xml and plunk the following code in the block for our category view:
<block type="cms/block" name="your_block_id" before="-">
      <action method="setBlockId"><block_id>your_block_id</block_id>
      </action>
</block>

This code will place the block “your_block_id” that you have created in the admin above the content on the category pages (notice the before=”-“ attribute, which makes sure your block gets displayed before the rest of the content). This is perfect for a seasonal banner that could advertise a current sale on all product listings.
Controlling static blocks with XML is geared for content that will remain in a consistent position in your theme.
Sometimes however you gotta get down and dirty and place your CMS static block inline in your template. That’s where the next method comes in.

2. PHP 

Adding your static block inline with PHP is the quickest way to get your block in your template. Let’s say you want to add a quick blurb about your return policy right after the “Add to Cart” button. The client needs to be able to occassionaly update this blurb from time to keep it current. So you open your template file that contains the “Add to Cart” button app > design > frontend > default > your_theme > template > catalog > product > view > addtocart.phtml. Find the <button> tag and right afterwards add the following code:
[cc lang="php" tab_size="2" lines="40"]
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your_block_id')->toHtml(); ?>
[/cc]

This code will add the block “your_block_id” right after the button. Jobs done. This method is perfect for getting into those nooks and crannies in Magento’s vast and awkward file structure.

3. Shortcode 

This method is used when you need to pull in a static block while in Magento’s admin creating CMS pages or other static blocks. A possible example would be injecting contact information into multiple CMS pages. So you create a contact static block, and then can insert the contact info on the contact us page, your privacy policy page, customer service page, etc. If the contact info changes, you simply update the static block and the changes will be reflected across all your CMS pages.
{{block type="cms/block" block_id="your_block_id"}}
This code will place the block “your_block_id” inline in your CMS page.

Conclusion 

The whole idea of creating these static blocks is to streamline the amount of time it takes to update your site. Clients won’t have to bother you to change their 800 number. Your design team or site administer can simply FTP a new image and update the image path. Or if you own the site, you don’t have to go dumpster diving through your template files to find where you put that couple paragraphs of content.

Magento : 404 error is showing admin page

Hello, Sometimes we may get the error on admin page once done with the Magento installation. In that scenario, we have to do the following: ...