Definition

hook_productapi(&$node, $op, $arg3 = NULL, $arg4 = NULL)
ecommerce-4-7/docs/developer/hooks/core.php, line 210

Description

Add a product

The

Parameters

&$node The node object for the product.

$op What kind of action is being performed. Possible values:

  • "wizard_select":
  • "cart add item": called when trying to add a product to a shopping cart. This allows the product to limit the addition of items. This is optional as a null return will be treated as true and the item will be added.
  • "attributes":
  • "adjust_price": called to provide a price adjustment to the product. No changes to node->price should be made.
  • "transaction": I can only guess. the only place I see this is coupon.module
  • "on payment completion": called on payment completion
  • "subproduct_types": called by subproduct to get a list of supported subproducts
$arg3 The "adjust_price" operation passes a current price here. Possible values for attributes operation:
  • "in_stock"
$arg4

Return value

This value varies depending on the operation.

  • The "wizard_select" operation should return an array of product types provided by the module. The key should uniquely identify the type and the value should be a translated description.
  • The "cart add item" operation should return a bool value. True or NULL will add to cart and false will redirect. You must provide you own drupal_set_message failure message.
  • The "ajust_price" operation returns a new price.
  • The 'insert'

Code

<?php
function hook_productapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {

  switch($op) {
    case 'wizard_select':
      return array('coupon' => t('Gift Certificate'));

    case 'cart add item':
      break;

    case 'attributes':
      return array('in_stock', 'no_quantity', 'no_discounts');

    case 'transaction':
      break;

    case 'adjust_prices':
      if (!((float)$node->price)) {
        return $node->gc_price;
      }
      break;
    case 'subproduct_types':
      return array('sandwich');
    case 'fields':
      break;

    case 'validate':
      break;

    case 'load':
      break;

    case 'insert':
      break;

    case 'update':
      break;

    case 'delete':
      break;
  }
}
?>