Download the PHP package offline/oc-microcart-plugin without Composer
On this page you can find all versions of the php package offline/oc-microcart-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package oc-microcart-plugin
oc-microcart-plugin
The
OFFLINE.MicroCart
plugin aims to provide simple shopping cart and payment features.
This plugin is meant for projects where simple items are sold online (Tickets, Coupons, etc).
You will have to implement the "item part" (like a Ticket
model) yourself. You can use
the plugin as cart and payment solution.
Features
The OFFLINE.MicroCart
plugin provides the following features:
- A
Cart
model with a nice API to add and removeCartItems
- A
Cart
component base, that is meant to be extended by you Stripe
,PayPal
andSIX SaferPay
payment integrations- Support to add custom payment gateways
- Numerous events for you to hook into
It does not provide any of these features:
- Product data management
- E-Mail notifications
- Multi currency support
- Stock management
- Shipping rules
- ... and lots of other extended eCommerce features
If you are looking for a fully featured eCommerce solution for October CMS check out OFFLINE.Mall.
Getting up and running
Create your own plugin that extends MicroCart
The MicroCart plugin is meant to be extended by your own plugins. Refer to the official October CMS docs for a list of all extension possibilities.
Backend menu
The plugin does by default not register any backend menu items. You can use the
following snippet in your own Plugin.php
to use the default orders overview.
Cart component
The plugin does not register any components but it provides you with a Cart
base
component that you can extend.
Simply register your own component and build from there.
Register your component in your Plugin.php
.
Make sure the component extends MicroCart's base component.
To modify validation rules and messages take a look at the getValidationRules
, getFieldNames
and getValidationMessages
methods on the base Cart
class.
Copy the default partials from MicroCart's base component to your own component. Modify them as needed.
Updating the cart partials
You can return $this->refreshCart();
from your Cart component's methods to refresh the cart display.
Using payment providers
There are three payment providers supported out-of-the-box:
- PayPal (
composer require omnipay/stripe
) - Stripe (
composer require omnipay/paypal
) - Six SaferPay (
composer require ticketpark/saferpay-json-api
)
Run the composer commands beside each provider you plan to use. You can configure the providers via October's backend settings.
Custom payment providers
To register a custom PaymentProvider
create a class that extends MicroCart's PaymentProvider class.
Check out the existing providers to get some inspiration on how to create your own.
In your Plugin.php
register this custom provider by returning them from a registerPaymentProviders
method.
Link your model to cart items
The easiest way to link a model to a CartItem
is to add a simple belongsTo
relationship.
API
Cart
Get the user's cart
Add an item to the cart
Ensure an item is in the cart
Remove an item from the cart
Remove all items with a given code from the cart
Update an item's quantity
Service fees and discounts
Set the kind
attribute to either CartItem::KIND_SERVICE
or CartItem::KIND_DISCOUNT
if the item is a service fee (Shipping, Handling) or a discount.
Use the ensure
method to make sure it's only added once to the Cart.
Access cart contents
You can access all cart items using the $cart->items
relation.
You also have access to filtered list_items
, service_fees
and discounts
properties that only contain the given item types.
Print the customer's address
After a Cart
checkout has been successful, you can use the following helpers
to get the customer's address as an array or an escaped HTML string.
CartItem
Create an item
Access item information
Money
There is a Money
singleton class available to format cents as a string.
A microcart_money
Twig helper is registered as well.
Change the default money formatter
You can register your own formatter function by adding the following code
to your Plugin's register
method.
Events
Cart
offline.microcart.cart.beforeAdd
Fired before an item is added to the Cart. It receives the following arguments:
$cart
: theCart
of the current user$item
: theCartItem
being added
offline.microcart.cart.afterAdd
Fired after an item has been added to the Cart. It receives the following arguments:
$cart
: theCart
of the current user$item
: theCartItem
added
offline.microcart.cart.beforeRemove
Fired before an item is removed from the Cart. It receives the following arguments:
$cart
: theCart
of the current user$item
: theCartItem
being removed
offline.microcart.cart.afterRemove
Fired after an item has been removed from the Cart. It receives the following arguments:
$cart
: theCart
of the current user$item
: theCartItem
removed
offline.microcart.cart.quantityChanged
Fired after the quantity of a cart item has changed.
$cart
: theCart
of the current user$item
: theCartItem
that was updated
Checkout
offline.microcart.checkout.succeeded
Fired after a checkout was successful.
$result
: aPaymentResult
instance
offline.microcart.checkout.failed
Fired after a checkout has failed.
$result
: a?PaymentResult
instance (nullable)
offline.microcart.checkout.cancelled
Fired after a checkout has been cancelled.