With our products nicely categorized, and the individual items looking good, the last step is to design a top-level catalog overview page using the Views module. In this lesson we'll create a catalog view and use relationships to pull in our product data. We'll also need to aggregate multiple products into one item so we don't have a crazy list of every possibility as individual items, and we'll wrap it all up nice and tidy by grouping the products based on taxonomy.
Additional resources
It’s easy to imagine that different kinds of stores might have certain things they want to have happen when various events take place throughout the purchasing process. For example, if someone adds more than 10 of an item to his cart, a store might want to provide a 10% discount. Or if someone was anonymous and then registers or logs in, a store might want to assign his old shopping cart to his newly found account. Traditionally, this kind of custom logic would have to be done in code by a programmer. However, the Rules module exposes a user interface for clicking together custom logic in a web-based interface. This increases accessibility to non-programmers, and also allows for bits of business logic to be shared among multiple sites with the Rules module’s import and export capabilities. In this lesson we'll review the main architectural blocks of the Rules module, covering events, conditions, actions, variables, and data selectors.
Additional resources
In this lesson we'll try a practical example of some Rules module concepts for the Sweet Tees store. Drupal Commerce’s Tax module stores its tax charging in Rules. Before we can open up our store to the public, we need to ensure that all applicable sales taxes are being applied to our items. Because Sweet Tees is based in California, we will need to charge 7.25% sales tax on all products sold if the customer lives in the state of California. This means we need to set up a conditional tax rate to only apply to California.
Additional resources
Of course, it’s one thing to have a bunch of products ready for purchase, but what Sweet Tees really cares about is accepting money for those products. They want to be able to accept credit card transactions on their online store. There's more than what's on your Drupal site involved in this though. In this lesson, we'll discuss merchant accounts and payment gateways—what they are and why you need them, along with providing payment security.
Additional resources
PayPal is a popular payment processor, especially for new site owners. It allows credit card transactions as well as payments from within PayPal itself. There are predominantly two “flavors” of PayPal’s payment processing tools: Website Payments Standard (WPS) and Website Payments Pro (WPP). For our purposes, we’ll be using Website Payments Standard, since there are no setup fees, no extra security setup required, and we can get started right away. In this lesson we'll create test PayPal buyer and seller accounts, set up access to the test sandbox, and make sure it is working properly.
Additional resources
Now that we have the PayPal side of payments set up, it’s time to set up the Drupal side of things. We’ll do this with the Commerce PayPal module, which is an extension of the main Drupal Commerce package. Just as we saw with Taxes, Commerce payment methods are Rules-enabled for maximum flexibility. In this lesson we'll walk through enabling the PayPal WPS payment method and configuring our PayPal sandbox access so that we can start taking test transactions on our store.
Additional resources
Using Drupal, 2nd edition
Using Drupal source code
Commerce PayPal project
The remaining element of our site is actually implementing the e-commerce portions: an online shopping cart and the ability to process orders, as well as reporting tools to tell us how our store is doing. We will now complete our store configuration by adding a shopping cart, configuring the checkout process, and placing a test order to make sure the whole store is actually working.
Additional resources
In this series, we have covered the basics of setting up an online storefront and shopping cart using the Drupal Commerce package for Drupal. However, there are several additional modules that you will likely want to consider before taking your online store live. We'll take a brief tour of:
Additional resources
In this series, we were able to set up a complete online store for our customer, Sweet Tees, using Drupal Commerce, a powerful, flexible e-commerce framework built on Drupal. We set up a payment system through PayPal’s Website Payments Standard. We also delved into the topic of data imports with the Feeds module, and covered tweaking Drupal’s functionality at various system points with the Rules module. In this lesson we'll tour the Sweet Tees site, discussing our implementation points, and reviewing the modules and resources we used.
Additional resources
Using Drupal, 2nd edition
Using Drupal source code
Up next: Using Drupal Appendix A: Installing and Upgrading Drupal
Just like PHP or JavaScript, Twig has functions that can be used once we’re inside either a Twig delimiter. To see the built-in functions, check out the bottom of the Twig documentation page. In your application, especially if you’re using Twig inside something like Symfony or Drupal, you may have even more functions available to you. Fortunately, the syntax to use a function is always the same: just check out your project’s documentation to see what other goodies you have. In this tutorial, you will start using Twig functions and filters to get the length of a collection in our demo site. We'll also play around with the dump
function to see how we can go about debugging Twig.
Additional resources
Until now, we’ve been working with simple values like pageTitle or products, which is an array that contains simple values where we loop over and print each out. In this tutorial, you will work with more complicated arrays, using keys, and figure out how to get at object data as well.
If we view the HTML source of our project so far, we’ll see just the HTML tags and printed variables from our homepage.twig file
. So far, there’s no HTML layout, head or body tags, but since our project has been ugly long enough, in this tutorial we'll add these. Instead of just putting these in our homepage file, we're going to make this more flexible by using template inheritance, so we can reuse these pieces in other template files as we grow our site. We'll be diving into the world of Twig extends and blocks, and talking about how to avoid common mistakes.
Additional resources
Twig: The Basics
FreeTwig is a templating language for PHP, which is a boring way of saying that it’s a tool used to output variables inside HTML. In this series we'll show you how to use Twig from the ground up, clearly pointing out its syntax, and then graduating to some really neat and advanced tricks. We'll start with a look at Twig syntaxes, functions and filters. Then we'll get into the world of debugging with the dump()
function. With the basics under control, we'll move to handling arrays and objects. template inheritance, tests, looping tricks, and macros (Twig functions).
To make this interesting, we're going to build something useful with Twig, like a penguin clothing store! We're starting out with a small website set up under your web server’s document root and a test page called test.php, which you can find in the series demo site download. In this lesson, you will create your first Twig template, render a variable, and learn the basic Twig syntax you'll need to know.
Additional resources
Twig Templating
CourseIn this tutorial we're going to wrap things up by taking a look at some quick, simple tips for working with Twig. We're going to explain what GlobalVariables is, and then play with the block function and clean up some whitespace issues.
Additional resources
In this lesson we'll going to look at a few shortcuts we can use in our controller, using the SensioFrameworkExtraBundle
, which comes with the standard Symfony project. We're going to review how to use @Template
rendering, annotations, and working with routes.
Additional resources
Autoloading is the magic that lets us use classes without needing to require or include the file that holds them first. An autoloader has a tricky job: given any class name, it needs to know the exact location of the file that holds that class. In many modern projects, including ours, Composer handles this for us, and there are two pieces to understanding how it figures out what file a class lives in. In this lesson we're going to get an overview of how directory structures and namespaces make autoloading work.
Additional resources
A fixture is just a PHP class that puts some stuff into the database. To get your dummy data set up, in this lesson, you'll write a fixture and then load it up.
We have the application looking a lot better, and now, to see things fleshed out a little more we're going to load fixtures, which are dummy data we put into the database. When we started the project, we downloaded the Symfony Standard edition—our pre-started project that came with Symfony and other tools like Doctrine. Unfortunately, it didn’t come with any tools for handling fixtures. To do this yourself, you're going to learn to use Composer and KnpBundles.com to take care of things.