[Magento] How to place a product on sale or special in Magento?

When you go around some online shop, sometime you’ll see products with ribbon ‘Sales‘ or will see two price (1 for original price, 1 for new price) and something like that….

So how to do it in magento?

It’s very esay. I’ll explain step by step in this below:

1. Login to the Magento admin.
2. On the top menu go to ‘Catalog > Manage Products.
3. Click the product on the grid to edit.
4. On the left menu, click ‘Prices‘.
5. (If you only have one store skip this step) On the top left, select the appropriate Store from the drop down.
6. Enter the desired Sale price on the field ‘Special Price‘.
7. If applicable, assign a date range using the fields ‘Special Price From Date’ and ‘Special Price To Date‘.
8. Click Save.
9. On the top menu go to ‘System > Index Management‘.
10. Find “Product Prices” from the grid and hit ‘Reindex Data‘.
11. On the top menu go to ‘System > Cache Management‘.
12. Check the ‘Page Cache’ item, make sure the ‘Actions’ dropdown has a value of ‘Refresh‘, and click Submit.

That’s all.

[Magento] How to remove index.php from URLs?

Working with magento, sometime, you can see index.php appear in URLs of your website url. The index.php appears in your URLs because it is the file responsible for processing all requests to the system. In a URL such as http://example.com/index.php/template_group/template, the template_group/template segments are simply information passed to index.php and do not refer to actual files or folders in the server’s filesystem.

Actually, they are not good for SEO, bad for site structure and consistency, and then they’re even worse for a clean URL freak like me.

Let’s clean it…

1. Log-in to your Mangento administration area the go to ‘System -> Configuration -> Web‘.

2. Navigate to Unsecure’ and Secure’ tabs. Make sure the ‘Unsecure‘ and ‘Secure‘-‘Base Url‘ options have your domain name within it, and do not leave the forward slash off the end of the URL. Example: http://tofuandtomato.com/

3. While still on the ‘Web’ page, navigate to the ‘Search Engine Optimisation‘ tab and select ‘Yes‘ underneath the ‘Use Web Server Rewrites‘ option.

4. Navigate to ‘Secure‘ tab again (if not already on it) and select ‘Yes‘ on the ‘Use Secure URLs FrontEnd‘ option.

5. Now go to the root of Magento website folder and use this code for your .htaccess:

* If your Magento store is installed in root(public_html) , use this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

** If your Magento store is installed in a subfolder (public_html/shop), use this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>

Save the .htaccess and replace the original file (You need backup your original file before replacing).

6. Now go to ‘Cache Management‘ in Administration area to clear Cache.

You are done!

Let’s me know in the comments below if you use this or run into any issues.

[Tofu And Tomato] Magento 1.7 “Database server does not support InnoDB storage engine message”

I’m trying to re-install a cloned Magento 1.7 website on a local server using AMPPS. InnoDB is set as the default engine but it still shows me the message: Database server does not support InnoDB storage engine.

To sort out this issue:

Go To Line 59 of the file app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php

Replace:

public function supportEngine()
{
    $variables  = $this->_getConnection()
        ->fetchPairs('SHOW VARIABLES');
    return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true;
}

With:

public function supportEngine()
{
    $variables  = $this->_getConnection()
        ->fetchPairs('SHOW ENGINES');
    return (isset($variables['InnoDB']) && $variables['InnoDB'] != 'NO');
}

Also see my screenshot:

magento1.7.inodb

[Tofu And Tomato] [Magento Solutions] Fix email not sent

Today, my client at http://www.dubuy.it/ told me that, he had an weird problem with email settings in Magento, he had never receive any sale / order emails after submitting one-page-checkout form.

If the order displays the email as sent and you or your clients are not receiving the email, then the problem is most likely the email settings you have for Magento or the local email server that Magento is using.

I also checked the settings:

  • Admin -> Configuration > Advanced -> System > SMTP Settings and see that you do not have emails disabled.
  • Admin -> Configuration > General > Store Email Addresses and check if you have the email addresses in there correctly. Sometimes email servers would refuse to send email if the senders email is not a proper email address.

However, the settings are correct but emails still were not sent. After digging into the code, I found the issue:

Just been looking into this myself. I’ve followed the code and functions back to this function “public function sendNewOrderEmail()” in:

app/code/core/Mage/Sales/Model/Order.php

starting at line 1270 is the following code:

$emailSentAttributeValue = $this->load($this->getId())->getData('email_sent');
    $this->setEmailSent((bool)$emailSentAttributeValue);
    if ($this->getEmailSent()) {
        return $this;
    }

This is checking the sales_flat_order db table to see if the email has already been sent to the customer and if so just to return, but this does not send the email and should throw an error. So I would say it is a bug somewhere. To fix it so you can resend order/invoice emails etc..

Copy

app/code/core/Mage/Sales/Model/Order.php

to

app/code/local/Mage/Sales/Model/Order.php

and comment out line 1273

if ($this->getEmailSent()) {
            //return $this;
        }

Works like a charm for me. But literally only this second tested it.

magento-fix-email-not-send

[Tofu And Tomato] How to add CSS classes to Magento top links.

