Advanced moduledevelopment d6_slideshare
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Advanced moduledevelopment d6_slideshare

on

  • 1,389 views

Advanced module development featuring Ubercart uc_etranzact contrib module on Drupal 6. DrupalCamp Lagos 2011.

Advanced module development featuring Ubercart uc_etranzact contrib module on Drupal 6. DrupalCamp Lagos 2011.

Statistics

Views

Total Views
1,389
Views on SlideShare
1,389
Embed Views
0

Actions

Likes
0
Downloads
19
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Advanced moduledevelopment d6_slideshare Presentation Transcript

  • 1. Advanced ModuleDevelopment (D6)Case study: UC_Etranzact Ubercart contrib module Kayode Odeyemi Technical Architect, Opevel DrupalCamp Lagos 2011
  • 2. Where to start from?There are various ways of starting a Drupalmodule;• Using Features module: Makes your Drupal module exportable and deployment easier.• Using Module Builder module: auto-generates a skeleton or "scaffolding" for a module
  • 3. Drupal Common Hooks• Hook_menu• Hook_init• Hook_help• Hook_nodeapi• Hook_theme• Hook_install• Hook_uninstall• Hook_form• Hook_form_alter• Hook_form_submit• Hook_form_validate
  • 4. Very useful Drupal APIs for everyday development • Module_invoke • Module_load_include • Drupal_write_record • Function_exists • Call_user_func_array • Db_table_exists • Db_query • Db_result • Db_object_fetch_array and db_object_fetch_object • Drupal_set_message or dsm if using devel module • Db_create_table • Update_sql • Views_get_views_result • Db_add_field • Db_drop_field • Drupal_get_schema • Element_children • Views_get_default_view
  • 5. Writing Drupal HooksThere are different ways of writing Drupal hooks.// Using module_implements inline within a non-hook function and using module_invokeforeach(module_implements(‘hook_name) as $module) { module_invoke($module, ‘hook_name, $args);}// Explicitly writing the hook as a function with module_implements alonefunction mymodule_hook($fees) { foreach (module_implements(‘hook_name) as $module) { $function = $module . _hook_name; $result = $function($fees); if (isset($result) && is_array($result)) { $return = array_merge($return, $result); } else if (isset($result)) { $return[] = $result; } } return $return;}
  • 6. drupal_http_request: Drupals simple curl equivalent // curl $curl = curl_init(); $apiurl = variable_get(uc_etranzact_demo_mode, 1) ? UC_ETRANZACT_SERVICE_DEMO : UC_ETRANZACT_SERVICE; $apiurl = sprintf(%s?%s, $apiurl, $query); curl_setopt($curl, CURLOPT_URL, $apiurl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($curl); // drupal_http_request $result = drupal_http_request($uri, $header, $method, http_build_query($data, , &));
  • 7. Test with SimpleTest • When your project is starting to get robust and clumsy, test with SimpleTest • Common SimpleTest APIs are: – drupalGetNodeByTitle($title) – drupalCreateNode($settings) – drupalCreateContentType($settings) - drupalCreateUser($permissions) – checkPermissions(array $permissions, $reset = FALSE): Check to make sure that the array of permissions are valid. – drupalLogin(stdClass $user): Log in a user with the internal browser.
  • 8. Test with SimpleTest – drupalLogout – assertNotEqual: Check to see if two values are not equal. – assertEqual: Check to see if two values are equal. – drupalPost: Execute a POST request on a Drupal page. – drupalGet: Retrieves a Drupal path or an absolute path. – assertTrue: Check to see if a value is not false (not an empty string, 0, NULL, or FALSE) – assertFalse: Check to see if a value is false (an empty string, 0, NULL, or FALSE). – assertNull: Check to see if a value is not NULL.
  • 9. Administer Drupal faster with Drupal • Drush is Drupal’s CLI language • Administer modules quickly with Drush • When working with multi-sites, Drush is your best friend • Drupal cheat sheet – Drush status – Drush dl <modulename> – Drush cc – Drush eval “<php code>” – Drush en <module name> – Drush dis <module name> – Drush up – Drush upc <module name> – … more on drupal.org
  • 10. Debugging Drupal• The devel module and theme developer modules are very handy tools for Debugging Drupal.• There’s also a firebug Drupal extension for debugging Drupal• Useful functions: – Dsm – Dpr – dvm
  • 11. Ubercart Payment Hooks and useful APIs• Hook_payment_method: define a custom payment method• Hook_order: define and process the order items• Hook_checkout_pane: define a custom pane for your order and style it• uc_order_status_data: Check the status of an order• uc_cart_empty(uc_cart_get_id()): Empty a cart• uc_order_save($order): save an order to the database• Hook_tapir_table_alter• Hook_cart_item: alter the items in cart• Hook_cart_pane: Override the cart pane• Hook_product_description: modify the descriptions of items in cart• Uc_cart_get_contents: get cart contents
  • 12. Understanding ubercart cart process • Add items to cart using uc_cart_add_items. • Checkout your order and implement hook_checkout_pane to customize the order items. • Review the order in different states namely: – New: only called if the order is new – Submit: Process the order such as integrating with a payment gateway like etranzact. – Save: Save your order in a database – Load: called immediately an order is successfully saved in the db
  • 13. How we build it: uc_etranzact module • Uc_etranzact module only requires a payment gateway implementation • Ubercart Hooks that got the job done: – Hook_payment_gateway – Hook_order – Callback functions to process the order to integrate with etranzact system
  • 14. Questions • Website - http://opevel.com • Twitter : @opevel @drupal @acquia • Opevel Services – Drupal custom development – Drupal site architecture – Custom Application Development on Google App Engine http://drupal.org/sandbox/charyorde/1310706 • Datasphir is hiring Drupal developers. – http://datasphir.com