By Vasi Chindris 19th December 2012 Drupal

The Drupal Commerce module is a great solution for anyone who wants to have a shop implemented with Drupal. It doesn't matter if you configure the shop from scratch or if you use an installation profile, you can have a shop in a very short time. Most of the time is just configuration, almost no coding required.

By default, you can create your products, set the prices for them, categorize them, create rules for tax handling, use different payment gateways (also with the help of some contributed modules) and many many other things. Unfortunately there is one thing you cannot do just with configuration: a donation system. The main problem in the donation system is that the amount of each donation can be different. If your donation system has only fixed amounts, then there is no problem, all you have to do is to create one product for each donation amount. But when the amount is variable, then implementing this using only configuration may not be so trivial (if not possible at all).

I will explain next how we deal with this case, when we have to build such platforms.

The concept

If we go a bit deeper and check how the Drupal commerce system is built and how the price of the order is calculated, we can see that each line item from the order has a unit price field, that usually is populated with the price of the product to which it is associated. So the user clicks on the button to add the product to the cart, and this triggers the creation of a line item in the order that will have the unit price of that product. But in our case, the price of the product is variable, because it is about a custom amount that the user wants to donate, so we cannot really use that price to populate the line item. We will have to handle this by ourselves, to implement some logic that will populate the unit price of the line item with the amount of the donation. The solution involves site configuration, as well as some coding.

The main idea is to have a new field on the line items (a price field) that will be populated with the value the user wants to donate, and then using a rule that will be triggered on the event “Calculating the sell price of a product” to put the value from our custom field into the price field of the line item. The reason why we do not just put the value directly in the line item price field, when we create the line item, is that the price of the line item can actually be updated later. For example commerce_cart_order_refresh() would update the price of the line items. In this case, our code that populates the unit price will not be executed, and we will not be able to maintain the correct price of the line item. That's why we use that rule that fires on the “Calculating the sell price of a product” and we store the amount that is being donated in a separate field that will not be altered by any other code.

The setup

And this is how it works:

add a price field on the line item type (admin/commerce/config/line-items/product/fields), with the name: field_variable_price

create a product with the SKU “donation” that has the price set to 0

add a rule that updates the price of the line item


 

For the coding part, an example can be found in a sandbox project. An important remark for the coding part is that we actually have to create the order and add the donation product to the order by ourselves, because we have to populate the field_variable_price with the amount that the user want to donate.

The code also has a page: /donate and a configuration form /admin/commerce/config/donation_amounts where some predefined amounts can be configured. For more details about the coding part, you can just check out the sandbox project.

While finalizing this blog post I discovered that, since starting to implement this feature on a recent project, a new module called Commerce Donate surfaced on Drupal.org which might be interesting for you too.

By Oriana Pivetta 10th December 2012 Business, Drupal

Hooray, we are happy to announce the launch of our latest project. Get Active is a fundraising project of the Biovision Foundation, a charitable organization which aims to improve the life for people in Africa while conserving the environment as the basis for all life.

Getactive.ch is a fundraising platform with the objective to raise money through a series of activities suggested by the community. The goal of the first campaign is to reach CHF 10,000 by April 2013 in order to help and support farmers triple their harvest using the push-pull method. But how can YOU get active and why?

There are three options to get started:

  • Donating
  • Finding an activity to support
  • Starting your own

Developing this platform, we could draw from our expertise in community and fundraising solutions. Implementation was done using Drupal 7, including organic groups, commerce and i18n.

So, have you found your activity yet? The platform is waiting!

By George Papadongonas 29th November 2012 Drupal

The SEO environment has changed significantly during the last 18 months, especially after the Panda and Penguin updates. What worked a couple of years ago, is just not relevant anymore. Before those updates, it was much easier to achieve high rankings in search engines just by building or buying links from low quality sites. Post-penguin SEO requires a more holistic approach, with focus on quality content but also requires a technical perfection.

But, Drupal is already SEO friendly; you are going to answer. Of course it is, but that does not mean that it is perfect right out of the box, but that it has the flexibility to become a SEO-perfect platform. A plain Drupal installation does not provide everything that is required so, here are the basic steps to optimize it to the last detail.

Planning

  1. Begin with the Search Optimization planning, before beginning to build the site. The development of the website is the not the final destination after all, it’s just the medium for the creation and promotion of site’s content. 
  2. Do your keyword research to understand what people are looking for and how you can help them to find it. Plan your site architecture, hierarchy and layout based on your findings. Use the Keyword Tools from Google or Bing. For a more advanced tool, use KeywordSpy (paid, with a free trial).

Setting up Drupal

  1. Create a redirect between the www and the non-www version of your site. If you don’t, search engines will index both versions and you will have a duplicate content issue. It really does not matter which version you’re using, but stick to one. To enable it, open the .htaccess file and uncomment the related lines (lines 81-82 with the www version, lines 87-88 without the non-www version).
  2. Install the SEO Checklist module. This module does not provide any functionality by itself, but it gives you a 58-points checklist for the most important actions related to the On-Site SEO. It helps to keep things organized and it also provides some automated tests for installed modules etc.
  3. Enable Clean URLs. This one is more than obvious, must check it just in case.
  4. Install and configure Pathauto module. The default URL for a Drupal node page is node/nid. Use this module to define URL patterns for every content type, taxonomy and user pages. Now, every time you create something new, a URL alias will be created automatically, which will be search engine friendly. For better results, try to limit the URL length to 115 characters.
  5. Install and configure Global Redirect module. In the previous step, we actually created a duplicate URL for every piece of content. When search engine’s spiders visit the site, they will actually track two different pages and it’s very possible to have a duplicate content penalty. This module solves this problem by creating 301 redirects from the original to the alias URL.
  6. Install and configure Redirect module. If you change the URL in a page which is already indexed in a search engine, when a user clicks on this specific result will land on a 404 error page on your site. You’ll also lose the benefit that you had from existing incoming links to this page. This module creates redirects from the old to the new alias and improves the search experience of the users.
  7. Install and configure Pathologic module. It fixes images paths and URLs inside your content, so that you can move them in different domains, subdomains or folders without creating broken links.
  8. Install and customize Transliteration module if you are creating a web site in a language different than English and you want to use only US-ASCII characters in your URLs.
  9. Create an account in Google Analytics and install and configure Google Analytics module. Google Analytics does not only have information about traffic, but it can also provide useful insights about the performance of the site’s landing pages for different keywords.
  10. Install XML sitemap module. Do not forget to configure the module and declare the content types and taxonomy terms that you want to be included in it the XML sitemap. 
  11. Create an account in Google Webmasters Tools and submit the XML sitemap. This is a step, which is often overlooked. After the creation of the XML sitemap do not forget to submit it in GWT. Make a check a after a while that it was submitted successfully and there were no errors.
  12. Create an account in Bing Webmasters Tools and submit the XML sitemap. We all tend to focus on Google, but as Bing has now a market share of 16%, it is an important player that you cannot ignore.
  13. The default robots.txt of Drupal works fine in most cases, but some minor changes are usually required. In many cases you want to hide specific pages or folders of the site for search engines, by adding a new line with the “Disallow” command and the name of file or folder. 
    Also, add the URL of the XML sitemap inside the robots.txt file.
    If you’re running a multi-site Drupal installation, use RobotsTxt to generate different files for every one of them.

