# reach-digital/magento2-companyswitcher

> Moves the Company and Vat field to the top of the checkout and add a switcher (private/business).

`composer require reach-digital/magento2-companyswitcher`

Canonical URL: https://packagento.com/reach-digital/magento2-companyswitcher

## At a glance

- **Vendor**: reach-digital (https://packagento.com/reach-digital.md)
- **Latest version**: 0.5.0 — released 2023-04-13
- **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/reach-digital/magento2-companyswitcher 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 reach-digital/magento2-companyswitcher:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## What it does

Moves the Company and Vat field to the top of the checkout and add a switcher (private/business).

## README

[Changelog](CHANGELOG.md)

### Installation
```BASH
composer require reach-digital/magento2-companyswitcher
php bin/magento module:enable Ho_CompanySwitcher
```

### Description
Moves the Company and Vat field to the top of the checkout and add a switcher (private/business).

#### 'Own Reference' field
Field is added to the order view page automatically. You'll need to edit the matching template when adding the field to email/pdf.

##### Email
For email you can use:
`{{depend order.getData('own_reference')}}<div>{{trans 'Own reference: %own_reference' own_reference=$order.getData('own_reference') |escape|raw}}</div>{{/depend}}`

##### (Fooman) PDF
For PDF you can use:
```PHP
<?php if (! empty($order->getData('own_reference'))): ?>
    <?= __('Own reference') ?>: <?= $block->escapeHtml($order->getData('own_reference')); ?><br/>
<?php endif; ?>
```

#### Configuring with OneStepCheckout.com extension
Onestepcheckout fields can randomly shift when using this extension without properly configuring the extension. You need to add the two new fields, and set them in the correct order. In the Onestepcheckout configuration add field with name 'company_switcher' and a field with the name 'own_reference'. Set the order of the fields:
1. company_switcher (enable it!)
1. company
1. vat_id
1. own_reference (you can disable it if you don't use it. But you need to add it)

### Credits
Read more about this extension on our blog    
https://www.reachdigital.nl/blog/gratis-magento-2-module-optimaal-zakelijk-bestellen-in-het-magento-afrekenproces

Developed by Reach Digital  
https://www.reachdigital.nl

## Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) 
and this project adheres to [Semantic Versioning](http://semver.org/).

### [Unreleased]

### [0.1.0] - 2016-12-29
#### Note
- Created module

## Recent Versions

| Version | Released |
|---|---|
| 0.5.0 | 2023-04-13 |
| 0.4.1 | 2023-03-16 |
| 0.4.0 | 2022-11-15 |
| 0.3.0 | 2021-07-27 |
| 0.2.0 | 2020-08-06 |
| 0.1.1 | 2018-02-22 |
| 0.1 | 2017-07-28 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| php | ^7.2\|^7.3\|^7.4\|^8.0\|^8.1 |

## Quality

Latest release (0.5.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 | 1 | – |
| 2.4.9 | – | – | 1 | 1 |


### 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 | 6 | 3 errors, 3 warnings (ruleset: Magento2) — 3 auto-fixable with phpcbf |
| PHPMD | Warning | 2 | 2 rule violations (UnusedFormalParameter:2) |
| 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 | 2 | 2 | – | – |
| 2.4.8 | – | 2 | 4 | – |
| 2.4.9 | – | – | 4 | 4 |


### 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=["reach-digital/magento2-companyswitcher"],
  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

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

