# code4business/freeproduct2

> Adds a sales rule action to add a product to cart. Can be used to create sales rules to add gifts to cart.

`composer require code4business/freeproduct2`

Canonical URL: https://packagento.com/code4business/freeproduct2

## At a glance

- **Vendor**: code4business (https://packagento.com/code4business.md)
- **Latest version**: 1.4.0 — released 2026-05-26
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/code4business/freeproduct2 and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require code4business/freeproduct2:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Adds a sales rule action to add a product to cart. Can be used to create sales rules to add gifts to cart.

## README

Freeproduct
===========

An extension that allows configuring sales rules to add free products to cart. This is the Magento 2 version of the same extension that can be found [here](https://github.com/code4business/freeproduct). 
The development and the function of the original Magento1 extension is described in the following two websites:
- <http://www.code4business.de/make-a-gift-magento-warenkorbpreisregeln-um-geschenke-erweitern/>
- <http://www.webguys.de/magento/turchen-21-kostenlose-produkte-uber-warenkorb-preisregeln/>

Contributors
-------
This repository is not run by code4business anymore, but Simon Sprankel and Ole Schäfer of CustomGento stepped up to keep freeproduct alive.

Requirements
-------
- PHP 7.4, PHP >= 8.1
- Magento >= 2.4.3-p1

Generally the last full release -1 version is tested and made to work. Older versions are not actively supported.

Supported Product Types
-------
The extension only supports simple and virtual product types, other types or custom options are not supported. The reason is that other product types need additional information that can only be added with IDs. This leads to a way more complicated module; we want to keep this module clean and easy.

Instalation
-------
Go to the Magento 2 root directory and run the following commands in the shell:
```
composer require code4business/freeproduct2
bin/magento module:enable C4B_FreeProduct
bin/magento setup:upgrade
```

Configuration
-------
Sales rules for carts are configured in _Marketing->Cart Price Rules_:  
- In the Actions tab, the Apply field should be set to Add a Gift
- Gift SKU: Product that will be added. Only simple and virtual products without (required) custom options are supported. Multiple comma-separated SKUs can be specified
- Discount Amount: The qty of added gifts  
- The gift item is added once for the whole cart

Action **Add a Gift (for each cart item)** works similarly but will add the gift item for each product in cart. The qty of said product is also taken into consideration.  

This action usually needs conditions to match only specific items *(Apply the rule only to cart items matching the following conditions)*.   

Limitations:
-------
- Gift products are added during discount total processing, after subtotal and shipping totals. Because of that gift products will not be included in any shipping calculations.
- Only simple and virtual products without required custom options are supported.

Current localizations:
-------
- de_DE
- es_ES
- fr_FR
- nl_NL
- pt_PT
- sl_SI

License
-------
[Open Software Licence 3.0 (OSL-3.0)](http://opensource.org/licenses/osl-3.0.php)

## Recent Versions

| Version | Released |
|---|---|
| 1.4.0 | 2026-05-26 |
| 1.3.2 | 2023-04-06 |
| 1.3.1 | 2022-08-24 |
| 1.3.0 | 2022-08-10 |
| 1.3.0-beta | 2022-08-10 |
| 1.2.9 | 2020-12-09 |
| 1.2.8 | 2020-03-16 |
| 1.2.7 | 2019-12-06 |
| 1.2.6 | 2019-08-09 |
| 1.2.0 | 2019-02-08 |

Showing 10 of 16 versions. Full release history on https://packagento.com/code4business/freeproduct2.

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/module-sales-rule | ^101.2.3 |
| php | ~7.4 \|\| ~8.1 |

## Quality

Latest release (1.4.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | Pass | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 114 | 1 error, 113 warnings (ruleset: Magento2) — 71 auto-fixable with phpcbf |
| PHPMD | Warning | 7 | 7 rule violations (UnusedFormalParameter:5, CyclomaticComplexity:1, MissingImport:1) |
| Cpd | Pass | 0 |  |
| Composer validate | Pass | 0 |  |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 16 | 16 | – | – |
| 2.4.8 | – | 16 | 16 | – |
| 2.4.9 | – | – | 16 | 16 |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["code4business/freeproduct2"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

code4business is a Magento 2 vendor on Packagento. See https://packagento.com/code4business.md for their full catalogue.

