drupal commerce dealing with any shopping scenario

18
DRUPAL COMMERCE DEA LING WITH AN Y SH O PPING SCENARIO

Upload: trenton-fake

Post on 29-Mar-2015

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

DRUPAL C

OMMERCE

DE

AL I N

G W

I TH

AN

Y S

HO

PP

I NG

SC

EN

AR

I O

Page 2: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

INTRODUCTION

Drupal Commerce adds the functionality online merchants need in a Drupal based site! Eg Cart, Checkout, Orders, Invoices, Shipping, Tax etc

• Created by Ryan Szrama, the author of Ubercart

• Like Drupal, acts as a framework which can be extended

• Distributions for catering to specific scenarios

• Built/supported by Commerce Guys

• 23,000 + active sites

• Growing Commerce specific contrib

• Huge potential

Page 3: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

WHY DRUPAL COMMERCE

• Hands down beats most E-com solutions for anything CMS / Social etc

• Huge D7 contrib space which can be used in Commerce, Eg Image Galleries, Flags, Ratings, newsletters, support forums, blogs etc

• Powerful search with Search API, Facet API and Solr

• Good theme system / responsive - Omega

Where it currently falls down

• Not as mature as existing solutions / not as tried and tested

• Actually still pretty complicated for a standalone simple store

We all know Drupal and have been building CMS sites, why not start using our skills to tackle E Commerce?

Page 4: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

DISTRIBUTIONS

Commerce Kickstart

• Best introduction for commerce

• http://drupal.org/project/commerce_kickstart

• http://demo.commerceguys.com/

MartPlug

• http://drupal.org/project/martplug

• http://demo.martplug.com/

Open Deals

• http://drupal.org/project/opendeals

• http://opendealsapp.com/demo/

Page 5: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE DEPENDENCIES

• Views

• Rules

• Address field

• Entity API

Why are these important?

• Existing ecosystem - lots of modules are “entity-aware”

• Use standard hooks/classes (eg EntityFieldQuery & Metadata Wrappers)

• Hmmmm tasty! Views & Rules…

Page 6: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE ENTITIES

Product A node can have multiple Product reference fields, each contain price, SKU and other Product Attributes. “Product Types” allow for variations

Customer Profile

Customers Profiles contain billing & shipping information. Each user may have multiple profiles, eg Work or Home Address.

Order Orders can have multiple line item references and a single Customer Profile reference. Represents major states through the life of an order (Canceled, Cart, Pending, Complete).

Line Item Used in Orders to store a product references or product specific fields.

Payment Records details of the transaction such the state (pending / success / failure) which updates the order

Page 7: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE FIELDS

Status – cannot edit, from product module

SKU – cannot edit, from product module

Address – from Address contrib module

Price

Product reference

Line item reference

Customer profile reference

Add Attributes as almost any field

Page 8: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

ENTITY METADATA WRAPPERS

• Provided by Entity API

• Much of Commerce expects you to use entity metadata wrappers

• Used by Rules & Search API for their magic

Benefits:

• Allows chaining

• Prevents hardcoded nesting

• Easier Looping

• Getters and Setters

• Some nice extra methods like access, validate etc

Entity API takes an entity type and an entity object as parameters to create a new object which has many useful methods attached to aid in accessing and manipulating an entities properties and fields

Page 9: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

ENTITY METADATA WRAPPERS EXAMPLES

How to get the wrapper and see what's available:

$wrapper = entity_metadata_wrapper('node', $node);

dpm($wrapper->getPropertyInfo());

Helps get values without the nesting. Eg

$node->field_name[LANGUAGE_NONE][0][‘value’];

Becomes:

$wrapper->field_name->value();

Set the field with:

$wrapper->field_name->set(“new value”)

Page 10: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

ENTITY METADATA WRAPPERS EXAMPLES

Chaining Entity data with Audoloading

$order_wrapper = entity_metadata_wrapper(‘commerce_order’, $order);

$address = $order_wrapper->commerce_customer_billing->commerce_customer_address->value()

