Name

External — enable dump of selected global and catalog values for use by external programs

SYNOPSIS

No | Yes

DESCRIPTION

The directive enables dump of selected global and catalog information for use by external programs, possibly written in languages such as PHP, Python or Ruby.

Dump file format is a direct Perl memory dump, internally most often produced by invoking Perl's Storable methods.

The dump takes place at time of catalog (re)configuration.

Global External must be enabled first to allow individual catalogs to use External themselves and dump their information.

DIRECTIVE TYPE AND DEFAULT VALUE

Global directive,
Catalog directive

EXAMPLES

Example: Defining External

Put the following in both global interchange.cfg and the specific catalog.cfgs:

External yes

Example: PHP connector for accessing the structure file

<?php

$interchange_base = '/usr/lib/interchange';
$interchange_lib = "$interchange_base/lib";
$interchange_struct = "/var/run/interchange/external.structure";

putenv("PERL_SIGNALS=unsafe");
umask(7);

$perl = new Perl();

$perlstring = "
  use lib '$interchange_lib';
  \$ENV{EXT_INTERCHANGE_FILE} = '$interchange_struct';
  \$ENV{EXT_INTERCHANGE_DIR} = '$interchange_base';
";
$perl->eval($perlstring);
$perl->require("Vend/External.pm");

$origsid = $sid = $_COOKIE["MV_SESSION_ID"];

if(! $sid) {
	$_REQUEST["mv_session_id"];
}
$cat = 'standard';
$catback = $perl->catalog($cat);

$out = "sid=$sid<br>";
$out .= "parm is debug=" . $_REQUEST["debug"] . "<br>";
$out .= "catalog is $catback<br>";
$out .= "now sid=$sid<br>";
$remote = $_SERVER['REMOTE_ADDR'];

$perl->remote_addr($remote);
$new = $perl->session($sid);

if($new) {
	$sid = $perl->session_name();
	$out .= "new session, now sid=$sid<br>";
}

if($sid != $origsid) {
	setcookie('MV_SESSION_ID', $sid, 0 , '/');
}

## Can print now that cookie is set
print $out;

$fname =  $perl->value("values","fname");
$lname =  $perl->value("values","lname");
print "Well what do you know, we have a '$fname $lname'!<br>";
$cart = $perl->value('carts', 'main');
$nitems = count($cart);
if($nitems) {
	print "We have a cart with $nitems items</br>";
	for($i = 0; $i < $nitems; $i++) {
		$code = $cart[$i]["code"];
		$quantity = $cart[$i]["quantity"];
		print "Item $code is in cart, quantity $quantity.<br>";
	}
}
?>

NOTES

For discussion and examples of connecting Interchange to external programs, see glossary entry external.

AVAILABILITY

External is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: lib/Vend/Config.pm
Line 518

['External',     'yesno',          'No'],

Source: lib/Vend/Config.pm
Line 712

['External',     'yesno',          'No'],

Source: lib/Vend/Config.pm
Line 5414 (context shows lines 5414-5426)

sub parse_yesno {
my($var, $value) = @_;
$_ = $value;
if (m/^y/i || m/^t/i || m/^1/ || m/^on/i) {
  return 1;
}
elsif (m/^n/i || m/^f/i || m/^0/ || m/^of/i) {
  return 0;
}
else {
  config_error("Use 'yes' or 'no' for the $var directive\n");
}
}

AUTHORS

Mike Heins

SEE ALSO

ExternalFile(7ic), ExternalExport(7ic)

DocBook! Interchange!