Documentatie B2bFatturazione

Installatiestappen en alles wat je nodig hebt om de B2B-velden via je eigen storefront beschikbaar te maken, inclusief headless/GraphQL-checkouts zoals React Checkout.

Weergeven als Markdown

Installatie

Vereisten

Magento 2.4.x — getest op 2.4.9, compatibel met eerdere 2.4.*-versies. PHP 8.1–8.5. Compatibel met zowel het standaard Luma-thema als het Hyvä-thema.

Installatiestappen

  1. Voeg de inloggegevens die je per e-mail ontvangt toe aan auth.json in de root van je Magento-project:
    { "http-basic": { "repo.codingrow.com": { "username": "...", "password": "..." } } }
  2. composer config repositories.codingrow composer https://repo.codingrow.com
  3. composer require codingrow/module-b2bfatturazione
  4. bin/magento module:enable Codingrow_B2bFatturazione
  5. bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento cache:flush
  6. Plak je licentiesleutel in Admin → Stores → Configuration → Codingrow Extensions → B2bFatturazione → License → License Key, sla op en voer dan bin/magento cache:flush uit. De sleutel is gebonden aan het domein dat bij aankoop is opgegeven — op elk ander domein blijft de module geïnstalleerd maar blijven de velden uitgeschakeld.
  7. Als de site in production-modus draait, implementeer dan ook de statische content opnieuw: bin/magento setup:static-content:deploy -f.

Deïnstallatie

composer remove codingrow/module-b2bfatturazione daarna bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento cache:flush.

Documentatie

Wat het doet

Dit is een bewust kleine, gerichte module: het voegt vijf velden toe — Klanttype (zakelijk/particulier), btw-nummer, SDI-code, PEC (gecertificeerde e-mail) en fiscaal nummer — aan het adresboek van de klant en aan de checkout (facturering en verzending), zowel in het standaard Luma-thema als in Hyvä. Er is geen configuratie nodig behalve het installeren en invoeren van de licentiesleutel; het werkt meteen na installatie.

VeldZichtbaar wanneerVerplicht wanneerFormaat / notities
KlanttypealtijdaltijdParticulier / Bedrijf. Bepaalt al het andere.
BedrijfsnaamBedrijfBedrijf—
Btw-nummerBedrijfBedrijfMax 15. Twee beginletters = buitenlands → SDI/PEC verborgen.
SDI-codeBedrijf + Italiaanse btw + factuur gevraagdSDI of PECMax 7.
PECBedrijf + Italiaanse btw + factuur gevraagdSDI of PECGecertificeerde e-mail.
Factuur gevraagdParticulier (vinkje)—Aanvinken maakt de fiscale code verplicht.
Fiscale codeBedrijf, of Particulier + factuur gevraagdParticulier + factuur gevraagd16 tekens (persoon) of 11 cijfers (bedrijf).
The B2B fiscal fields on the storefront address form (Customer Type set to Business): VAT number, SDI, PEC, Fiscal Code

The same fields appear in checkout (billing and shipping) and in the admin customer address book.

Admin-configuratie

Er is geen gedragsconfiguratie — de enige admin-instelling is de licentiesleutel. Al het andere (welke velden verschijnen, wanneer ze verplicht zijn) is automatisch.

B2bFatturazione admin configuration: a single License Key field

GraphQL-/headless- & React Checkout-compatibiliteit

De vijf B2B-velden worden blootgesteld via Magento's eigen core GraphQL-types en mutations — geen aangepaste API. Als je storefront op GraphQL is gebaseerd (React Checkout, of een andere headless/GraphQL-frontend), lees en schrijf je deze velden precies zoals elk ander native adresveld, via de mutations die je al gebruikt.

Velden lezen

customer_type, sdi, pec, codice_fiscale en fattura_richiesta worden rechtstreeks toegevoegd aan Magento's eigen types BillingCartAddress, ShippingCartAddress en CustomerAddress:

{
  customerCart {
    billing_address {
      customer_type
      sdi
      pec
      codice_fiscale
      fattura_richiesta
    }
  }
}
{
  customer {
    addresses {
      customer_type
      sdi
      pec
      codice_fiscale
      fattura_richiesta
    }
  }
}

Velden schrijven

Dezelfde vijf velden worden toegevoegd aan Magento's eigen core-type CartAddressInput, dus ze worden meegegeven samen met de normale adresvelden in de standaard cart-mutations — geen aparte mutation nodig:

mutation {
  setShippingAddressesOnCart(
    input: {
      cart_id: "abc123"
      shipping_addresses: [
        {
          address: {
            firstname: "Mario"
            lastname: "Rossi"
            street: ["Via Roma 1"]
            city: "Milano"
            postcode: "20100"
            country_code: "IT"
            telephone: "+390000000"
            customer_type: "azienda"
            sdi: "ABC1234"
            pec: "mario.rossi@pec.it"
            codice_fiscale: "RSSMRA80A01F205X"
          }
        }
      ]
    }
  ) {
    cart { id }
  }
}

Implementatienotities

  • Dit alles gebeurt via de officiële Magento-uitbreidingspunten (di.xml-plugins op core-interfaces zoals Magento\QuoteGraphQl\Model\Cart\QuoteAddressFactory en Magento\CustomerGraphQl\Model\Customer\Address\ExtractCustomerAddressData) — er wordt niets gepatcht of gekopieerd in de core GraphQL-resolvercode.
  • Serverside validatie (bijv. "SDI of PEC is verplicht voor een zakelijke klant") werkt op dezelfde manier, ongeacht welke storefront de mutation aanroept — REST, GraphQL, of de standaard Luma- checkout.
  • fattura_richiesta (factuur gevraagd) geldt alleen voor particuliere klanten — zakelijke klanten ontvangen wettelijk altijd een factuur, dus het veld is specifiek zinvol voor het geval "particulier" ("privato").

Nauwkeurige adresweergave in admin

De samenvatting van het standaard facturerings-/verzendadres van de klant in Customers → All Customers → [customer] → Addresses, en op het tabblad Customer View, bevat nu ook de B2B-velden — niet alleen het basisadres:

VoorNa
Mario Rossi
Mario Rossi S.r.l.
Via dei Test, 1
Roma, RM, 00100
Italië
T: 333 1122334
Btw: 01234567891
Mario Rossi
Mario Rossi S.r.l.
Via dei Test, 1
Roma, RM, 00100
Italië
T: 333 1122334
Klanttype: azienda
Btw: 01234567891
SDI: ABCDEFG
PEC: mario.rossi@pec.it
Fiscaal nummer: RSSMRA80A01H501V

React Checkout: direct te gebruiken, zonder extra ontwikkeling

Codingrow onderhoudt ook codingrow/module-react-checkout, een klein aanvullend pakket dat het daadwerkelijke B2B-factureringsformulier (klanttype, btw-nummer, SDI, PEC, fiscaal nummer) toevoegt aan Hyvä's React Checkout — de UI bovenop de hierboven gedocumenteerde GraphQL-velden. Installeer beide samen en het factureringsformulier werkt direct, zonder maatwerkontwikkeling.

Het bevat ook onze eigen compatibiliteitspatch waarmee React Checkout daadwerkelijk werkt op PHP 8.4 en 8.5. Het upstream-pakket dateert van vóór de striktere deprecation-afhandeling van PHP 8.4 — impliciete nullable parameters en een niet-escapede str_getcsv()-aanroep veroorzaken beide fatale fouten onder Magento's errorhandler op 8.4+, niet alleen waarschuwingen, waardoor React Checkout anders onbruikbaar zou zijn op een moderne PHP-stack. Deze patch wordt automatisch toegepast als onderdeel van de installatie hieronder.

React Checkout installeren met B2B-ondersteuning

  1. Vereis beide pakketten:
    composer require hyva-themes/magento2-react-checkout codingrow/module-react-checkout
  2. Voeg de PHP 8.4/8.5-compatibiliteitspatch toe aan de composer.json in de root van je project en voer daarna composer update --lock uit zodat deze wordt vastgelegd:
    "extra": {
        "patches": {
            "hyva-themes/magento2-react-checkout": {
                "PHP 8.4/8.5 compat": "vendor/codingrow/module-react-checkout/patches/react-checkout-php84-compat.patch"
            }
        }
    }
    (Vereist cweagans/composer-patches; voer eerst composer require cweagans/composer-patches uit als je dit nog niet hebt.)
  3. Schakel de modules in:
    bin/magento module:enable Codingrow_ReactCheckout Hyva_ReactCheckout
    bin/magento setup:upgrade
  4. Schakel React Checkout in: bin/magento config:set hyva_react_checkout/general/enable 1
  5. Bouw de React-app:
    cd vendor/codingrow/module-react-checkout/reactapp
    npm install
    npm run build
  6. Implementeer de statische content opnieuw — elke keer vereist, ook buiten de production-modus; anders kan de browser een verouderde bundel blijven laden:
    bin/magento setup:static-content:deploy -f en_US --theme <your-theme>
  7. bin/magento cache:flush

Vereisten: Magento 2.4.9, PHP 8.1–8.5 (inclusief 8.4/8.5, via de meegeleverde patch).