Commerce Plugin - interest?

So… is this project dead already?

LOL, no. But I have a 40/hour/week work schedule and little opportunity to develop a project that doesn’t provide immediate income. But as of next week I’m opening some time up in my week to dedicate to Kart. Stuff will start happening soon … but probably slowly.

I didn’t ment to be pushy, thanks for your answer :slight_smile:

Hey, I’d like to help out on this if you need another dev on this. I’ve got pretty much every day open to dev

Thanks for the note @tnViking. I’m going to actually start to do something with Kart in a few weeks, I’ll contact you when I’m ready to get some work done.

This just in: The new Perch Shop
From what I’ve read in this topic, the approach is similar. Not creating a whole shop with Kirby, but creating a bridge with commerce platforms.

@max brought moltin to my attention. Another strong option.

Edit: then I looked at what Perch Shop uses…

1 Like

As much as I don’t want to admit that the project is truly dead, I think I’m indeed going to have to put the Kart on permanent hiatus. I’ve just got too many other things going on right now to manage or contribute to the development, and it sounds like there are some great alternatives. Moltin and Perch look like the options I would personally pick.

There would still be some major advantages to having a shopping cart integrated directly with Kirby, so maybe soon I can get a client to pay for my hours while I work. :slight_smile: But for now, it’s sadly just not financially practical for me. I thank everyone for their input so far though, especially @distantnative and @BenSeitz, your insights have been incredible valuable.

I too have been looking for this code, which was published in the old forum, as I was thinking it could at least serve as a good starting point for a project I’ve been asked to do, which means implementing Paypal in some fashion. I’ve read Paypal documentation until my eyes seeped out of their sockets, leaving me with a feeling I know less and less the more I read (quite opposite my experience from implementing Stripe on another project).

For those that don’t remember, here is Kyle Beans shop: http://www.kylebean.co.uk/shop which is using Kirby (1?) and a simple Paypal cart. That is not a dummy site, so if you click through the purchase process you will actually purchase (some of Kyle Beans amazing) products.

Kyle’s solution involved a plugin and templates that worked together… I have the plugin file knocking around here: https://gist.github.com/samnabi/bc6d95beffb9be6c82d7

But I can’t find the original templates unfortunately. I may or may not have some work-in-progress files of my own, but that code isn’t ready to share just yet…

1 Like

Since the post is no longer available online, I paste it here for reference, if anybody is interested, should be easy enough to update for Kirby 2:

Title: PayPal eCommerce store

