SitePoint PHPShopify App Development Made Simple with HTTP APIs and Guzzle (26.10.2016, 19:01 UTC)

In this tutorial, you're going to get started with developing Shopify apps. You're going to create a simple app that lists out products from a Shopify store. The full source code of the app is available on Github.

Shopify logo

What are Shopify Apps?

Shopify apps are a way of extending the functionality of a Shopify store or to provide ecommerce capabilities to websites or mobile apps. Here's a list of approaches to do this:

  • HTTP API - gives web apps the ability to perform different operations in a Shopify store. Things like adding a customer, getting a list of products, or listening for different events. This is done by means of webhooks.
  • JavaScript Buy SDK - allows you to fetch product information, add items to a cart and checkout either from a website or hybrid mobile apps such as those built with Cordova.
  • Embedded App SDK - allows you to embed your web app directly into the Shopify admin interface. This is useful for apps that have an admin settings page. Instead of the user having to access it on a separate website, the web app will be loaded as an iframe.
  • iOS and Android Buy - used for integrating Shopify checkout into your iOS or Android app.
  • Shopify POS App SDK - allows you to embed your web apps directly inside the Shopify POS.

In this tutorial, you're going to learn about the HTTP API.

Sign up for a Shopify Partner Account

The first thing that you need to do is to sign up for a Shopify Partner Account. This allows you to create a development store for testing a Shopify app. You will be asked to fill out a form with things like your company name, business type, email address, website, password and other relevant information.

Shopify Partner Signup

If all the information you provided is valid, you should be greeted with the following page:

Shopify Partner Success Page

Create a Development Store

The next step is creating a development store which is like a Shopify store. You can add products, store HTML and CSS code for themes, and test purchases through a bogus payment gateway. The only limitation is that you can't add a custom domain or charge customers in a development store.

Click the Create a development store button and you will be redirected to the following page:

Create Development Store

Add the store name, the password for logging in to the store (your Shopify partner email address is the login email), and the kind of store to create. Stick with an Online store for now. This gives you the ability to build custom themes, develop an app, or set up your client's online store. Once you're done with filling the form, click the Create Store button to create the development store.

Continue reading %Shopify App Development Made Simple with HTTP APIs and Guzzle%

Nomad PHPWrite More Expressive Tests with Hamcrest PHP (26.10.2016, 15:05 UTC)

Speaker: Gareth Ellis @garethellis Have you ever struggled to write expressive, easy-to-read test assertions in PHP? If so, then Hamcrest PHP could be the answer. In this talk, I’ll show you how to use Hamcrest to make your test assertions a positively pleasant experience, and cover how you can create your own custom matchers for …

The post Write More Expressive Tests with Hamcrest PHP appeared first on Nomad PHP.

Davey ShafikI’m Sorry… (26.10.2016, 06:14 UTC)

Some of you may have noticed that I was absent from several events over the last month, specifically, DrupalCon Dublin, PHPNW, and BulgariaPHP.

I had intended to fly from my home to Dublin, before hopping over to Manchester, and then finally on to Sofia before coming back home again.

I was stoked to attend my first ever DrupalCon, to be going back home for the excellent PHPNW, and ending my trip with my favorite conference of 2015, BgPHP. It was going to be amazing.

And I couldn’t do it.

I did a lot of travel last year, and it was amazing. And tiring. I decided this year to do less travel, and I think that objectively, I have. However, this year is the first time my son has also cried when I’ve left, and my travel has been bunched up such that I’ve been away on several long trips.

I had just completed an unexpected West-East-West-East-West (SEA (Home) -> BUF (CodeDaze) -> SEA (PNWPHP) -> JFK (Velocity) -> SEA (Home)) and it was exhausting.

So, as I got up, said goodbye to my family, and loaded my stuff in my cab to the airport, I was anxious about being away for yet another extended period of time.

We started our drive to the airport, and I used my time to share my feelings with some friends via Twitter… and it became clear to me that I was either experiencing, or close to burnout.