Optimizing Pages

  1. Install Meta tags module. It allows the creation of patterns for automated generation of meta tags in the <head> section of the page. You can define global settings, but also different settings for every content type, taxonomy, file type or users.
  2. Configure page titles from meta tags settings.  Every URL should have a page title; it is the main definition for search engines and their users, about the page’s content.  To be compatible with the main search engines, try to limit the title’s length to 65 characters. Also, avoid duplicate page titles.
  3. Configure meta descriptions from meta tags settings. Meta description is not a ranking factor, but is the text that users read in the search engine results pages.  The automated generation method uses the first paragraph from your text, so it’s not always ideal. It’s better to take a quick look before posting a node and adjust accordingly.  Avoid duplicate meta descriptions and try to limit their length to 156 characters.
  4. Do not bother to use the keyword tag. Search engines stopped using it several years ago, so it’s not a ranking factor anymore. Actually, it can only help your competitors, as they can easily understand what keywords you are targeting for.
  5. Use proper heading tags. Drupal usually does it right by default, as node pages ,pages created by the Page Manager or Views, are using <h1> titles. Also, secondary elements like blocks or panes are using <h2> titles. Things to watch: some themes are using <h1> to display the site name, so be sure that you do not have two <h1> tags per page. Also, when you are creating your template overrides, be sure that you are using the appropriate markup for heading tags.
  6. Add the rel=”canonical” link element to declare the preferred version for search engines, among the different URLs that a Drupal page has. It can be performed through the meta tags module settings. 
  7. Use the <alt> attribute for your images. Without it, search engines cannot understand the content of the image. Remember that you can have search engine visibility not only for pages, but for images as well.
    When you’re using an image field, you can enable the alt attribute, through the field settings and then add it for every new image.
  8. Optimize your image file names. Using a descriptive file name helps to achieve better rankings. Also, it is the first piece of text that is displayed in Google Images results, so an appropriate file name will attract more clicks.
  9. In many cases you create nodes in Drupal (like images, or tweets), with the only purpose to be included in other nodes, views or panels. To completely hide those pages from search engines, you can use the Rabbit Hole module, which creates redirects from this nodes to custom paths, so they are not visible or crawlable.
  10. Pay special attention when you are creating multilingual web sites. Translating only the site’s content and header tags is not enough. Every important element like page titles, page descriptions and alt attributes should be translated as well.
  11. Install and customize microdata module. Using microdata to markup you pages according to schema.org specifications, will increase the change for rich snippets to be displayed in search engine results pages and will have as a result increased visibility for your web site and clicks from the search engines. Alternatively, you can use RDFa.
  12. Social signals are becoming an important ranking factor, so it’s good to add social share buttons to your pages. There are many different modules for this task, like Social Share or Share This. Even better use custom code, as described in the Google Analytics social integration guidelines.
  13. You may read that Google+ is a failure or it’s dead. The truth is that even if it’s still a small network, it’s growing fast. In many cases Google+ is an important ranking factor for Google. So, creating a page in Google+ is a beneficial strategy.  Also, use rel=”publisher” to connect your website with your Google+ page. 
  14. Google authorship provides several benefits related to SEO. In many cases, it adds the author’s picture in the search results, thus increasing trustworthiness and click-through rates. Also, it generates a “more from author” button, to check other posts from the same author.  So, first ask your site authors to create personal profiles in Google+ and add the site details in them.  Then, add the rel=”author” attribute, a way to do it in Drupal is described here.
  15. If you’re creating a news website, optimize your site for Google news. Generate a Google news site map by installing the related module Also, consider using the news keyword metatag (yes, it’s a keyword metatag!) to help Google to better understand your content. 
  16. Be careful when you’re using https. Many times both the http and the https versions of your pages will be indexed as separate pages.  Search in Google for “site:yourdomain.com inurl:https”  to locate duplicate content. Use robots.txt to keep search engines from indexing https pages.
    Consider also to switch the whole site to https, as Matt Cutts from Google says in a comment that it’s OK to do it.
  17. Unfortunately, Views or Panels do not have meta tags by default. Install and configure the Meta Tags Quick module, which allows the addition of the main meta tags for any path that is generated by Drupal.
  18. For the pager links of paginated content like Views, use rel=“next” and rel=“prev”. An easy way to do it is described here.
  19. Faceted Search is a great feature and very helpful for site visitors. If it’s not handled right though, it can cause serious problems to the site’s SEO. First of all, the generated URLs are containing a lot of parameters and are not search engine friendly. Faceted API Pretty Paths module solves this problem, as it allows the creation of URLs with an appropriate format. Also, as every filter and every sorting option creates a new URL with an extra parameter, even a small site with a few nodes can generate thousands of different URLs and gave a duplicate content issue. The correct use of canonical tags can eliminate this conflict.

Launching and beyond

  1. Hide or delete your development site. Your client will not like it when it is ranked higher than the production site in search engines. 
  2. On the other hand, if you put a “Disallow: /” in your robots.txt file, remember to remove it, so that search engine’s spiders can crawl your new web site.
  3. Site speed is a factor in search rankings, and it also affects conversion rates.  Read carefully the Drupal caching, speed and performance guide and optimize every aspect to your web site to the maximum.
  4. Use Screaming Frog to quick analyze your site and detect possible issues. Check for client and server errors, broken links, titles, headers, images and be sure that your new site is error-free.
  5. Forget the traditional link-building methods. Create a content creation and promotion plan and acquire links through social media and relationship building. Do not expect to rank well just because you stuffed some nice keywords and you are using Drupal.
  6. Be a part of the Search Engine Optimization Drupal group or chat on irc://irc.freenode.net/drupal-seo

SEO does not end with site launch, but it is a continuous process. Google algorithm changes about 500-600 times a year, so you have to be sure that everything is up-to-date. Make monthly audits in your website, study your analytics, check that all the new content is SEO optimized and make sure that no issues were causes by new functionality or updated modules.

By Daniel Truninger 6th November 2012 Business, Drupal

It is our pleasure to announce the release of FIDES Business Partner

The Zurich-based company is the result of the three-party merger between KMU Businesspartner, agino Management Consulting and FIDES Equity Partners. FIDES Business Partner provides investment advisory services as well as capital and management capacities for SMEs.

Due to our development of KMU Businesspartner's website, one of the merging partners, we were mandated to do the same for the new company's web presence.

The KMU Businesspartner site was frequently used as showcase (e.g. at DrupalCon London) for responsive web design and the Omega theme in the Drupal community. As mentioned in the Hofrat Suess blog post, we already released a first site on the most recent iteration of our favorite theme and decided to use Omega 4 for a second project.
 
 
Beside being fully responsive, like the merging partners' previous site, the new site features some subtle parallax scrolling elements to give the site a smart appearance.
 
By Michael Schmid 4th November 2012 Drupal, Events

Drupal Camps and Cons are just awesome. There are so many things to do: attend sessions, listen to keynotes, meet new people while having fun. 

But there is also another thing happening which is not really seen by most of the attendees: Drupal Core Development.

The core contributors use these opportunities to meet in person and decide about things which are hard to discuss via IRC or the Drupal.org Issue Queues. These meetings not only happen before or after the actual conference, also during the conference. Usually there is a Coder Lounge where people are working on Drupal's Core and drive it forward.

Especially here at BADCamp, it is the last real possibility to define things before the Drupal 8 Feature Freeze. This means everybody gives more than 100% to make the next Drupal version the best it can be.

As an active contributor to the Drupal 8 Multilingual Initiative it is essential to attend these meetings in order to know at first hand what was decided. And of course to get a lot of coding done.

See all pictures from BADCamp 2012 here.

By Daniel Truninger 2nd November 2012 Business, Drupal

Drum roll, please, for the launch of our latest client project: Hofrat Suess! If you are looking for a digital marketing and communication agency in the Greater Area Zurich and have a sweet tooth, you should to add Hofrat Suess to your shortlist. The two, self-proclaimed, Digital Brothers decided to offer their services directly to customers and hence started their own agency in Winterthur.

From a Drupal point of view, we are happy to announce that Hofrat Suess is our first Omega 4 website. Yes, that's Omega 4 as in 7.x-4.0-alpha1! After extensive usage of Omega 3 we felt the time was right to give the future of our favorite Drupal theme a go.
 
