Prefabs
Building your shop frontend with PHP
The localhost demo works out of the box. To build a custom frontend for your shop, copy a few snippets and templates from the plugin into your root Kirby project folders. As long as you keep the folders and filenames unchanged, Kirby will treat your files as replacements for those from the Kirby Kart plugin.
The plugin includes a hardcoded yet stylable theme as an alternative to creating your own PHP-based frontend.
Content
- Create a content file for the cart at
content/cart/cart.txt
Snippets
The Kirby Kart plugin includes several preinstalled snippets. These snippets are used in the localhost demo and serve as starting points for you.
When you create a snippet in your site/snippets-folder with the same name as the one from the plugin you will be overwriting it. My advice would be to copy the snippets from the plugin to your site/snippets-folder one by one as you proceed to customize the look. Copying everything at once can result in an overwhelming number of new snippets, many of which may not be necessary for your setup and can be left out.
Most likely you will want to copy at least these five snippets:
- snippets/kart/cart.php
- snippets/kart/cart-add.php
- snippets/kart/cart-buy.php
- snippets/kart/wish-or-forget.php
- snippets/kart/wishlist.php
Templates
Similarly to the snippets, the Kirby Kart plugin registers a few templates used in the localhost demo, and again, you might not need all of them. Start by copying these four into your site/templates folder.
- templates/cart.php
- templates/order.php
- templates/products.php
- templates/product.php
Blueprints
The plugin automatically registers the blueprints it needs and provides a simple way to add custom product fields.
Create a site/blueprints/tabs/products-local.yml, and any columns/sections/fields you add there will be shown on the second tab of the product's blueprint. This allows me to push improvements to the blueprints without disrupting your custom setup.
The alternative would be to copy all the YAML files from the plugin blueprints into your project's site/blueprints/pages and site/blueprints/users-folders. While this option allows full adjustment of the panel views, you will miss out on my updates.
The blueprints for the product and order tabs are intended to be copied to the site/blueprints/tabs folder and modified by you. This is the recommended way to add custom fields.
If you customize the customer blueprint or add additional roles make sure these roles do not have access to the panel! It is easy to get the settings wrong and Kirby might fall back to the default permissions which would allow access to the Panel. Verify at least once it is working as intended.
Models and adding functionality to Kart
The plugin automatically registers the necessary models, and to keep the complexity of the codebase manageable, you cannot currently add code to them directly. One way to extend the models would be to extend the classes from Kart and register your models after Kirby has loaded Kart (mind the extensions/plugin loading order). Or using the /site/models-folder should work too.
If you need to add only a few functionalities to page models quickly, consider using Page Method extensions instead and add an if-clause with a check on the template name.
Consider reading up on the various hooks and callbacks (like completed or orders.order.zip) this plugin has. There is a good chance you can use these to solve some of your e-commerce related tasks.
If you start extending Kart classes you might need to disable the shorthand names the plugin is registering via class_alias before initializing Kirby. Only do that if you run into errors. This works similar to the Kirby helpers configuration.
<?php
define('KART_CLASS_ALIAS', false);
require __DIR__ . '/../vendor/autoload';
echo (new Kirby)->render();
Providers
You can extend the classes of a provider and re-register them, like with the models. The documentation of the default provider, the kirby_cms-provider, explains how to do so. This is a bit more advanced and usually not necessary.