Ever wonder or ever hit your head on the wall what bloody template file controls the site link, footer link in Magento and how to add a class to it? That’s right, it’s thepage/template/links.phtml.

The template file generates ‘first’ and ‘last’ class in li tag, but sometimes we need more styling in each individual link list and we want to add a class either in li or anchor tag without hacking the core file or extend a class in Magento core, how do we do that?

The answer is in the xml file

magento-top-links

LET’S HAVE A LOOK AT MY CODE:Screen Shot 2014-10-18 at 11.38.48 AM

[Tofu And Tomato] Magento – How to add another language to your store

I currently have two sites under development that are going to take advantage of multiple languages.

One will have a second store view in French and another will have a second store view in Spanish.

The fist step is to change the default store view name to English. Login into admin and go to the System>Manage Stores section.
Click on Store View Name for your default store. Change the store name to English. Then save.

Next step is to create the second store view, which will be Spanish.
Click on Create Store View button at top.
Enter your information for the Spanish store per image below:

new-spanish-store

Click on Save Store View and you should have a new Spanish store view.
On the front end, you will now see that there is a store switcher in the header area.

switcher

Now, we have two stores, one english and one spanish.
But as you can see, it’s not all working as it should.
If you go to the home page in the Spanish Store, we will get a 404.
You can fix that by assigning the home page to All Store Views, per below.

home

You will also need to go to Catalog>Manage Products and select all your products, then update attributes.
Then go to websites section, per below, and add product to website.

update-products

You should now see all your products showing in categories, regardless of what store view you are in.
We will cover products later.

If you take a quick look at your Spanish view store, you will notice that it’s not really in Spanish, it’s still in English.
That’s because you haven’t given Magento any translations for your Spanish store. That’s next.

Go to Magento’s Translations Page.
Search for your language pack then click on it to go to the pack’s download page.
You are now ready to download the Spanish pack, see below.

translations

Save the es_MX folder to your desktop, and upload to your server in the app>locale folder.See below.

locale

Now that you have installed the Spanish language page, it’s time to tell Magento about it.
Go to System> Config> General tab, then click on Locale Options tab.
In top left, select Current Configuration Scope, and select Spanish. See below.

config Now that Magento knows about our Spanish language pack, it should be serving translated files in the front end.
Let’s see…

translated

Finally, we will talk about product translations.
If you want to have Spanish in a product, for example, you will need to go to Catalog>Manage Products.
Select your product, then select Spanish store view in top left.
Add your Spanish translations to short description, for example, by unchecking ‘Use Default Value’ and then pasting in your Spanish translation. See below.

short-desc

Here is result of that translation on front end…

short-desc-tl

I know that’s alot of steps, but it’s really amazing what we have just done.

We now have a multi-language store, serving different visitors, in their own tongue.

$this What is it?

When we work at front-end in magento (in templates), we often see $this or $this-> … If you don’t know that,  will you ask a question for it, sometimes? I think this answer is YES

This is problem which baffles beginner Magento developers. Here’s to hoping I can provide a half-decent explanation as to what it is, and where it comes from. The most important point you should take away from this is: all Magento templates have a corresponding block instance. The $this exposed to us is the block instance, as if we were inside a method of the object (See Mage_Core_Block_Template::fetchView).

Blocks in Magento are PHP class that are designed as a place to put all of your business logic, instead of your templates. Blocks are normally reusable class. A great example of the reusability of certain class is the Mage_Core_Block_Template and Mage_Page_Block_Html_Pager class. The core/template block is the foundation of the template system, allowing us the ability to load .phtml files from our themes. The page/html_pager block provide generic methods for paginating collection, such as isLastPage().

If you are ever in any doubt as to which block type the template is using, just call echo get_class($this). Remember, it’s an object.This gives you a great place to start when hunting down methods available to the template.

Understanding Magento Observers

Magento has a pretty well implemented Event/Observer system, but before we dive into the specifics, let’s make sure that we have a clear understanding of the design patterns that are in play in the Magento application.

Specifically, lets’ talk about the concept of the event system, how it works and what it is. Though we’ve covered certain design patterns in other articles on Tuts+, we haven’t done so within the context of Magento.

To that end, let’s take a look at the pattern in order to gain a clear understanding of how it is, how it works, and how it’s beneficial.

Over the years a wide array of design patterns have been dveloped. But what is a design pattern exactly?

To quote Wikpedia:

“In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.”

If we reduce that a little we’re left with: a design pattern is a reusable solution to a common problem. That is as perfect a description.

The design pattern is a template that can be used to create a solution that will fit problems of the same nature. The pattern itself is not the actual solution, it defines the way the solution can be implemented as a guideline.

Your actual solution, even if adhering to the defined pattern can be different from mine as long as they both follow the guidelines set out by the design pattern.

Now that we know what a design pattern really is, lets take a look at the Observer Pattern.

First implemented in the MVC architecture, the Observer Pattern has turned out to be a very valuable addition to the architecture. In part because of this an enormous amount of libraries have implemented the pattern over time and if you’ve been programming for a while it’s not unlikely you’ve already used it.

Enough history now though, let’s take a look at how it works.

