Pages

Thursday, July 4, 2013

Script for to remove the cache - Magento

Here i paste code to remove the cache from the magento.. magento can provide a options to us to remove cache form the admin configuration, but sometimes it not more helpful to us... so expert suggest to remove cache folder..

make one cache-clear.php file into your root folder and paste following code:

 <?php 
 require_once ("app/Mage.php"); 
 umask(0); 
 Mage::run(); 
 Mage::app()->getCache()->clean(); 
 exit("done"); 
 ?> 

can call that file with :http://yourdomainname/cache-clear.php

hope this helps :)

Cheers,

How to create Multiple Websites in Magento

I was getting crazy trying to solve this. Finally I found the solution.

After create the X Websites you need from your Admin section we hace to edit a piece of code.

Note: each Website has one unique Store and one unique Store View.
Note2: use short and easy Websites codes, we will need them now.



Sub Domain Method

In your Index.php file (in the root directory of the Magento installation) you have to look for:
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

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

Then replace the found code for this new one:
// this first line detects the domain / sub domain
switch($_SERVER['HTTP_HOST']) {

case 'store1.domain.com':

/* store1 is the code you wrote in the admin
when created the website */
Mage::run('store1', 'website');

break;

// domain.com (default store)

default:
Mage::run();

break;

}
Sub Directory Method

Using a Sub Directory means more job.

First of all you need to create as much as directories you wanna have.

Example:

    http://mydomain.com/store1
    http://mydomain.com/store2

So following the example you will create 2 directories in the root of your magento installation.

Now you have to copy & paste the index.php and the .htaccess to those folders.

Once that we need to edit the index.php.

Look for:
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

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

And replace it for:
// this will force to load the Website with the code store1
Mage::run('store1', 'website');

You need to repeat this step to every folder, to every index.php you created before.

Now check out this screenshot to see how to configure the Website:

Done!

Now you know how to create multiples Websites in one Magento Installation.
 

How to remove .html from Magento

There is an easy way to improve the SEO of your Magento store by removing the .html extension from the url
Example:
We have a category called Shoes
  • http://mydomain.com/default/shoes.html
And we want to have an URL like this:
  • http://mydomain.com/default/shoes
Now go to your Admin Panel. System -> Configuration. Then go to Catalog and expand the Search Engine Optimization tab.
Remove the “.html” text from both the input fields. Product URL Suffix and Category URL Suffix.
Finally the page will look like this screenshot:

How to change currency position in Magento

I mean it doesn’t crash or something it’s just it doesn’t change the currency position.
Example:
For US Dollars have to be $10,00
But for Euro in Spain we use 10,00€
There is an easy way to change the currency position in the Locale (lenguage) you want.
In my case I wanted to change the € simbol for the Spanish locale on my Magento installation.

1. Go from your root folder to /lib/Zend/Locale/Data

2. Find the lenguage file. In my case es.xml

3. Look for <currencyFormat>
A line just below you will find the <pattern>
Change the side of the weird simbol and leave it like this:

Before
<currencyformatlength>
   <currencyformat>
    <pattern>¤ #,##0.00</pattern>
  </currencyformat>
</currencyformatlength>
After
<currencyformatlength>
   <currencyformat>
    <pattern>#,##0.00 ¤</pattern>
  </currencyformat>
</currencyformatlength>
Now this becomes interesting. Try to refresh the Magento Cache and the browser cache. In my case nothing happened. The change made effect itself an hour after this.
I’m not sure but I think its something about caching those XML files.
Anyway, just be patient until the change comes by itself.

Extra Fee Shopping Cart Price Rules Magento

Under the Promotions tab in your admin panel:
It’s cool but it’s not cool enough. What I wanted to do is to set a surcharge for one payment method. I needed to add a charge in PayaPal method.
So I found the way you can set negative discounts (what means a surcharge) in the cart total price.

Note: we are going to change Magento Core files. Please make a backup of your files before continuing.

1. Go to app/code/core/Mage/Rule/Model/Rule.php

Find the line:

//check if discount amount > 0
if ((int)$this->getDiscountAmount() < 0) {
Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.));
}

Just add some bars // to comment the code:

//check if discount amount > 0
//if ((int)$this->getDiscountAmount() < 0) {
//Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
//}

2. Now go to: app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php

Look for:

$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
class=> ‘validate-not-negative-number’,
‘label’ => Mage::helper(’salesrule’)->__(‘Discount amount’),
And again comment like this:
$fieldset->addField(‘discount_amount’, ‘text’, array(
‘name’ => ‘discount_amount’,
‘required’ => true,
// ‘class’ => ‘validate-not-negative-number’,
‘label’ => Mage::helper(’salesrule’)->__(‘Discount amount’),

3. Translate the discount word.

Go to app/locale/es_ES (I’m using the Spainish translation so maybe yours would be en_US)
Find a file called Mage_Sales.csv. Inside look for the word discount you will find something like:
"Discount (%s)","Discount (%s)"
You can change the value in order to show your own text. For example:
"Discount (%s)","Extra Fee (%s)"

Now you’re free to set negative values in the input field:



Fixed amount discount for whole cart

If you select this option the code above will not work entirely.

Add links Magento

Today we’re going to see how to add them to a Static Block or a Page (under your CMS panel).

Example:

If you want to add a link to the page About Us in your footer. How you do that?

If you try this code it will only work for the default lenguage. We need Magento to build a link with our lenguage tag.
<a href="/about-us">About us</a>

What we need is something like http://my_site.com/en/about-us

So we will use Magento shortcodes. You will need to write the page identifier after the direct_url:


<a href="{{store direct_url='about-us'}}">About us</a>

Using the structure above it will build links dinamically with everything it needs in the url.

Can’t Log In Magento Admin

Look for the file:

/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

Arroud the line 100:
call_user_func_array('session_set_cookie_params', $cookieParams);

Add bars to comment the line:
//call_user_func_array('session_set_cookie_params', $cookieParams);
Done!

Now you will be able to login.

Install Magento Locally with MAMP PRO

1. Set up a new enviroment in MAMP PRO
2. Use the web browser to access to it. Verify it’s working.
3. Access to your PhpMyAdmin
4. Create a database and optionally import Sample Data.
Download all files you need from: http://www.magentocommerce.com/download/noregister
5. Browse again your site and the Install Wizard will show. Follow my screenshot:
Done!
Important
Maybe you will be not able to log in in your backend (admin). It happened to me.

How to create Downloadable Products Magento

1. Go to Catalog -> Manage Products -> Add product.
Select the Downloadable Product type:
2. Basic set up. Name, price, stock, website, category…
3. Downloadable set up.
Here you can create optionally Samples and at least one Link.
You can upload files or put an URL.
Now we can see the product in our frontend store.
Once you buy the item it will show up in your customer account (My Account). After validate the order it will allow you to download the file.

SEO URL Magento

When you installMagento probably your URLs would be like:
  • http://www.domain.com/index.php/about-us
There is an option to remove that index.php from the URL.
Go to your admin panel -> System -> General -> Web -> Search Engines Optimization.
Change Use Web Server Rewrites to Yes.
Now your URL will be cool enough