Search

I'm using the Members and Shopping Cart extensions in Symphony 2.2.5, which is working fine. I now need to save customer orders in my Orders section.

I've set up an Orders section with appropriate fields, and made an event.

I've been advised that the cleaner way of collecting data in an event is by reading it directly from the session and not via $_POST and hidden form elements. I think I get why: it removes the possibility of the customer changing the customer ID, for example, as well as simply removing the need for more markup. I think it also provides me with a chance to try to understand events, and I need to do some custom combining of data anyway.

event.save_order.php (cropped):

protected function __trigger(){

    echo "<pre>";print_r($_SESSION);echo "</pre>";
    die;

    include(TOOLKIT . '/events/event.section.php');
    return $result;

}

$_SESSION data:

Array
(
     [sym-] => Array
         (
             [username] => davido
             [pass] => 10b97...
         )

     [category] => desktop
     [] => Array
         (
             [id] => 4917
             [email] => customer1@domain
             [password] => 37f77...
         )

     [sym-cart] => Array
         (
             [1920] => Array
                 (
                     [num] => 1
                     [sum] => 22
                 )

             [2299] => Array
                 (
                     [num] => 5
                     [sum] => 17.8
                 )

         )

)

So the customer (member) ID (4917 in this case) and the item IDs, quantities and prices are all available in the $_SESSION data for me to grab and save into the Orders section as an entry.

I think one of my problems is that I don't know how my PHP which will iterate through the $_SESSION data should relate to what is already set up in the default event. If I allow Symphony's event.section.php to be included, I think this will result in Symphony trying to do its own saving (which won't work because I don't have the form fields present).

If I don't allow event.section.php to be included, I don't think I'll get any $result XML data returned to the frontend, and I think I may then be responsible for all of the entry saving by using Symphony's API (e.g. Entry).

As you can tell, I'm a bit lost as to how to start.

A second requirement is accessing the XML from this event as I need to grab the items' names so that they can be concatenated to the text before being saved in the Orders section. I hope this is possible?

Any pointers/examples of similar events appreciated. Thanks.

If I allow Symphony's event.section.php to be included, I think this will result in Symphony trying to do its own saving (which won't work because I don't have the form fields present).

Not 100% sure about this, but I guess the easiest way would be to just map your session data to the default $_POST-structure, so the section event can handle everything else for you.

Any advice from more experienced extension developers? I'm always curious about some best practices for stuff like this.

Jens, thanks. I've now got data saving into the Orders section. Hoorah!

That just leaves the adding of the related data (like item name) as text. How do I access data source XML output in my custom event?

David - DataSources always run after events. So I don't really think you can access DS data from events.

DataSources always run after events. So I don't really think you can access DS data from events.

True.

Thanks chaps. SymQL seems to work fine when used in an event, so I can access the data using that.

In case it's useful for anyone else, my event will end up being something like:

protected function __trigger(){
    require_once(EXTENSIONS . '/symql/lib/class.symql.php');
    $query = new SymQLQuery();
    $query->select('*');
    $query->from('instances');
    foreach ($_SESSION['sym-cart'] as $key => $item) {
        $query->where('system:id', $key);
    }
    $result = SymQL::run($query);

    // $_SESSION to $_POST mapping with addition of data from SymQL result here

    include(TOOLKIT . '/events/event.section.php');
    return $result;
}

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details