So much for our part. Now we wish Clemens M. Schuster and Marc Suess all the best with their venture and their gorgeous responsive website.
 
By Vasi Chindris 24th October 2012 Drupal

If you are a developer it is almost certain that you had to refactor code at some point. Refactoring is no joy, especially if it is not your code and badly written.

In the bigger picture refactoring is ever-present. Just take a look at the Drupal ecosystem. You could refactor content types, display suite fields or views.
 
In this blog post I will give you an insight in how we deal with code refactoring at Amazee Labs.
 

The three code states

I like to think that the code we write can have three states:

  • stable code: code that is subject to almost no changes, and at the same time permits to easily add new functionality.
  • code to be refactored: this is the code that we are working on, or it is marked with @todo and a comment regarding why and what should be refactored.
  • bad code: code that should be refactored, but nobody is aware of it - at least not yet... You will only notice when the client reports a bug or a feature request that cannot be implemented without changes in that portion of code.

Managing @todos

One of the though lessons learned is that when you set a @todo, unless you reserve exclusive time for code refactoring, you will not refactor that code until it is subject of a bug. Since, our first rule regarding code refactoring is actually to try to avoid it, or to make it really early in the development stage, and not let too many @todos go into production. But in the real world, this rarely happens, there always will be @todo in the code.
 
The next thing is how you report a @todo. A bad example is:
 
// @todo: This code has to be refactored.
 
This does not give a clue what the code does now or why the code should be changed. You should always point out the reason why the code needs to be refactored.
 
 

Refactoring

Then, when the time comes to actually refactor the code, the question is: How do you refactor? It depends on the code that has to be refactored, but most of the time it involves moving code into a separate function, changing the structure of a classes tree or moving the implementation from a function oriented to an object oriented approach.

Finally, you have to check if your refactored code really works. Because you refactored the code, this does not mean that you fixed the bugs. You could even have introduced new ones. So to ensure this didn't happen, the best thing is  to have automated tests that you run on your code, which is not always a trivial task to do.
 

The five conclusions

  1. If possible, try to avoid having many @todos in your code, especially in the one that goes to production.
  2. Always write good documentation for what you have to refactor. It would be good to specify why the code has to be refactored, the priority and optionally why you've chosen not to refactor yet. 
  3. Refactor the code as soon as possible. Ideally is in the development stage.
  4. Always test the new code. If you refactor it, it does not mean that that code is correct.
  5. Avoid writing code you know that you will have refactore it in the future.

If you are looking for a more general blog post on code refactoring you should take a look at SourceMaking's "Introduction to Refactoring".

By Michael Schmid 18th October 2012 Drupal

A few hours ago, the Drupal Security Team informed about a highly critical Drupal 7 core issue: http://drupal.org/node/1815912

The vulnerability allows an attacker to reinstall an existing Drupal site with an external database server and then execute custom PHP code on the web server.

As usual, to mitigate a highly critical vulnerability, a new Drupal 7 version (7.16) was released which fixes this issue. Since it is not always possible to update or patch every customer website immediately there is an accepted workaround for this: Deny access to install.php.

Add this to .htaccess the file:

# Deny access to install.php because of SA-CORE-2012-003 http://drupal.org/node/1815912
<Files install.php>
  Order allow,deny
  ErrorDocument 403 "Sorry, no access to install.php. If you need access you will have to change .htaccess"
</Files>

This will prevent everybody from accessing install.php and rule out that an attacker can use it for an attack.

But overall it is best to update Drupal as fast as possible and also deny write access for settings.php as described in the Drupal security best practices.

You can deny the access to install.php by using this patch and applying it with: "patch < SA-CORE-2012-003_deny_access_install_php.patch"

By Boris Baldinger 10th October 2012 Drupal

