drupal commerce 2.x drupalcamp london 2015
TRANSCRIPT
![Page 1: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/1.jpg)
DRUPAL COMMERCE 2.XDRUPAL CAMP LONDON 2015
Presented by David Kitchen / @dwkitchen
![Page 2: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/2.jpg)
INTRODUCTIONS
![Page 3: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/3.jpg)
DAVID KITCHEN
![Page 4: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/4.jpg)
Technical Lead for Commerce Guys UKTax specialist and Commerce Contributor
![Page 5: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/5.jpg)
DRUPAL COMMERCE 2.X CO-MAINTAINERS
![Page 6: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/6.jpg)
Bojan Zivanovic (bojanz) and Ryan Szrama (rszrama)
![Page 7: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/7.jpg)
Our vision is for Drupal Commerce to be the number oneopen source e-commerce platform in the world...
Powering truly flexible e-commerce.
![Page 8: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/8.jpg)
DRUPAL COMMERCE 1.XA brief history.
![Page 9: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/9.jpg)
BUILT FROM SCRATCH ON DRUPAL 7
![Page 10: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/10.jpg)
MINIMALISTIC AND FLEXIBLE
![Page 11: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/11.jpg)
USES VIEWS FOR ALL LISTINGS
![Page 12: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/12.jpg)
USES RULES FOR BUSINESS LOGIC
![Page 13: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/13.jpg)
RELIES ON "ESSENTIAL CONTRIBS" AND DISTRIBUTIONS TOCOMPLETE THE EXPERIENCE
![Page 14: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/14.jpg)
WE'RE DOING SOMETHING RIGHT...
![Page 15: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/15.jpg)
SYMFONY PHP LIBRARIES
![Page 16: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/16.jpg)
WE* STARTED WITH RESEARCH*Led by Bojan Zivanovic.
Define the deficiencies in our own softwareExisting */money librariesSonata / Sylius e-commerce bundlesNon-Symfony PHP applicationsNon-PHP applications
![Page 17: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/17.jpg)
IDENTIFYING OUR WEAKNESSESAge old tax management issuesIncomplete price management APIIncomplete currency formatting rulesAddress implementation stretched to the limitLimited ability to collaborate outside of Drupal
![Page 18: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/18.jpg)
PROPOSING STANDALONE SOLUTIONSInternationalization (esp. currency formatting)Address formatting / validationTerritory grouping (to support taxing)Tax rate management (at least for VAT)Price calculation and manipulation
![Page 19: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/19.jpg)
Not just interfaces / classes but unprecedented data.also
![Page 20: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/20.jpg)
Minimal dependencies.
![Page 21: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/21.jpg)
Simple APIs with clear documentation and examples.
![Page 22: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/22.jpg)
Full test coverage.
![Page 23: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/23.jpg)
Reusable by any PHP based e-commerce application.
![Page 24: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/24.jpg)
INTLNumber Formatter, inspired by intl.CurrenciesCountriesLanguages
COMING SOON
Date Formatting
Drupal Commerce blog.
![Page 25: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/25.jpg)
CURRENCY HANDLING
$ ¢ £ p ¥ ₤ ₧ € ₹ ₩ ₴ ₯ ₮ ₲ ₳ ₵ ₭ ₪ ₫
![Page 26: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/26.jpg)
CURRENCY FORMATTING
€12,345.99
12 345,99 €
12.345,99 €
د.إ. ۹۹۹٫۹۹
![Page 27: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/27.jpg)
PRICINGA price is a value object. Each operation (add, subtract,
multiply, divide, round) produces a new price instance. Allamounts are passed as strings, and manipulated using
bcmath.
![Page 28: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/28.jpg)
CREATING PRICES
use CommerceGuys\Intl\Currency\CurrencyRepository;use CommerceGuys\Pricing\Price;
$currencyRepository = new CurrencyRepository;$currency = $currencyRepository>get('EUR');
$firstPrice = new Price('99.99', $currency);$secondPrice = new Price('100', $currency);$thirdPrice = new Price('20.307', $currency);
![Page 29: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/29.jpg)
PRICE OPERATIONS
// Every operation produces a new Price instance.$total = $firstPrice>add($secondPrice)>subtract($thirdPrice)>multiply('4')>divide('2');echo $total; // 359.366 EURecho $total>round(); // 359.37 EURecho $total>round(Price::ROUND_HALF_UP, 1); // 359.4 EURecho $total>greaterThan($firstPrice); // true
![Page 30: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/30.jpg)
CURRENCY CONVERSION
use CommerceGuys\Intl\Currency\CurrencyRepository;use CommerceGuys\Pricing\Price;
$currencyRepository = new CurrencyRepository;$eur = $currencyRepository>get('EUR');$usd = $currencyRepository>get('USD');
// Use an external library to get an actual exchange rate.$rate = 1;$eurPrice = new Price('100', $eur);$usdPrice = $eurPrice>convert($usd, $rate);echo $usdPrice;
![Page 31: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/31.jpg)
CURRENCY FORMATTING
use CommerceGuys\Intl\Currency\CurrencyRepository;use CommerceGuys\Intl\NumberFormat\NumberFormatRepository;use CommerceGuys\Intl\Formatter\NumberFormatter;use CommerceGuys\Pricing\Price;
$currencyRepository = new CurrencyRepository;$currency = $currencyRepository>get('USD');$price = new Price('99.99', $currency);
$numberFormatRepository = new NumberFormatRepository;$numberFormat = $numberFormatRepository>get('enUS');
$currencyFormatter = new NumberFormatter($numberFormat, NumberFormatter::CURRENCY);echo $currencyFormatter>formatCurrency($price>getAmount(), $price>getCurrency());
![Page 32: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/32.jpg)
ADDRESSINGAddress formats for 200 countriesSubdivisions (administrative areas, localities, dependentlocalities) for 40 countriesSubdivision translations for all of the parent country's (i.eCanada, Switzerland) official languages.Validation (via Symfony Validator)Form generation (via Symfony Form)Postal formatting
Featured on the Drupal Commerce blog.
![Page 33: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/33.jpg)
ADDRESS DATA
use CommerceGuys\Addressing\Repository\AddressFormatRepository;use CommerceGuys\Addressing\Repository\SubdivisionRepository;
$addressFormatRepository = new AddressFormatRepository();$subdivisionRepository = new SubdivisionRepository();
// Get the address format for Canada.$addressFormat = $addressFormatRepository>get('CA');
// Get the subdivisions for Canada, in French.$states = $subdivisionRepository>getAll('CA', 0, 'fr');foreach ($states as $state) echo $state>getName();
![Page 34: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/34.jpg)
WHAT FIELDS?
![Page 35: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/35.jpg)
SOMEWHERE ELSE
![Page 36: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/36.jpg)
ADDRESS FORMAT
Which fields are used, and in which orderWhich fields are requiredWhich fields need to be uppercasedField labelsRegular expression for validating postal codes
![Page 37: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/37.jpg)
ADDRESS FORMATTING
use CommerceGuys\Addressing\Formatter\PostalFormatter;use CommerceGuys\Addressing\Provider\DataProvider;
$dataProvider = new DataProvider();$formatter = new PostalFormatter($dataProvider);
// Format an address for sending from Switzerland, in French.// If the address destination is not Switzerland, the country name will be// appended in French, uppercase.echo $formatter>format($address, 'CH', 'fr');
![Page 38: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/38.jpg)
ZONEZones are territorial groupings mostly used for shipping or
tax purposes. For example, a set of shipping rates associatedwith a zone where the rates become available only if the
customer's address matches the zone.
A zone can match other zones, countries, subdivisions(states/provinces/municipalities), postal codes. Postal codes
can also be expressed using ranges or regular expressions.
![Page 39: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/39.jpg)
Create the German VAT zone
use CommerceGuys\Addressing\Model\Address;use CommerceGuys\Zone\Model\Zone;use CommerceGuys\Zone\Model\ZoneMemberCountry;
$zone = new Zone();$zone>setId('german_vat');$zone>setName('German VAT');$zone>setScope('tax');
![Page 40: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/40.jpg)
Add Germany to the zone,
$germanyZoneMember = new ZoneMemberCountry();$germanyZoneMember>setCountryCode('DE');$zone>addMember($germanyZoneMember);
add the 4 Austrian postal codes that are in Germany for VAT.
$austriaZoneMember = new ZoneMemberCountry();$austriaZoneMember>setCountryCode('AT');$austriaZoneMember>setIncludedPostalCodes('6691, 6991:6993');$zone>addMember($austriaZoneMember);
![Page 41: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/41.jpg)
Initialising a zone matcher.
use CommerceGuys\Addressing\Model\Address;use CommerceGuys\Zone\Matcher\ZoneMatcher;use CommerceGuys\Zone\Repository\ZoneRepository;
$repository = new ZoneRepository('resources/zone');$matcher = new ZoneMatcher($repository);
![Page 42: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/42.jpg)
Create an address.
$austrianAddress = new Address();$austrianAddress>setCountryCode('AT');$austrianAddress>setPostalCode('6692');
Get the matching tax zones.
$zones = $matcher>matchAll($austrianAddress, 'tax');
Is in Germany for VAT.
![Page 43: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/43.jpg)
TAXSmart data model designed for fluctuating tax rateamounts ("19% -> 21% on January 1st").Predefined tax rates and zones for EU countries, Iceland,Norway, South Africa and Switzerland. More to come.Tax resolvers with logic for all major use cases.
![Page 44: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/44.jpg)
EU TAX RESOLVER
use CommerceGuys\Tax\Repository\TaxTypeRepository;use CommerceGuys\Tax\Resolver\Engine\TaxTypeResolverEngine;use CommerceGuys\Tax\Resolver\Engine\TaxRateResolverEngine;use CommerceGuys\Tax\Resolver\TaxType\EuTaxTypeResolver;use CommerceGuys\Tax\Resolver\TaxRate\DefaultTaxRateResolver;use CommerceGuys\Tax\Resolver\TaxResolver;
$taxTypeRepository = new TaxTypeRepository();$taxTypeResolverEngine = new TaxTypeResolverEngine();$taxTypeResolverEngine>add(new EuTaxTypeResolver($taxTypeRepository));$taxRateResolverEngine = new TaxRateResolverEngine();$taxRateResolverEngine>add(new DefaultTaxRateResolver());$resolver = new TaxResolver($taxTypeResolverEngine, $taxRateResolverEngine);
![Page 45: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/45.jpg)
CALCULATES THE VAT RATE BASED ON
Goods or ServicesType of service, digital, educationB2C or B2BSupplier locationCustomer Location
![Page 46: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/46.jpg)
FULL DATA INC. HISTORIC RATES
"name": "British VAT","zone": "gb_vat","tag": "EU","rates": [ "id": "gb_vat_standard", "name": "Standard", "display_name": "% VAT", "default": true, "amounts": [ "id": "gb_vat_standard_1991", "amount": 0.175, "start_date": "19910319", "end_date": "20081130" ,
![Page 47: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/47.jpg)
WE'RE DOING SOMETHING RIGHT...
![Page 48: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/48.jpg)
DRUPAL COMMERCE 2.X
![Page 49: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/49.jpg)
DRUPAL COMMERCE 2.X SPRINT
Validated the architecture with members of SensioLabs,Smile, Publicis Modem, OSInet, i-KOS, Adyax, Ekino, and
others.
![Page 50: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/50.jpg)
ONCE AGAIN, WE START FROM SCRATCH<?php
namespace Drupal\commerce\Entity
![Page 51: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/51.jpg)
![Page 52: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/52.jpg)
![Page 53: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/53.jpg)
2.X ENTITY RELATIONSHIP MODEL
![Page 54: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/54.jpg)
![Page 55: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/55.jpg)
MULTI-STORE / MULTI-VENDOR
![Page 56: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/56.jpg)
HIERARCHICAL PRODUCT MODEL
![Page 57: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/57.jpg)
IMPROVED ORDER WORKFLOWS
![Page 58: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/58.jpg)
![Page 59: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/59.jpg)
IMPROVED PAYMENT PROCESSINGCreate a "mini" ledger for payments with double entry like
accounting features.
![Page 60: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/60.jpg)
![Page 61: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/61.jpg)
![Page 62: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/62.jpg)
![Page 63: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/63.jpg)
TRY IT OUT
![Page 65: Drupal Commerce 2.x DrupalCamp London 2015](https://reader031.vdocuments.site/reader031/viewer/2022020218/55a79a891a28ab206e8b46c1/html5/thumbnails/65.jpg)
QUESTIONS?Office hours: Wednesdays at 1PM GMT
Find us in #drupal-commerce.