Checkout Module

Foggy75

Joined: 2008-12-26
Posts: 14
Posted: Fri, 2009-10-16 02:52

Hi wondering if someone can help me ! Please Etc.Etc (o:

What im trying to do is modify the Checkout module so when an order is "complete" it connects to my home PC/Server to get the "original" raw file to email to the checkedout customer.

The ways I have tried to approach this is running a PHP script to check the fields in the database and if completed it then constructs the email.

My other thought was to just trigger the event on receipt of the notification email.

Has anyone any ideas on how to approach this Theory and practice welcome (o:

I will buy pizza for the best answer and a crate of beer if somebody shows me the light.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-10-16 09:41

This is actually pretty trivial, if you are competent with php and also know the Gallery2 API (worth learning, if you don't, imo):

All you need to do is....

1. Write a module that....
2. ... registers an Event Listener for the GalleryCheckout::transactionChange Event which ...
3. ... when triggered, checks the relevant Event's Data field, which holds an array which should contain a 'type' field which contains the value 'clear' - indicating payment cleared, and then looks in ...
4. ... the Event's Entity field which holds the TransactionEntity, from which you can get the relevant details of the order.

The code that posts the event is in GalleryCheckoutApi.class, I can't find the line number but it's in function changeTransactionStatus(), and you can see an example where changeTransactionStatus(...) is called in checkoutPaypal's IPN.inc in this bit of code which sets the Transaction status to "clear" if the incoming IPN indicates a payment has been made:

  /* Check the payment_status */
	    switch ($IPNpost[2]) {
	    case 'Completed':
	   	$ret = GalleryCheckoutApi::changeTransactionStatus($transaction, 'clear');
		if ($ret) {
	    	    return $ret;
		}

Enjoy!

Oh, I don't drink beer, but a bottle of a decent vintage Port is always welcome.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-10-16 09:52

Somewhere in the Forum I wrote an entire module that was only 10 lines long I think, you could probably do the rest of what you want in another 10. There's your challenge - 20 lines of php or less.

 
Foggy75

Joined: 2008-12-26
Posts: 14
Posted: Fri, 2009-10-16 11:14

Hi Alec,

Cheers for that mate im trying to hack my way round with limited knowledge (o:

You got the location of the 10 lines of code you have actually done and ill try to get the rest done.

Pm me your paypal id (o:

Cheers mate

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-10-16 11:49

You want something like this, in a file called module.inc in a folder called (eg) 'checkoutfetchoriginals'

<?php 
class CheckoutFetchOriginalsModule extends GalleryModule {
    function CheckoutFetchOriginalsModule() {
	$this->setId('checkoutfetchoriginals');
	$this->setName('checkoutfetchoriginals');
	$this->setDescription('Collect original files after payment cleared');
	$this->setVersion('0.1.0');
	$this->setCallbacks('registerEventListeners');
	$this->setRequiredCoreApi(array(7, 4));
	$this->setRequiredModuleApi(array(3, 0));
    }

    /**
     * @see GalleryModule::registerEventListeners()
     */
    function registerEventListeners() {
	$myListener = new CheckoutFetchOriginalsModule();
        GalleryCoreApi::registerEventListener('GalleryCheckout::transactionChange', $myListener);


  /**
     * Event handler for GalleryCheckout::transactionChange events
     *
     * @see GalleryEventListener::handleEvent
     */
    function handleEvent($event) {
    $result = null;
    if ($event->getEventName() == 'GalleryCheckout::transactionChange') {
        $eventData = $event->getData();
	$entity = $event->getEntity();
        if ($eventData['type'] == 'clear') {
            /**
                 here: sanity-check that entity is a GalleryCheckoutTransaction
                 then: do stuff with it, like get the image numbers, fetch files, email them etc etc
                 optionally: set a result code (research G2 Event handling to see what they do
            **/
	}
    }
    return array(null, $result);
}

?>

Notes:

1 - I haven't checked this for typos, missing braces etc
2 - I haven't actually checked that it works, at all, but this is the general idea
3 - This is the 'old' (deprecated) method of installing Event Handlers, but since there's not going to be a Gallery 2.4 ever, it doesn't matter much
4 - It's slightly over 20 lines

 
Foggy75

Joined: 2008-12-26
Posts: 14
Posted: Fri, 2009-10-16 12:16

Cheers let see if i can get it done thanks for your time alec

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-10-16 12:43

I put all that event stuff in checkout precisely to make it easy to do the kind of stuff you want to do. It would be nice to see someone make use of it!

Apart from me that is - obviously: every time I get an order, my server farm uses this mechanism automatically to transfer files to the drop folder that feeds into my array of Fuji Frontiers to print the pictures. In my dreams.