After a few weeks of using Sublime Text 2 (ST2) it is time to draw a conclusion. Did Sublime Text 2 manage to be a good replacement for a fully integrated development environment like NetBeans or PhpStorm?

Yes, ST2 is good, but skip the hype.

I joined the flock when ST2 was released and was really into it. Now, after the party, ST2 has just become another working tool. A very comprehensive text editor. That's all. And still, at certain points I miss the quick access to features I get in an integrated development environment. My modest advice: Only switch if you are not happy with your current setup, or have enough time to play around and google your plugins. ST2 is a very modular and highly configurable tool and this makes it fun, - no doubt.

Do I sound a bit hung over? If you are looking for more comprehensive arguments to switch to Sublime Text then you should look at Stuart Herbert's blog posts. He gives 10 reasons why you should switch to ST2 and made a YouTube series on how to setup your ST2 for PHP development. I included the playlist below.

Any final tips for Sublime Text 2?

I recently ran into an issue, where my Git configuration was overwritten by a plugin update. If you are having the same issue, just copy the Git.sublime-settings from the Git package folder to the User folder.

And if you wonder how to check for plugin-updates manually. Just hit CMD+SHIFT+P and type upgrade.

By George Papadongonas 5th October 2012 Drupal

This is the third and final part of this blog series. In the first part we installed and customized the Google Analytics Reports module and in the second part we created a Social Media Dashboard that displays the data in table format using Views.

The dashboard that we created in the previous part displays useful information, but the real fun starts when we create charts to visualize the data and make them easily understandable to everyone.
 
Following a similar procedure as in the previous post, you first have to create different Views panes for every specific metric and then use Page Manager to display all of them together in the dashboard.
 
Unfortunately, the Google Analytics Views module does not still support the “Chart” format, so you have to use the Views Dataviz module. After the installation, there is a new “Dataviz” format in Views, which you can use to create the charts.
 
 
The Dataviz settings are really simple, allowing you to customize the chart display:
 
 
Grouping field: If your report contains multiple dimensions, you have the ability to group your chart by one or more fields and display it in a more meaningful way.
 
Type: From this menu, you can select the type of the chart. Depending on your selection, there may be a secondary menu with more options. For example, for the line chart you can select if you want line smoothing or not and for the pie chart you can define if the text on the pie slices will be a percentage, the actual value, the label of this figure, or just nothing. Usually, it makes sense to experiment with different chart types, trying to find the optimal way to present the data. 
 
Width, Height: You can also define the exact width and height of every chart, or just leave it blank to use the default values.
 
Colors: In this field, you can select the specific colors for your chart, separated by a comma. Accepted values are hex colors (like #6495ED) and color names (like LightCoral).
 
Enable interactivity:  This checkbox defines if the charts will be interactive or not. 
 
So, by keeping the same field definition that we used in the previous post and changing the format from Table to Dataviz, you can easily transform your dashboard. For the specific reports that we built, I preferred to use the Pie Chart type for the three top ones, the column chart for the two next ones and the line chart for the last one. Of course, you can experiment with different types and decide what makes more sense for your case.
 
The final result can be seen in the following image:
 
 
Using Views to display Google Analytics data is the easiest way to do it, but sometimes it’s not that flexible. If you have specific requirements for a report, which cannot be created with Views, you can always write your custom code, using the Google Chart API module.  There are some code examples on the module's documentation page. We will examine more complex use cases with custom code, in one of our future blog posts.  

Pages

Search form

Latest comments

  • home business software programs's picture

    Good day! I simply wish to give a huge thumbs up for the nice info
    you have got here on this post. I will probably be coming again to your weblog for more soon.

    home business s...
  • Agentur Typo3 Programmierung at Steilstarter's picture

    Hello,

    I must say that you are going great. you are sharing your information with us so thanks for that.

    Agentur Typo3 P...
  • Daniel's picture

    By the way, by "no documentation" I´m referring to Views Autorefresh. It is either not complete or conflicting.

    Daniel

Subscribe to Amazee Labs Blog