Despite my embarrassment, I had my driver turn around and take me home. I cancelled my flights, my hotels, and told my boss. I contacted DrupalCon and went to bed. After I got up again, I contacted PNWPHP, and yet… I still hoped to make BgPHP. I thought maybe I could get my shit together in 5 days or so and still make the event I’d been looking forward to all year. But no… I couldn’t. And so, a few days later I told them too.

For those wondering, my emails were something like this:

Hi Ramelina (and the rest of the BgPHP crew),

As you know BgPHP is my absolute favorite conference in the entire world… however, I won’t be able to make it this year :(

After scaling back my travel due to mental health reasons I’m no longer able to attend :(

I understand that this is less than ideal for you and the wonderful attendees, and I’d like to do anything possible to make it easier for you.

Please let me know if I can be of any help, and if there any costs (such as hotel) that I need to cover.

I’m really sorry :(

And you know what? Everyone was fantastic. Nobody got mad, nobody was upset, they all just wished me well, and I’m sure scrambled to fix the mess I had made. And I am eternally grateful.

And dreadfully sorry.

I am sorry to the organizers, of course, but also to the attendees and wider community. As a Developer Advocate, I would like to be relied on by conference organizers and the community, as a known entity of stability. This is why, for example, I always let organizers know I have other talks I can give if someone else can’t speak for any reason. This is why I try to always get in early, and I work so hard on my slides.

I’m currently writing this from Berlin, and in truth, there was still a bit of anxiety leaving for this trip (with Akamai Edge in San Francisco first) — but, I’m glad I did it, if only to prove to myself that I still can.

Thank you, to every one who reached out to me when they heard I wasn’t going to make it, and in person this week, it meant a lot to me.

I will try to do better.

Photo by GPS, used under a CC-BY-SA 2.0 License.

Voices of the ElePHPantInterview with Larry Garfield (25.10.2016, 10:00 UTC)
Larry Garfield

Show Notes

More from this guest

See Larry’s talks, Functional PHP, and Make Your Code Do Your Job on Nomad PHP

The post Interview with Larry Garfield appeared first on Voices of the ElePHPant.

Evert PotSwitching to Google AMP and back (25.10.2016, 04:26 UTC)

A few months ago I added support for AMP to this blog. Not that it desperately needed it, but the premise seemed interesting and I figured it would be good to get some experience with new technology. The real selling point for me is how fast this website would appear in search results.

The switch to AMP

This website is built with Jekyll, hosted on Github pages, and behind a Cloudflare proxy. Why cloudflare? Same reason for using AMP! Websites are pretty much my business, and I want my own home to be powered by both TLS and HTTP/2!

What this meant for AMP though is that I had to change my main site into an AMP site. Dynamic websites unlike this might be able to create both an AMP and non-AMP website.

In practice these are the things I had to do:

  • Inline stylesheets. This was fairly easy with jekyll, I just had to change my linked stylesheets to an {% include .. %}.
  • Add a bunch of AMP boilerplate.
  • Add JSON-LD in my website header. The AMP website says it’s not required, but without it you’re not going to get AMP support in google results.
  • Changing all <img> tags to <amp-img> tags.
  • Removing all javascript. The only bits of JS I had was for google analytics, which gets replaced with <amp-analytics>.
  • And.. Disqus. This was a bit harder to solve.


Disqus requires javascript. I figured the best solution for using Disqus with AMP is to have the Disqus comment box run in an iframe. This created a few more challenges:

AMP doesn’t allow javascript, but it does allow iframes using <amp-iframe>, but there’s a caveat. If you want to run javascript inside that iframe, the iframe has to be hosted on a different domain for security reasons.

I tried to trick it with some domain variations, and a redirect, but had no luck. I ended up creating a separate github repository specifically for serving my Disqus comments.

This worked, but there was a second issue. Disqus itself also uses an iframe to embed comments. To ensure that this Disqus iframe is large enough, it will dynamically resize based on its contents.

I had to do something similar. I had to detect when the inner Disqus iframe resized, so I could resize the outer amp iframe. I had trouble doing this with my usual javascript events. After I while I realized that Disqus itself must send a message from the iframe to the top document. I figured it would likely do this with the postMessage javascript API. And I was right!

So all I had to do is listen for the resize messages the Disqus application sends out, and then forward the resize messages to the AMP document. A total hack, but here is a snippet:

window.addEventListener('message', function(ev) {
    if (String(!=='{') {
        // Not a disqus event
    var data = JSON.parse(;
    if ( !== "resize") 

Truncated by Planet PHP, read more at the original (another 4971 bytes)

Matthew Weier O'PhinneyAutomating PHPUnit with Node (24.10.2016, 20:25 UTC)

I've been trying to automate everything this year. When working on OSS, this is usually as simple as setting up Travis CI; in some cases, even that becomes a little more involved, but remains possible.

But that's continuous integration. What about continuous development?

Continuous development?

With continous integration, every time I push to a branch associated with a pull request or on the origin repository, a build is triggered. Which is great, because I can verify and validate that my code runs fine on all the target platforms. But I have to wait for the build to trigger and then run.

Ideally, I should also be testing locally; I likely don't want to push anything upstream that will fail! So, I look in the contributing guidelines, and determine how to run coding standards checks and unit tests, and do those manually.

Manually? Ugh. Too easy to forget, and too easy to lose track and make a ton of changes between runs, making breakage easier.

I'd like to automate running these as part of my development process. I want continuous development cycles.

Preparing your project

The first step is preparing your project. I like to run my tests and CS checks using Composer, as that allows me to change what I'm using later, but also allows me to standardize invocation of the tools. I define the following scripts in my composer.json:

"scripts": {
  "check": [
  "cs-check": "phpcs --colors",
  "cs-fix": "phpcbf --colors",
  "test": "phpunit --colors=always"

You may, of course, need to alter these to use the tools specific to your own project. The main thing is that you have a "check" target, which runs all the various QA tools.

You don't need to do this. But I definitely recommend it. If you can simplify invocation for your users, and for your tools, automation is far easier.

Using gulp

Node has some great tools for watching the filesystem and reacting to it. Two of these are considered "build" or "workflow" tools: Grunt and Gulp.

I've opted for Gulp here, as the setup is far simpler; that said, it's not difficult to do in Grunt, either.

First, you'll need npm, which usually comes packaged with node, or yarn, a more recent addition to the node ecosystem. Once you have these, you can continue.

Second, I installed a few dependencies:

  • gulp is the actual taskrunner. It needs to be installed both globally, and locally. It includes the functionality for watching the filesystem.
  • gulp-shell provides the ability to execute arbitrary command line tools.
  • gulp-notify ties into your system's notifications abilities.

Navigate to your project directory, and install these as follows:

$ npm install -g gulp # this may require sudo, depending on your system
$ npm install --dev gulp gulp-shell gulp-notify

If you are using yarn:

$ yarn global add gulp # this may require sudo, depending on your system
$ yarn add --dev gulp gulp-shell gulp-notify

Third, create the following gulpfile.js in your project:

/* jshint: node: true */
var gulp = require('gulp');
var notify = require('gulp-notify');
var shell = require('gulp-shell');
var project = require('path').posix.basename(__dirname);

gulp.task('default', ['watch']);
gulp.task('php_check', function () {
    .pipe(shell('composer check'))
    .on('error', notify.onError({
      title: project + ' failures',
      message: project + ' CS checks and/or tests failed'
gulp.task('watch', function () {
    ['phpunit.xml.dist', 'phpcs.xml', 'src/**/*.php', 'test/**/*.php'],

What the above does is:

  • Watch the filesystem for changes to any of:
    • phpunit.xml.dist, which would indicate a change to the test runner behavior.
    • phpcs.xml, which would indicate a change to the coding standards.
    • PHP files found in either the src/ or test/ directories.

Truncated by Planet PHP, read more at the original (another 4483 bytes)

SitePoint PHPIs It Possible to Write and Run PHP Code on an iPad? (24.10.2016, 17:00 UTC)

I love the iPad. It's a fantastic form factor for media consumption and gaming; and it also works well as an e-reader. The trouble is I don't use it nearly as much as I could. Most of the time I'm consuming media (Netflix, Twitch, YouTube), I'm coding in parallel.

I can do that on my MacBook, but I've never been able to do that until now. Two things have made it possible:

  1. iOS recently added support for picture in picture playback. That means I can keep a video app playing, while working on something else.

  2. Fantastic apps (like DraftCode and Working Copy) make it possible to code and run PHP apps, and push changes to Github, directly from the iPad.

Picture in picture

Today I'm going to show you how I code on an iPad. I won't pretend it's a perfect workflow (what workflow is?), but this is as exciting for me as the first time I used a laptop instead of a desktop.

I started writing this post a while ago. To tell you the truth, I don't think the apps I've going to talk about were ready then. They've both received updates since. It's as though the developers could hear inside my brain, and wanted to make me happy. I also apologize for the size of this page; there are many animated gifs..


One of the most important parts of this whole experiment, is finding the right keyboard. When it comes to mobile devices, there's no shortage of poor-quality hardware.

I searched for quite some time before I settled on a keyboard I liked the look of. I can safely say I made the right choice.

This keyboard is about twice the length of the iPad Mini 2, and weighs about the same. The keys feel amazing, with plenty of space between them. And it's quiet!

This keyboard also has a trackpad. iOS doesn't support mouse or trackpad (as far as I'm aware), so you don't have to go with a keyboard that has a trackpad. I like this because it can double as an input device for my Raspberry Pi (using a single USB port for keyboard and trackpad).

Unless you're using a Bluetooth keyboard, you're going to need a USB port. Fortunately, Apple produce an adapter (originally made for digital camera compatibility), that works wonderfully with every USB keyboard I've ever tried.

The Windows key doubles as a command key, and Windows + z / Windows + x / Windows + c / Windows + v all work as you're used to. You can also use Windows + → and Windows + ← to move to the beginning and end of lines.

The All-in-one Media keyboard is listed as USD 39.95 on the Microsoft website, but you can pick it up for USD 29.99 on Amazon. The Lightning USB adapter is listed as USD 29.99 on the Apple website, and actually costs a couple dollars more from Amazon.


I've already mentioned a couple of apps (DraftCode and Working Copy), and the truth is these are the only two you need.

What tools do you use to code? You probably use an IDE (or at the very least a text editor, like Atom). You probably use something like Git, to organize and version your source code.

Continue reading %Is It Possible to Write and Run PHP Code on an iPad?%

PHP ClassesHow to Stream Your PHP Code on (24.10.2016, 08:41 UTC)
By Danilo Bilandzija is a live streaming platform that allows people to share code, exchange programming experiences, and socialize, while improving their code.

Read this article to learn how you can expose your PHP programming skills while you program live, as well how you can embed your recording live streaming videos in PHP Classes, so other PHP Classes users can learn how you are doing your work.
Liip Drupal SearchAPI and result grouping (24.10.2016, 07:17 UTC)

In this blog post I will present how, in a recent e-Commerce project built on top of Drupal7 (the former version of the Drupal CMS), we make Drupal7, SearchAPI and Commerce play together to efficiently retrieve grouped results from Solr in SearchAPI, with no indexed data duplication.

We used the SearchAPI and the FacetAPI modules to build a search index for products, so far so good: available products and product-variations can be searched and filtered also by using a set of pre-defined facets. In a subsequent request, a new need arose from our project owner: provide a list of products where the results should include, in addition to the product details, a picture of one of the available product variations, while keep the ability to apply facets on products for the listing. Furthermore, the product variation picture displayed in the list must also match the filter applied by the user: this with the aim of not confusing users, and to provide a better user experience.

An example use case here is simple: allow users to get the list of available products and be able to filter them by the color/size/etc field of the available product variations, while displaying a picture of the available variations, and not a sample picture.

For the sake of simplicity and consistency with Drupal’s Commerce module terminology, I will use the term “Product” to refer to any product-variation, while the term “Model” will be used to refer to a product.

Solr Result Grouping

We decided to use Solr (the well-known, fast and efficient search engine built on top of the Apache Lucene library) as the backend of the eCommerce platform: the reason lies not only in its full-text search features, but also in the possibility to build a fast retrieval system for the huge number of products we were expecting to be available online.

To solve the request about the display of product models, facets and available products, I intended to use the feature offered by Solr called Result-Grouping as it seemed to be suitable for our case: Solr is able to return just a subset of results by grouping them given an “single value” field (previously indexed, of course). The Facets can then be configured to be computed from: the grouped set of results, the ungrouped items or just from the first result of each group.

Such handy feature of Solr can be used in combination with the SearchAPI module by installing the SearchAPI Grouping module. The module allows to return results grouped by a single-valued field, while keeping the building process of the facets on all the results matched by the query, this behavior is configurable.

That allowed us to:

  • group the available products by the referenced model and return just one model;
  • compute the attribute’s facets on the entire collection of available products;
  • reuse the data in the product index for multiple views based on different grouping settings.

Result Grouping in SearchAPI

Due to some limitations of the SearchAPI module and its query building components, such plan was not doable with the current configuration as it would require us to create a copy of the product index just to apply the specific Result Grouping feature for each view.

The reason is that the features implemented by the SearchAPI Grouping are implemented on top of the “Alterations and Processors” functions of SearchAPI. Those are a set of specific functions that can be configured and invoked both at indexing-time and at querying-time by the SearchAPI module. In particular Alterations allows to programmatically alter the contents sent to the underlying index, while the Processors code is executed when a search query is built, executed and the results returned.
Those functions can be defined and configured only per-index.

As visible in the following picture, the SearchAPI Grouping module configuration could be done solely in the Index configuration, but not per-query.

SearchAPI: processor settings

Truncated by Planet PHP, read more at the original (another 4725 bytes)

Stefan KoopmanschapZendCon 2016 (21.10.2016, 03:30 UTC)

It's just past 5AM as I start writing this. I'm sitting downstairs in the ZendCon hotel, with a view on an empty bar and brightly coloured gambling machines. Since I woke up at 3AM (don't you love jetlag?) and today is the day I travel back home, I've been reflecting on the conference. I'll be missing a few sessions because I had to leave early, but I've already gotten a lot of new stuff to ponder about, my head is pretty full. Time to let it sink in a bit.

As I was pondering the lessons of this conference, I thought back to the last talk of yesterday, Exploiting the brain for fun and profit by Alena Holligan. One of the things Alena talked about was how you can improve your learning. One of the things she mentioned was teaching others. Teaching others really helps you to learn stuff yourself. But the other thing was: Write it down. Writing things down will help you to not forget stuff. She even mentioned the situation I've been in a couple of times: Googling for a problem only to end up on your own blog, where you discuss the solution. As such, I'm writing down some of my lessons of ZendCon. So I won't forget, and hopefully to help others learn about this stuff as well.

Let's start with the opening keynote by Andi Gutmans and Rod Cope. Andi and Rod looked back at where we came from and where we're going with technology. While the picture for the future that was painted sounded awesome for users, it sounded horrible for privacy. I'm really curious to see where this will be going.

I also attended the Composer for corporate use talk that Stephan Hochdörfer did. One of the things I learned from that talk is the composer license command, which gives you an overview of the licenses used by your dependencies. Related to that, I also learned about VersionEye, which seems like an interesting service. That is now on my list of things to check out.

I was really looking forward to see Uncle Bob do a keynote at ZendCon, and this turned out to be an amazing keynote. He gave a nice overview of some common patterns from the past as well as the present. It also taught me that at my current project we're doing pretty well for some of these topics. There's always room for improvement, but we're on the right track. It is good to get that kind of confirmation.

Next to the talks I also had a nice chat with some of the sponsors at their booths. My most important lesson there was the Clean Coders video platform. Before ZendCon I was not aware it even existed, but with a lot of material delivered by people like Uncle Bob, Corey Haines and Michael Norton on topics such as architecture, technical debt, testing, SOLID etc it looks like an amazing opportunity.

It has been another amazing ZendCon, and I'm bringing the lessons back home with me.

LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP