Download the PHP package philipbrown/merchant without Composer
On this page you can find all versions of the php package philipbrown/merchant. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philipbrown/merchant
More information about philipbrown/merchant
Files in philipbrown/merchant
Package merchant
Short Description Ecommerce abstraction for dealing with products, orders and sales
License MIT
Informations about the package merchant
Merchant (DEPRECATED)
Ecommerce abstraction for dealing with products, orders and sales
Merchant is a simple abstraction for working with products, orders and sales within an ecommerce application. It aims to solve the problem of dealing with multiple product orders and the associated data that you will be required to store and use within the lifecycle of a customer.
Installation
Add philipbrown/merchant
as a requirement to composer.json
:
Update your packages with composer update
.
Usage
The primary purpose of Merchant is a way to store and organise the data about each individual product with an order or a sale and then to find the aggregate totals using a simple interface.
Regions
Due to the fragmented situation of the world's financial rules and regulations, Merchant is broken into individual regions. Each region has specific data set as properties that are applicable in that region.
For example, England is represented as:
If you would like to add your region to Merchant:
- Open a Pull Request
- Create a new class for your region under
src\Philipbrown\Merchant\Region
- Make sure your class extends
AbstractRegion
and implementsRegionInterface
Money and Currency
Money and Currency in Merchant is abstracted to Money. For full details, usage and documentation please see that repository.
Briefly:
- Values are represented as integers to avoid the floating point problem
- Objects are immutable
- Currency details are encapsulated in it's own class
Creating a new Merchant instance
To create a new Merchant instance to work with, simply pass the Region
you want to create to the order
method:
Adding a product
Adding a product to your order is as simple as specifying a SKU and the value of the product as an integer:
The values for tax (if applicable) as well as the correct Currency
instance will automatically be handled for you from the Region
you specified when you created the Merchant instance.
The add
method also accepts a third optional parameter of either an array
or a closure
. The third parameter allows you to perform actions on the product such as setting a discount, making this particular product not taxable, a freebie or setting a coupon:
Removing a product
To remove a product simply pass the sku
to the remove
method:
Updating a product
When you update a product, first the product instance is removed and then replaced with the new data that you pass:
Order totals
As you add, update or remove products from your order Merchant will be automatically calculating the various totals that you will need to record in your database and display on reciepts and invoices. Each total is an instance of Money
:
Future developments
Currently Merchant does not deal with any physical attributes of selling online. For example, delivery charges, international shipping etc, etc, etc.
I have no plans to add any of these attributes as I don't have the requirment. If you do and you want to extend Merchant, feel free to open a Pull Request.
License
The MIT License (MIT)
Copyright (c) 2014 Philip Brown
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.