To observe something is to look at it, or, to observe its state. In a technical context, this is no different. Observers by definition are watching something and in our case, events. The idea here is that if an event gets dispatched, the observers that are observing this event get executed.

Generally, the subject that is being observed will be passed along by reference in order for the observer to be able to update or check it for changes.

Check out this example put together from the Magento code:

01
02
03
04
05
06
07
08
09
10
11
class Mage_Catalog_Model_Product
    extends Mage_Catalog_Model_Abstract
{
    public function validate()
    {
        Mage::dispatchEvent('catalog_product_validate_before', array('product' => $this));
        $this->_getResource()->validate($this);
        Mage::dispatchEvent('catalog_product_validate_after', array('product' => $this));
        return $this;
    }
}

Alright, so this is the validate method as its available in your run of the mill Magento installation. For clarity I replaced two variables with their actual values. You can see two events are dispatched here. catalog_product_validate_before andcatalog_product_validate_after, each of these gives the product object along with the dispatch so that the observer might do something with it.

01
02
03
04
05
06
07
08
09
10
11
12
13
class Enterprise_AdminGws_Model_Models
    extends Enterprise_AdminGws_Model_Observer_Abstract
{
    public function catalogProductValidateAfter(Varien_Event_Observer $observer)
    {
        if ($this->_role->getIsAll()) {
            return;
        }
        $product = $observer->getEvent()->getProduct();
        $this->_forceAssignToWebsite($product->getWebsiteIds());
    }
}

And here’s an observer class and its method. This class and method are hooked into the system using Magento’s configuration system. The event itself is handed to the observer class and the product is reachable from the event.

I’ll cover the actual creating and hooking of observers as well as reaching the subjects with more detail in the next post.

One of the primary arguments to use the Observer Pattern, or its close relatives like the Pub/Sub Pattern is the modularity it provides.

Because anything can hook into an event that is being dispatched, you never have a strong reference to it. This is exceptionally useful in a setting where you’re always working with modules that may or may not provide services to a specific element that may or may not be available.

To use Magento again, I can build a module that will observe product changes as well as a module I built that fires off its own custom events. Now, in a regular system this module would be dependent on the earlier module, but using a Pub/Sub or the Observer Pattern I can make that dependency optional and only apply whatever it is my current module to it when it’s available.

After this quick refresher on what exactly design patterns are as well as the more in depth look at the Observer Pattern, in the next post I’ll explain how it’s used in Magento, how you can start using it in your own modules and provide them in your own modules as well to hook into from different ones, or for others to hook into.

4 Benefits of Using Ecommerce Responsive Website Deisgn For Your Business

“Having an eCommerce responsive website for your online business is completely best to increase your sales and profit. By adopting a responsive web design, businesses can get lots of benefits, so checkout this blog and know what type of benefits you can get.”

In this highly competitive world, it becomes quite difficult for all the businesses run a successful online business by which they can boost sales of their business and earn maximum profit. However, it is not possible for businesses to increase their sales and profit without using responsive web design service.

If you have decided to make your eCommerce business more popular, it is best for you to adopt a responsive web design so that one can access your website from any device. By making your eCommerce website responsive, you can allow your customers and website visitors to access your website from any device or computer like desktop, tablet, laptop, smart-phone or any other device.

In this blog, I have listed the major benefits of responsive web design, so go through it and make yourself to ready to make your site responsive:

Improve User Experience –

Today, more than 90% of people have smart-phones and they prefer to access online websites from their device, so it is important for online businesses to have a Magento responsive design that helps their business to enhance user experience. By adopting responsive website, users can give a well-formatted website to access, and the website automatically adjusts as per their device’s screen and orientation.

tumblr_inline_n8e54uX55t1stddiv

Boost Conversion Rate of The Site –

One of the major benefits that businesses can get by opting for responsive web design is it helps them to boost conversion rate of their website. As per the report, approximately 54% of respondents are satisfied with their mobile experience and prefer to come again to purchase from the retailers mobile channel. Moreover, it is well-known for using standardized style sheets for lots of devices and develops a reliable look to provide a positive impact on the conversion rates.

Increase Brand Awareness –

Some years ago, having a simple website was good enough for visitors to access it from their computer, but now-a-days, most of the people prefer to access online websites from their tablets and smart-phones, so it is essential to have contemporary websites that adjust their resolutions in different screen sizes.

Responsive website design helps you to increase your brand awareness and get lots of attention from visitors and customers. You can give your customers a pleasant experience and stat ahead of your expectations by designing an attractive responsive site.

Improve SEO of Your Site –

Apart from above mentioned benefits, the other benefit that businesses can get is that they only need to optimize the content for one link. Because the URL structure of the website remains as it is for other devices as well.

Online businesses can make their website responsive and have only one URL that is easy to update and optimize their content. It does not matter whether it is iPad, desktop or any Smartphone, responsive design lets Google crawlers to index your website pages easily.

So, these are the major benefits of responsive website design that all the eCommerce businesses can adopt to make their business popular worldwide. However, if you have decided to make your eCommerce site responsive, it is important to hire a professional eCommerce developer from any trusted company.