code4business / freeproduct2

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.

  • Dominik Meglič
magento2-module Compatibility: 2.4.7-2.4.9 Code Quality: Fail Tests: N/A Security: Pass OSL-3.0

Are you the maintainer of code4business?

Packagento pulls code4business's Composer packages from the public registry so buyers can find them here.

Claim the namespace to take ownership, publish new releases directly, and start charging for premium versions.

Claim this namespace →

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.
The development and the function of the original Magento1 extension is described in the following two websites:

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)

No changelog yet

The vendor hasn't published a changelog. Tagged releases appear in the Versions tab.

Versions
Version Stability QA Status Compatibility Released
1.4.0 stable Fail Magento 2.4.7-2.4.9 Details 2026-05-26 13:27:21
1.3.2 stable Not tested Not yet tested Details 2023-04-06 07:57:08
1.3.1 stable Not tested Not yet tested Details 2022-08-24 07:20:44
1.3.0 stable Not tested Not yet tested Details 2022-08-10 10:27:16
1.3.0-beta beta Not tested Not yet tested Details 2022-08-10 10:17:10
1.2.9 stable Not tested Not yet tested Details 2020-12-09 13:29:13
1.2.8 stable Not tested Not yet tested Details 2020-03-16 09:40:44
1.2.7 stable Not tested Not yet tested Details 2019-12-06 07:13:02
1.2.6 stable Not tested Not yet tested Details 2019-08-09 14:44:03
1.2.0 stable Not tested Not yet tested Details 2019-02-08 08:08:41
1.0.5 stable Not tested Not yet tested Details 2018-09-04 06:47:44
1.0.4 stable Not tested Not yet tested Details 2018-08-16 11:39:27
1.0.3 stable Not tested Not yet tested Details 2018-06-05 15:24:47
1.0.2 stable Not tested Not yet tested Details 2018-04-13 08:44:56
1.0.1 stable Not tested Not yet tested Details 2018-01-08 08:15:23
1.0.0 stable Not tested Not yet tested Details 2017-11-07 08:55:21

Requires 2

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

Compatibility

Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.

Compatibility matrix (Magento × PHP)
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. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge. 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.

Static analysis results
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's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases.

PHPStan results by Magento and PHP version
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 for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.

Unit tests

Unit tests results by Magento and PHP version
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

Integration tests results by Magento and PHP version
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

Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.

Security results
Tool Status Findings Summary
Composer audit Pass 0
Malware scan Pass 0
License
OSL-3.0
Homepage
https://github.com/code4business/freeproduct2
Authors
Make it pay

Turn an existing module into recurring revenue.

If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.