passing parms to called program

Questions and answers about ShopSite Custom Templates

passing parms to called program

Postby FredW » Wed Jun 26, 2013 1:29 pm

Hi Folks,

I have been working on a custom template to call a php program when the ProductField2 contains some data. I want to pass the SKU to this php program.

I have been successful with everything but passing it the SKU. It appears that the parameter is either not passed or I have some syntax error causing my php program to get a null value.

Here is the code in my template:
[-- IF PRODUCT.Field2 --]
<p>
<b>[-- STORE.ProductField2 --]:</b> [-- PRODUCT.Field2 --]</p>
[-- CALL fw-xref.php(q="PRODUCT.Sku") --]
[-- END_IF --]

My Php program uses the parameter (SKU) to look up data in a SQL database. It worked successfully outside of ShopSite, but based on some diagnostic messages, appears to be getting nothing passed.
Here is what it is printing out:
Connection was OK!

looking up

var sql is = SELECT * FROM `xref` WHERE `SKU` =

query error:


Can you offer any suggestions?
Thanks in advance.
Fred
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm

Re: passing parms to called program

Postby loren_d_c » Wed Jun 26, 2013 1:43 pm

That looks like the incorrect syntax for the CALL tag. See:

http://www.shopsite.com/help/11.2/en-US/sc/pro/custom.template.spec-global.html

So try the tag like this:

Code: Select all
[-- CALL fw-xref.php(PRODUCT.Sku) --]


-Loren
loren_d_c
 
Posts: 2569
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Re: passing parms to called program

Postby FredW » Wed Jun 26, 2013 2:03 pm

loren_d_c wrote:That looks like the incorrect syntax for the CALL tag. See:

http://www.shopsite.com/help/11.2/en-US/sc/pro/custom.template.spec-global.html

So try the tag like this:

Code: Select all
[-- CALL fw-xref.php(PRODUCT.Sku) --]


-Loren

Thanks Loren,
I actually went to that page and tried what you suggested before I posted this post. I just tried it again and am getting the same results.
Template code is now:
-- IF PRODUCT.Field2 --]
<p>
<b>[-- STORE.ProductField2 --]:</b> [-- PRODUCT.Field2 --]</p>
[-- CALL fw-xref.php(PRODUCT.Sku) --]
[-- END_IF --]

I changed my PHP code to print the parameter as soon as it gets it:

---- authentication code remove ----

$q=$_GET["q"];
print "passed from ShopSite:";
print $q;

$con = mysqli_connect('localhost','fred','sqlKSS060812','manuspec');
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else { echo "Connection was OK!\n";}
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm

Re: passing parms to called program

Postby FredW » Wed Jun 26, 2013 2:05 pm

Sorry, here is the results I get:

Home>Denver Page>DB-xref
83-255.jpg

DB-xref
Write Your Own Review | No reviews for this product.

Text from this filed is placed on the More information page

The following is a test to see how ShopSite indexes html:

xyzzyx

This contents is indexed: parthvac
SKU: db-xref

$8.88
Quantity:

Weight: 8.88 lbs
Specifications provided by manufacturer on manufacturer's website

Product Field 2:


passed from ShopSite:Connection was OK!

looking up

var sql is = SELECT * FROM `xref` WHERE `SKU` =

query error:
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm

Re: passing parms to called program

Postby loren_d_c » Wed Jun 26, 2013 2:19 pm

Maybe you need a space after the script name and before the parameter, like this:

Code: Select all
[-- CALL fw-xref.php (PRODUCT.Sku) --]


But it more likely has to do with how your PHP script is (or rather, is not) handling the commandline parameters. You may need to use $argv[0] or $argv[1], see the PHP documentation page at:

http://php.net/manual/en/reserved.variables.argv.php

-Loren
loren_d_c
 
Posts: 2569
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Re: passing parms to called program

Postby FredW » Wed Jun 26, 2013 2:31 pm

Thanks Loren, but a blank before the (PRODUCT... does not help.

I'll look at the link you gave me, but my php program worked fine invoked from a browser window passing the parameter. Are you saying that invoking it from ShopSite is different from that?

Fred
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm

Re: passing parms to called program

Postby loren_d_c » Wed Jun 26, 2013 2:41 pm

Are you saying that invoking it from ShopSite is different from that?


Yes, very. It is called as a commandline script with commandline parameters, not like it would if executed via the URL in a browser.

-Loren
loren_d_c
 
Posts: 2569
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Re: passing parms to called program

Postby loren_d_c » Wed Jun 26, 2013 2:50 pm

If you want it to execute in the browser (i.e. the PHP code executes each time the page loads in a browser), then just name your ShopSite pages or More Info Pages with .php file extensions, then just add the PHP code directly into your product template like:

Code: Select all
<?php
$q="[-- PRODUCT.SKU --]";

{the rest of your PHP code, or call to an external PHP function, here}

?>


But as long as you have your script in a CALL tag, it is only being executed at the time of the Publish and the cgi that is running the publish (generate.cgi) is executing it as a commandline script.

-Loren
loren_d_c
 
Posts: 2569
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Re: passing parms to called program

Postby FredW » Thu Jun 27, 2013 4:27 am

Hi Loren,

We want the call to the program during publish time.

I have tested my php program and have it running as a command line. For testing, I have tested the program by passing a constant 'testing' and the var_dump(&argv) prints it correctly.

But the issue appears to be I can't pass the variable PRODCUT.SKU, when I try it passes: "db-xref" . I don't know where that is coming from?

There may be another clue that my program is no outputting any data but the print of the variables passed.

The next statements may be failing and I can't figure out how to find out if an error message is being generated:
print "ver 1.40
<p>";
var_dump($argv);
$q = $argv(1);

print "passed from ShopSite:";
print $q;

$con = mysqli_connect('localhost','fred','sqlKSS060812','manuspec');
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else { echo "Connection was OK!\n";}
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm

Re: passing parms to called program

Postby FredW » Thu Jun 27, 2013 9:17 am

Just to let you know, that I got it to work.

Thanks for your help.
Fred
FredW
 
Posts: 188
Joined: Mon Apr 02, 2012 2:07 pm


Return to Custom Template Questions

Who is online

Users browsing this forum: Google [Bot] and 14 guests

cron