Forums / General Questions / Designing a mod that uses an API to send info offsite

Designing a mod that uses an API to send info offsite

Views: 967

Results 1 to 10 of 10
9 Sep 2013, 7:13 PM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Designing a mod that uses an API to send info offsite

This API requires a few things sent off - very few things such as customer first and last names, email and the product modules from the order that are in a specific category.

I started working on just a query and insertion in the checkout success page and have just had a conversation with someone who suggested a different approach which makes more sense.

So somewhere in the process - possibly as part of the order creation process - the information will be pulled from the order and stored in a new database table. I want the info sent off automatically at the end of each order that contains those products from a specific category.

So the question is - how can I do this without mangling a number of core files? The order is created in the order classes file, I believe. Is this new table insertion going to have to be done in the class file? Is there any other way to do it?

Should I tie the API send to checkout success - like in the header or should I do it earlier in case the order gets created and something goes wrong and the customer never gets to the success page (for various and sundry bizarre reasons)?

Any suggestions would be appreciated!

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

9 Sep 2013, 7:45 PM
#2
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Designing a mod that uses an API to send info offsite

in modules/checkout_process
the code after

// store the product info to the order
will I believe give you the meat you are looking for!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

9 Sep 2013, 8:55 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Designing a mod that uses an API to send info offsite

thank you sir!!!!

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

30 Sep 2013, 6:29 PM
#4
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Designing a mod that uses an API to send info offsite

Well, I've run into a problem. After getting the code working separately, I'm finally trying to integrate this into the check_out process.

it's not happy. get an error message: Call to undefined method order::createSendMURPHY()

So I'm thinking it only allows payment or order total methods in here and not an additional function like I have created.

Any other ideas?

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

1 Oct 2013, 2:39 AM
#5
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Designing a mod that uses an API to send info offsite

There are a handful of notifies during the checkout process... You may be able too just hook into one of these with an observer which then runs your code...

I've used these in the past with success... For example to record live shipping request/responses for completed orders (useful for testing, saving the estimate REF#, saving user selected shipping options such as insurance, etc).

This also avoids the need to edit core files in most cases.

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

1 Oct 2013, 4:03 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: Designing a mod that uses an API to send info offsite

Delia, if you get a message that says undefined method order::createSendMURPHY()
It means you are trying to call $this->createSendMURPHY() on an order object. Just call it as a regular method

createSendMURPHY();

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

1 Oct 2013, 5:13 PM
#7
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Designing a mod that uses an API to send info offsite

Thanks to both of you.

I see the advantage of using observers - and not editing core files but by the time y'all had responded I started a different path (one that I wasn't really wanting to visit). So three sets of code later...

If doing it either as an additional observer class or inside the checkout process, the stumbling block is how to pull the order id for my use. In checkout process it's the $insert_id. I can't seem to pull that for my use from checkout process.

I changed the line in checkout process to createSendMURPHY($insert_id);

and changed the function to: function createSendMURPHY($order_id)

But that does not pick up the $insert_id during the process. I do have the $order_id as a global.

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

1 Oct 2013, 5:36 PM
#8
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Designing a mod that uses an API to send info offsite

Oversimplified Example ("/includes/classes/observers/dosometingafterorder.php"). This will be triggered by checkout_process or PayPal IPN when an order is successfully added to the database:

class DoSomethingAfterOrder extends base {

	function __construct() {
		global $zco_notifier;
		$zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS'));
	}

	function update(&$class, $eventID, $paramsArray = array()) {
		global $db;
		$order_id = $_SESSION['order_number_created']; // May also be available in $GLOBALS['insert_id'];

		// Do something with the order id and / or database
	}
}

And the simplified autoloader file ("/includes/auto_loaders/config.dosometingafterorder.php":

$autoLoadConfig[10][] = array('autoType'=>'class',
  'loadFile'=>'observers/dosometingafterorder.php' // File where the class is located
);

// 80 is where the shopping cart is established for the session
// 110 is where the language components are established for the session
$autoLoadConfig[115][] = array('autoType'=>'classInstantiate',
  'className'=>'do_something_after_order', // Variable name accessible by in other files
  'objectName'=>'DoSomethingAfterOrder' // Name of the class
);

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

1 Oct 2013, 5:39 PM
#9
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Designing a mod that uses an API to send info offsite

Yeah, I was looking at the products viewed observer class. Looks simple - deceptively so!

The full-time Zen Cart Guru. WizTech4ZC.com
New template for 2.0 viewable here: 2.0 Demo

1 Oct 2013, 5:48 PM
#10
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Designing a mod that uses an API to send info offsite

lhungil:

...

// 80 is where the shopping cart is established for the session
// 110 is where the language components are established for the session
$autoLoadConfig[115][] = array('autoType'=>'classInstantiate',
'className'=>'do_something_after_order', // Variable name accessible by in other files
'objectName'=>'DoSomethingAfterOrder' // Name of the class
);

Should be:

// 80 is where the shopping cart is established for the session
// 110 is where the language components are established for the session
$autoLoadConfig[115][] = array('autoType'=>'classInstantiate',
'className'=>'DoSomethingAfterOrder', // Name of the class
'objectName'=>'do_something_after_order' // Variable name accessible by in other files
);


What I would not give for extended editing period when on a mobile phone (the scripts active when typing in this box seem to cause my mobile browser to crawl).

The glass is not half full. The glass is not half empty. The glass is simply too big!
Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker