You are here

function uc_usps_ca_predicate in Ubercart 6.2

Implements hook_ca_predicate().

Connect USPS quote action and event.

File

shipping/uc_usps/uc_usps.module, line 115
Shipping quote method module that receives quotes from the United States Postal Service via XML web service.

Code

function uc_usps_ca_predicate() {
  $enabled = variable_get('uc_quote_enabled', array());
  $quote_action = array(
    '#name' => 'uc_quote_action_get_quote',
    '#title' => t('Fetch a shipping quote'),
    '#argument_map' => array(
      'order' => 'order',
      'method' => 'method',
    ),
  );

  // Domestic areas include U.S., American Samoa, Guam, Puerto Rico, and the Virgin Islands
  $countries = array(
    16,
    316,
    630,
    840,
    850,
  );
  $predicates = array(
    'uc_usps_get_quote' => array(
      '#title' => t('Shipping quote from USPS'),
      '#trigger' => 'get_quote_from_usps',
      '#class' => 'uc_usps',
      '#status' => $enabled['usps'],
      '#conditions' => array(
        '#operator' => 'AND',
        '#conditions' => array(
          array(
            '#name' => 'uc_order_condition_delivery_country',
            '#title' => t('Is in domestic US areas (US, AS, GU, PR, VI)'),
            '#argument_map' => array(
              'order' => 'order',
            ),
            '#settings' => array(
              'countries' => $countries,
            ),
          ),
        ),
      ),
      '#actions' => array(
        $quote_action,
      ),
    ),
    'uc_usps_get_env_quote' => array(
      '#title' => t('Shipping quote from USPS'),
      '#trigger' => 'get_quote_from_usps_env',
      '#class' => 'uc_usps',
      '#status' => $enabled['usps_env'],
      '#conditions' => array(
        '#operator' => 'AND',
        '#conditions' => array(
          array(
            '#name' => 'uc_order_condition_delivery_country',
            '#title' => t('Is in domestic US areas (US, AS, GU, PR, VI)'),
            '#argument_map' => array(
              'order' => 'order',
            ),
            '#settings' => array(
              'countries' => $countries,
            ),
          ),
        ),
      ),
      '#actions' => array(
        $quote_action,
      ),
    ),
    'uc_usps_get_intl_quote' => array(
      '#title' => t('Shipping quote from USPS Intl.'),
      '#trigger' => 'get_quote_from_usps_intl',
      '#class' => 'uc_usps',
      '#status' => $enabled['usps_intl'],
      '#conditions' => array(
        '#operator' => 'AND',
        '#conditions' => array(
          array(
            '#name' => 'uc_order_condition_delivery_country',
            '#title' => t('Is not in domestic US areas (US, AS, GU, PR, VI)'),
            '#argument_map' => array(
              'order' => 'order',
            ),
            '#settings' => array(
              'negate' => TRUE,
              'countries' => $countries,
            ),
          ),
        ),
      ),
      '#actions' => array(
        $quote_action,
      ),
    ),
    'uc_usps_get_intl_env_quote' => array(
      '#title' => t('Shipping quote from USPS Intl.'),
      '#trigger' => 'get_quote_from_usps_intl_env',
      '#class' => 'uc_usps',
      '#status' => $enabled['usps_intl_env'],
      '#conditions' => array(
        '#operator' => 'AND',
        '#conditions' => array(
          array(
            '#name' => 'uc_order_condition_delivery_country',
            '#title' => t('Is not in domestic US areas (US, AS, GU, PR, VI)'),
            '#argument_map' => array(
              'order' => 'order',
            ),
            '#settings' => array(
              'negate' => TRUE,
              'countries' => $countries,
            ),
          ),
        ),
      ),
      '#actions' => array(
        $quote_action,
      ),
    ),
  );
  return $predicates;
}