PHPackages                             mothership-ec/cog-mothership-commerce - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. mothership-ec/cog-mothership-commerce

AbandonedLibrary[Framework](/categories/framework)

mothership-ec/cog-mothership-commerce
=====================================

Cog module for commerce building blocks in Mothership

5.20.0(10y ago)52.2k1[88 issues](https://github.com/mothership-ec/cog-mothership-commerce/issues)[6 PRs](https://github.com/mothership-ec/cog-mothership-commerce/pulls)7GPL-3.0+PHPPHP &gt;=5.4.0

Since Aug 27Pushed 10y ago5 watchersCompare

[ Source](https://github.com/mothership-ec/cog-mothership-commerce)[ Packagist](https://packagist.org/packages/mothership-ec/cog-mothership-commerce)[ Docs](http://mothership.ec)[ RSS](/packages/mothership-ec-cog-mothership-commerce/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (8)Versions (148)Used By (7)

Mothership Commerce
===================

[](#mothership-commerce)

The `Message\Mothership\Commerce` Cogule provides base commerce functionality for Mothership. This forms part of the building blocks for both `ECommerce` and `EPOS`.

Installation
------------

[](#installation)

Install this package using [Composer](http://getcomposer.org/). The package name is `message/cog-mothership-commerce`.

You will need to add Message's private package server to the `repositories` key in `composer.json`:

```
{
	"repositories": [
		{
			"type": "composer",
			"url" : "http://packages.message.co.uk"
		}
	],
	"require": {
		"message/cog-mothership-commerce": "~4.1"
	}
}

```

\##Product A Product object represents a certain product. They provide attributes such as the category and brand as well a prices. Units allow Variants on Products such as "size" and "colour". For this reason, it is usually desirable to use Units over Products when displaying prices to users.

If no prices are provided on a Unit, it will default to the Product prices.

\##Product\\Types Each product has a Type associated to it. The main use of a Type is to allow different information to be required by different products. For example a `MusicProductType` requires an Artist to be provided. Types also allow the "display name" to be set into to a different format.

Types provided for use within the admin panel are set in the IoC as the service `product.types`. Only types registered in the service container may be used when creating products.

\##Product\\Price The product Pricing object is a group of prices (float) mapped against Currency and Locale. Product and Unit objects have a Pricing object which they use when calling `getPrice()`, `getNetPrice()` etc. This object does the legwork of getting the correct price to display based on currency and locale.

\##Product\\Tax Product taxes are loaded onto the product using an instance of `TaxResolverInterface`. Net and Gross prices are calculated using these tax rates and an instance of `TaxStrategyInterface`.

\###TaxResolver The `TaxResolverInterface` is an interface for a class that will take a token and an `Address` and return a `TaxCollection` containing all the applicable tax rates for that token/address combination. By default, the `TaxResolver` is used. This looks within the `tax.yml` file to resolve taxes.

\###TaxStrategy Whilst it is possible to implement the interface to provide further tax strategies, realistically there are only two which will be used. These are Tax Inclusive and Tax Exclusive. These are provided within Commerce.

Product\\Stock
--------------

[](#productstock)

### General

[](#general)

`Product\Stock` is responsible for handling stock changes. Every stock change is documented as a stock adjustment(`Product\Stock\Movement\Adjustment\Adjustment`). Stock adjustments created within the same action(creating a new order/ adjusting stock levels in one request) are surrounded by a stock movement(`Product\Stock\Movement\Movement`), to give them a reason, authorship, etc.

### Stock Manager

[](#stock-manager)

The stock manager `Product\Stock\StockManager` is responsible for creating and saving new stock movements (and adjustments). Please read the detailed readme of `Product\Stock` for more information!

### Movement Iterator

[](#movement-iterator)

Also there is an Iterator for stock movements, which allows you to iterate over the stock history and get the stock level at any time before or after a movement. Please read the detailed readme of `Product\Stock` for more information!

Product Page Mapper
-------------------

[](#product-page-mapper)

The commerce package ships with two implementations of the product page mapper: `SimpleMapper` and `OptionCriteriaMapper`. By default the `SimpleMapper` is aliased to `product.page_mapper`.

#### Configuration

[](#configuration)

To enable the mapper to correctly relate products to pages you must set the valid values for `product_content.field_name` and `product_content.group_name` for product pages. Additionally you should set the valid page types. You can change these using:

```
$services->extend('product.page_mapper', function($mapper, $c) {
	$mapper->setValidFieldNames('product');

	// Passing an array to either method will match against all values
	$mapper->setValidGroupNames(['product', 'showcase']);

	// Passing false to the group name will exclude pages within any group
	$mapper->setValidGroupNames(false);

	// Passing null or an empty array to the group name will match pages with
	// any or no group
	$mapper->setValidGroupNames([]);

	$mapper->setValidPageTypes(['product', 'strap']);

	return $mapper;
});
```

These default to:

- Field Names: `'product'`
- Group Names: `null`
- Page Types: `'product'`

### Simple Mapper

[](#simple-mapper)

The simple mapper just matches a basic product to a page.

#### Usage

[](#usage)

```
// Find a page from a product
$page = $services['product.page_mapper']->getPageForProduct($product);

// Find a product from a page
$product = $services['product.page_mapper']->getProductForPage($page);
```

### Option Criteria Mapper

[](#option-criteria-mapper)

The option criteria mapper can additionally apply a filter for a specific product option, for example `['colour' => 'red']`. You can pass any number of options: `['colour' => 'red', 'size' => 'medium']`.

To enable the option criteria mapper you must alias it to the page mapper in your services:

```
$services['product.page_mapper'] = $services->raw('product.page_mapper.option_criteria');
```

#### Usage

[](#usage-1)

In addition to the previous methods, you can also call:

```
// Find all pages from a product
$pages = $services['product.page_mapper']->getPagesForProduct($product, ['colour' => 'red']);

// Find a page from a unit
$page = $services['product.page_mapper']->getPageForProductUnit($unit);

// Find units from a page
$units = $services['product.page_mapper']->getProductUnitsForPage($page);
```

### Custom Mappers

[](#custom-mappers)

When writing a custom mapper you should extend `AbstractMapper` to ensure compatibility.

### Filters

[](#filters)

You can optionally pass in filter callbacks that are applied after the results are pulled from the database. Returning `false` from the callback will remove the object from the results.

#### Usage

[](#usage-2)

```
$services->extend('product.page_mapper', function($mapper, $c) {
	$mapper->addFilter(function($obj) {
		if ($obj instanceof Page) {
			return (false !== stristr($obj->title, "foo"));
		}
	});

	return $mapper;
});
```

License
-------

[](#license)

Mothership E-Commerce Copyright (C) 2015 Jamie Freeman

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

89

Last Release

3655d ago

Major Versions

1.2.0 → 2.0.02014-03-18

2.2.0 → 3.0.02014-06-11

3.6.1 → 4.0.02014-09-16

4.9.2 → 5.0.02015-02-24

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.1.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c80abec1ec847de90ada27e2239c31f4374ed1d91912493f5415a688c269a78?d=identicon)[thomasjthomasj](/maintainers/thomasjthomasj)

---

Top Contributors

[![thomasjthomasj](https://avatars.githubusercontent.com/u/4520924?v=4)](https://github.com/thomasjthomasj "thomasjthomasj (656 commits)")[![lsjroberts](https://avatars.githubusercontent.com/u/3817697?v=4)](https://github.com/lsjroberts "lsjroberts (331 commits)")[![kuiche](https://avatars.githubusercontent.com/u/5089510?v=4)](https://github.com/kuiche "kuiche (312 commits)")[![irisSchaffer](https://avatars.githubusercontent.com/u/4313088?v=4)](https://github.com/irisSchaffer "irisSchaffer (295 commits)")[![dannyhannah](https://avatars.githubusercontent.com/u/1499449?v=4)](https://github.com/dannyhannah "dannyhannah (197 commits)")[![eleanorshakeshaft](https://avatars.githubusercontent.com/u/5039349?v=4)](https://github.com/eleanorshakeshaft "eleanorshakeshaft (55 commits)")[![joeholdcroft](https://avatars.githubusercontent.com/u/2511043?v=4)](https://github.com/joeholdcroft "joeholdcroft (50 commits)")[![richmccartney](https://avatars.githubusercontent.com/u/1201618?v=4)](https://github.com/richmccartney "richmccartney (16 commits)")[![chadtomkiss](https://avatars.githubusercontent.com/u/1034152?v=4)](https://github.com/chadtomkiss "chadtomkiss (6 commits)")[![aislingbrock](https://avatars.githubusercontent.com/u/3073759?v=4)](https://github.com/aislingbrock "aislingbrock (4 commits)")

---

Tags

moneyordersproductscogmothershipcommerceorder

### Embed Badge

![Health badge](/badges/mothership-ec-cog-mothership-commerce/health.svg)

```
[![Health](https://phpackages.com/badges/mothership-ec-cog-mothership-commerce/health.svg)](https://phpackages.com/packages/mothership-ec-cog-mothership-commerce)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

41.5k328.9k1](/packages/ccxt-ccxt)[kartik-v/yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.

743.1M27](/packages/kartik-v-yii2-dynagrid)[sylius/product-bundle

Product catalog for your Symfony applications.

16324.5k12](/packages/sylius-product-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
