Save data collected from multiple pages in one session w/ kirby

Noob question: how do you collect informations from multiple pages in one session without make a user login to the site?

Something javascript does or can php do it? It’s for populating a checkout order.

I might use Shopkit for that if the site I’m working on handles the whole payment process, but it’s still not clear so I thought I’d try to keep it basic for now…

(a forum search did not bring up anything relevant, and it might be because of my terminology probably)

You can check the shop kit code for saving items to the session:

Yes, thank you. Say I wanna things pretty simple for now:

I’m on the product page, I click the buy button, which directs me to a checkout page to process the order.

Do I need also in this case to save the session somewhere or can I somehow fetch the content from the page where I clicked the buy button?

You can send the page information in a data attribute you read via JS, without saving in the session, but if you want to store multiple items in a cart, that doesn’t make sense.

Yes you are right.

I only need a very simple example for now, simply click on a product page and place the order based on the informations fetched from that page. Later on I’d need to store multiple items though.

I think I’ll peek at how shopkit does that for now. I thought it was only a plugin, but realised it’s a full on website, which is not what I need.

Thank you!

Why don’t you have a look at Cartkit? It’s way more basic and easier to understand for the beginning, I think?

The logic in plugins/cart/cart.php is basically the same as in an old Kirby 1 theme and described here: Commerce Plugin - interest?

(Original post here:

Thanks for this, it looks more fitting for what I need to do. I’ll go through it and will report back.

In the example all the products are in one page, in my case each product has its own page, and a user is expected to visit a specific page to add a product to the list.

Does the session function works across pages? It should right? From what I understand the session function keeps working until you press the checkout button.

That is why sessions exist, actually. They exist until the session is destroyed.

By comparing cartkit with the plugin code from 2013 you shared, the main difference I saw is that in cartkit at every new function $cart = s::get('cart', array()); is called.

Which makes me think it’s because in case you open a new product page and want to keep up to date with the session’s data?

yes, but if you look closely, it’s all the same, the old version of cart_logic() expects an argument and gets the session data passed via this argument.

Been following through Cartkit and it’s been very useful so far.

I have one question at this point: in order to send the order to the service provider which processes it, I need to make an API call like so:

  require_once 'vendor/autoload.php';
  use \GingerPayments\Payment\Ginger;

  $price_i = $product->price();
  $price_o = preg_replace('/\./i','', $price_i);

  $client = Ginger::createClient('');
  $order = $client->createIdealOrder(
    $price_o, // The amount in cents
    'EUR',    // The currency

I tested the code on a simple page and the connection works well. How do I bind this action to a button now?

Should I make a checkout page? So when you click on Buy, you are being redirected to checkout.php which fires the above code?

@afincato Just to throw something out there incase you hit a wall trying to make this work, I have had great success with Snipcart, which can very easily be added to a Kirby site. It adds a shopping cart that can be customised easily via your own CSS. It’s javascript based and product information is fed to it via simple data attributes on buttons, and works well with a number of popular payment gateways (not totally sure GingerPayments is one of them). They even put together a getting started guide on adding it to Kirby.

OK, that’s where this code is living right now.

Can you elaborate a bit more on building helpers?

Sorry, no, because I don’t even know if that is necessary. I don’t know their API and looking into this would go far beyond Kirby support, I’m afraid.

I think a controller does a good job (: