home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (uc_cart_links.module)

This example Drupal source code file (uc_cart_links.module) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

access, arguments, array, cart, cart_link, directory, file, function, links, option, page, php, title, type

The uc_cart_links.module Drupal example source code

<?php
// $Id: uc_cart_links.module,v 1.2.2.8 2010/02/12 15:23:42 islandusurper Exp $

/**
 * @file
 * Allows store owners to create links to add products to carts and send
 * customers on to checkout.
 *
 * Development sponsored by the Ubercart project.  http://www.ubercart.org
 */


/*******************************************************************************
 * Hook Functions (Drupal)
 ******************************************************************************/

/**
 * Implementation of hook_menu().
 */
function uc_cart_links_menu() {
  $items['admin/store/settings/cart_links'] = array(
    'title' => 'Cart links settings',
    'description' => 'Configure and craft special product add to cart links.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('uc_cart_links_settings_form'),
    'access arguments' => array('administer cart links'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'uc_cart_links.admin.inc',
  );
  $items['admin/store/reports/cart_links'] = array(
    'title' => 'Cart links clicks',
    'description' => 'Track clicks through cart links.',
    'page callback' => 'uc_cart_links_report',
    'access arguments' => array('view cart links report'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'uc_cart_links.admin.inc',
  );
  $items['admin/store/help/cart_links'] = array(
    'title' => 'Creating cart links',
    'description' => 'Learn how to create cart links for your products.',
    'page callback' => 'uc_cart_links_creation_help',
    'access arguments' => array('administer store'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'uc_cart_links.admin.inc',
  );
  $items['cart/add/%'] = array(
    'title' => 'Add to cart',
    'page callback' => 'uc_cart_links_process',
    'page arguments' => array(2),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    'file' => 'uc_cart_links.pages.inc',
  );

  return $items;
}

/**
 * Implementation of hook_perm().
 */
function uc_cart_links_perm() {
  return array('administer cart links', 'view cart links report');
}

/**
 * Implementation of hook_add_to_cart().
 */
function uc_cart_links_add_to_cart($nid, $qty, $data) {
  if (user_access('administer cart links') &&
      variable_get('uc_cart_links_add_show', FALSE)) {
    $cart_link = 'p'. $nid .'_q'. $qty;
    if (!empty($data['attributes'])) {
      foreach ($data['attributes'] as $attribute => $option) {
        if (is_array($option)) {
          // Checkbox options are stored in an array
          foreach ($option as $oid => $ovalue) {
            if ($ovalue != 0) {
              $cart_link .= '_a'. $attribute .'o'. $oid;
            }
          }
        }
        else {
          // Textfield, Select, or Radio options
          $cart_link .= '_a'. $attribute .'o'. $option;
        }
      }
    }
    drupal_set_message(t('Cart link product action: @cart_link', array('@cart_link' => $cart_link)));
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal uc_cart_links.module source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.