Looping through a list:

$order_wrapper = entity_metadata_wrapper(’commerce_order', $order);

foreach ($order_wrapper->commerce_line_item->value() as $item) {

//$item is a fully loaded line item entity.

//Get product fields $item->commerce_product->field_name->raw()

}

Page 11: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

ENTITYFIELDQUERY

Provided by Drupal 7 Core API

Query your entities and their field data without writing complex join queries or knowing the schemas.

/** * Implements hook_commerce_product_can_delete(). */function commerce_product_reference_commerce_product_can_delete($product) { // Use EntityFieldQuery to look for line items referencing this // product and do not allow the delete to occur if one exists. $query = new EntityFieldQuery(); $query ->entityCondition('entity_type', 'commerce_line_item', '=') ->entityCondition('bundle', commerce_product_line_item_types(), 'IN') ->fieldCondition('commerce_product', 'product_id', $product->product_id, '=') ->count(); return $query->execute() == 0;}

Page 12: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

VIEWS & RULES

Views:

• Baskets, Checkout etc all built using Rules so can be extended

• Uses Views to make your Product listings / Catalogues

• Build those custom order reports etc pretty quickly

Rules:

• Adjust Prices using Rules for different roles, dates

• Tax and Shipping rates use Rules so can be modified

• Expire Products with Rules Scheduling

• Remove Items from the Cart

• Manage Experience with Custom Messages & Emails

Page 13: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SPECIFIC CONTRIB

commerce_addressbook Allows customers to ueuse previously entered addresses during checkout

commerce_coupon Adds coupons entity to be redeemed on orders and can be dependent on product / user / roles etc. Provides % or fixed price amounts.

commerce_checkout_redirect / commerce_checkout_login

Registers users before checkout

commerce_checkout_progress

Provides a nice block that shows the checkout steps

commerce_price_savings_formatter

Display formatter for price to how savings, take into account tax etc

dc_cart_ajax Better UX through ajax loading

commerce_wishlist Provides wish list functionality

commerce_reorder Allows a user to reorder past orders

commerce_google_analytics

Send order data to Google Analytics

Page 14: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SCENARIO DEMOS

Store needs Customizable products:

Flower shop needs to allow customers to define a custom message and date of delivery.

How to:

The line item is fieldable with the contrib module commerce_custom_product and allows for use cases like business cards, event registrations or donations where customer input is required to be stored.

The field is stored on the line item so its unique to a product.

Demo: http://kickstart.localhost:8082/customproduct/custom-shoes#

Page 15: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SCENARIO DEMOS

Store needs custom node / validation in checkout

A shop requires customers agree to a terms of service before they can make a purchase

How to:

Using commerce_extra_panes allows any node to be added in to the checkout process and ordered. Once the node is added a checkout can be included via a hook form alter using validation to ensure the custom has agreed

Page 16: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SCENARIO RECIPES

Subscription (membership site)

1. Install & configure “role_expire”

2. Setup a “Member” role with default expiration

3. Install & configure content_access to restrict view access to Members

4. Setup a “Membership” product

5. On order completion use Rules to Apply the “Member” role to the customer and depending on product set expiration time

Alternatively

Try commerce_sp – a feature module or commerce_subscription

Page 17: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SCENARIO RECIPES

Virtual goods / Subscription

Sell Product keys:

commerce_product_key – allows attaching unique product keys to orders to unlock / activate software

Sell files:

commerce_file – allows commerce to sell file access

Sell Individual Nodes:

Similar approach to selling membership, however each product should have a node reference to the node which a customer is buying access to. Also use content_access Rules module so on completing as order , loop through the line items using a component, if a node reference is set grant access to the node for the customer

Page 18: DRUPAL COMMERCE DEALING WITH ANY SHOPPING SCENARIO

COMMERCE SCENARIO RECIPES

Gamification

Applicable for Forums, Support sites etc where users can earn points and the get discounts. Use commerce_userpoints to buy products with points or use them to discount purchases