When creating the new site for [kylebean.co.uk](http://kylebean.co.uk) I needed to create an online shop using Kirby.

# Explanation
This cart system builds a form for PayPal to receive and take payment. It uses `PHP sessions` to store products in an array called 'cart'. Each item in the array takes the UID for the product as it's key, and quantity as it's value.

# Plugin cart.php
My solution was to create a plugin called _cart_:
	<?php
	function get_cart() {
	    s::start();
	    $cart = s::get('cart', array());
	    return $cart;
	}
	
	function cart_logic($cart) {
	
	    if (isset($_REQUEST['action'])) {
	      $action = $_REQUEST['action'];
	      $id = $_REQUEST['id'];
	      switch ($action) {
	          case 'add':
	              if (isset($cart[$id])) {
	                  $cart[$id]++;
	              } else {
	                  $cart[$id] = 1;
	              }
	              break;
	          case 'update':
	              if (isset($_REQUEST['quantity'])) {
	                  $quantity = intval($_REQUEST['quantity']);
	                  if ($quantity < 1) {
	                      unset($cart[$id]);
	                  } else {
	                      $cart[$id] = $quantity;                
	                  }
	              }
	              break;
	          case 'delete':
	              if (isset($cart[$id])) {
	                  unset($cart[$id]);
	              }
	              break;
	      }
	      s::set('cart', $cart);
	    }
	    
	    if (count($cart) == 0) {
	    	go(url('shop'));        
	    }
	    
	    return $cart;
	}
	
	function cart_count($cart) {
	    $count = 0;
	    foreach ($cart as $id => $quantity) {
	        $count += $quantity;
	    }
	    return $count;
	}
	
	function cart_postage($total) {
	    $postage;
	    switch ($total) {
	        case ($total < 10):
	            $postage = 2.5;
	            break;
	        case ($total < 30):
	            $postage = 3.5;
	            break;
	        case ($total < 75):
	            $postage = 5.5;
	            break;
	        case ($total < 150):
	            $postage = 8;
	            break;
	        default:
	            $postage = 10;
	    }
	    return $postage;
	}

You should update the cart_postage function to reflect your own shipping rates.

Content

The plugin expects the following structure in content:

  • shop/shop.txt
  • shop/cart/cart.txt
  • shop/complete/complete.txt
  • shop/XX-product/product.txt

Within shop/cart/cart.txt, you should write the email used on PayPal to receive payments:

Email: email@address.com
----

shop.php template

The shop template will list all products and allow people to add them to the cart.

	<?php $cart = get_cart(); ?>
    <?php $count = cart_count($cart); ?>
    
   	<!-- header here -->
   	
    <?php if ($count > 0): ?>
        <p>You have <strong><?php echo $count ?> item<?php if ($count > 1) echo 's' ?></strong> in your cart.</p>
        <p><a href="<?php echo url('shop/cart') ?>">View your Cart and Pay</a></p>
    <?php endif ?>
    
    <?php $products = $page->children()->visible() ?>
    
    <?php foreach($products as $product): ?>
        <article>
            <h2><?php echo kirbytext($product->title(), false) ?></h2>
            <?php echo kirbytext($product->text()) ?>
            <form method="post" action="<?php echo url('shop/cart') ?>">
                <input type="hidden" name="action" value="add">
                <input type="hidden" name="id" value="<?php echo $product->uid() ?>">
                <p>£<?php echo $product->price() ?> <button type="submit">Add to Cart</button></p>
            </form>
        </article>
        
    <?php endforeach ?>
    
    <?php if ($count > 0): ?>
        <p class="align-right"><a class="button" href="<?php echo url('shop/cart') ?>" data-icon-after=" &rarr;">View your Cart and Pay</a></p>
    <?php endif ?>
    
   	<!-- footer here -->

cart.php template

The cart template is used to show products in the cart, as well as to make changes to them.

	<?php $cart = cart_logic(get_cart()) ?>
	<?php $products = $page->siblings()->visible() ?>
	
   	<!-- header here -->
	        
	<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
		<input type="hidden" name="cmd" value="_cart">
		<input type="hidden" name="upload" value="1">
		<input type="hidden" name="business" value="<?php echo $page->email() ?>">
	    <input type="hidden" name="currency_code" value="GBP">
	    
	    <table>
	        <thead>
	            <tr>
	            	<th>Product</th>
	            	<th>Quantity</th>
	            	<th>Price</th>
	            </tr>
	        </thead>
	        <tbody>
	    <?php $i=0; $count = 0; $total = 0; ?>
	    <?php foreach ($cart as $id => $quantity): ?>
	        <?php if ($product = $products->findByUID($id)): ?>
	            <?php $product = $product->first() ?>
	            <?php $i++; ?>
	            <?php $count += $quantity ?>
	            <tr>
	                <th>
	                    <input type="hidden" name="item_name_<?php echo $i ?>" value="<?php echo $product->title() ?>" />
	                    <input type="hidden" name="amount_<?php echo $i ?>" value="<?php echo $product->price() ?>" />
	                    <?php echo kirbytext($product->title(), false) ?>
	                </th>
	                <td><input data-id="<?php echo $product->uid() ?>" data-quantity="<?php echo $quantity ?>" pattern="[0-9]*"  class="quantity" type="number" name="quantity_<?php echo $i ?>" min="1" value="<?php echo $quantity ?>"> <a href="<?php echo url('shop/cart') ?>?action=delete&amp;id=<?php echo $product->uid() ?>">Remove</a></td>
	                <?php $prodtotal = floatval($product->price()->value)*$quantity ?>
	                <td>£<?php printf('%0.2f', $prodtotal) ?></td>
	            </tr>
	            <?php $total += $prodtotal ?>
	        <?php endif; ?>
	    <?php endforeach; ?>
	        </tbody>
	        <tfoot>
	            <tr>
	                <td colspan="2">Subtotal</td>
	                <td>£<?php printf('%0.2f', $total) ?></td>
	            </tr>
	            <tr>
	                <?php $postage = cart_postage($total) ?>
	                <td colspan="2" class="align-right">Postage</td>
	                <td>£<?php printf('%0.2f', $postage) ?></td>
	            </tr>
	            <tr>
	                <th colspan="2" class="align-right">Total</th>
	                <th>£<?php printf('%0.2f', $total+$postage) ?></th>
	            </tr>
	        </tfoot>
	    </table>
	    <p><button type="submit">Pay with PayPal</button></p>
	    <p>or <a href="<?php echo url('shop') ?>">continue shopping</a></p>
	</form>
	    
   	<!-- footer here -->

You can see this in action at kylebean.co.uk/shop.

5 Likes

I’ve used this code for an older website. It doesn’t work perfectly, but that was mostly because I wasn’t that familiar with Kirby then: http://madame-stoeckelschuh.de/

We’ve expected about 10-20 products, but the client wanted way more products, categories, shoe sizes, sales, a “not available”-status, checking out with the same product in two sizes, article numbers and some other additional things. Overall I’m not very satisfied with the final product, but the plugin itself served me well.

I’m not a big fan of building eCommerce websites at all, after experience with Magento and xt:Commerce. But with the right plugin, Kirby is perfect for small shops in my opinion.

1 Like

Hi,
Remplace (cart.php template):

<?php if ($product = $products->findByUID($id)): ?>

to:

<?php if ($product = $products->find($id)): ?>

Work on Kirby 2.

Little demo

Chris.

3 Likes

So we have a more or less working shop plugin for kirby here, right?

Somebody up for putting it up on github?

Hey Guys,
i actually started this topic today : Is there a need for a kirby-based Shop System? now i was pointed to your project. Seems like you folks did a great job. Is https://github.com/getkart/kart/ the most recent status of the project? @plaidpowered are you the owner of the repository?

edit: Just read that the development has been stopped. I will most likely set up an own solution and see this as an inspiration. Anyone that is willing to contribute is very welcome to join.

@Tapefabrik, you may want to follow this ShopKit project.