Abo: Einmalprodukte bereits bei der Abo-Anlage + es/fr-Sprachsync

Einmalprodukte (Normalsortiment, show_on 3) können jetzt schon beim
Abo-Abschluss hinzugefügt werden – im Portal-Wizard (Abschnitt im
Upgrade-Schritt) und in allen drei Sales-Center-Abo-Strecken (eigene
Produktliste). Variante A: Zeilen laufen als Cart-Option abo_addon mit
durch den Checkout, werden sofort bezahlt und mit der Erstlieferung
verschickt (Rechnung/Lieferschein gruppieren automatisch).

- Checkout persistiert is_abo_addon (CheckoutRepository, PaymentHelper)
- createAboItems/ensureUserAboItemsFromLatestOrder überspringen Addons
  (sonst würden Einmalprodukte dauerhaft wiederkehren); amount ohne
  Addon-Anteil; aboHasBaseProduct ignoriert Addon-Zeilen
- CreateAboReplacementOrder propagiert is_abo_addon in Ersatzbestellungen
- iq-shopping-cart.js: zweite Datatable + abo_addon-Flag-Weitergabe
- i18n: neue abo.onetime_create_*-Keys (de/en/es/fr); zusätzlich es/fr
  komplett synchronisiert (abo-Kartenblock, navigation, payment,
  weborder inkl. Entfernung PAYONE-Altlasten, withdrawal.php neu)
- Tests: AboCreateOneTimeItemsTest, AboCreateOneTimeCartTest,
  AboPortalCreateOneTimeTest (17 neue, 122 Tests gesamt grün)

Plan: dev/2026-07-21-abo-einmalprodukte-anlage/

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin 2026-07-21 14:36:40 +00:00
parent 1e7ae92d0c
commit cdb121fde0
32 changed files with 1479 additions and 52 deletions

View file

@ -0,0 +1,134 @@
<?php
/**
* Einmalprodukte in der Sales-Center-Abo-Bestellstrecke (Anlage, Variante A):
* updateCart mit abo_addon=1 legt eine getrennte Cart-Zeile (Option abo_addon) an,
* Sortiment-Prüfung läuft gegen das Einmal-Sortiment (show_on '3').
*/
use App\Http\Controllers\User\OrderController;
use App\Models\Country;
use App\Models\Shipping;
use App\Models\ShippingCountry;
use App\Models\ShippingPrice;
use App\Services\ProductOrderContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
function makeOneTimeCartEnv(): ShippingCountry
{
$country = Country::create([
'code' => 'DE', 'phone' => '49', 'en' => 'Germany', 'de' => 'Deutschland',
'es' => 'Alemania', 'fr' => 'Allemagne', 'it' => 'Germania', 'ru' => 'Германия',
]);
$shipping = Shipping::create(['name' => 'Standard', 'active' => true]);
ShippingPrice::create([
'shipping_id' => $shipping->id, 'price' => 4.90, 'price_comp' => 0, 'num_comp' => 0,
'tax_rate' => 19, 'weight_from' => 1, 'weight_to' => 100000,
]);
return ShippingCountry::create(['shipping_id' => $shipping->id, 'country_id' => $country->id]);
}
/**
* Ruft OrderController::performRequest direkt auf (Domain-Routing hat einen Catch-All,
* daher kein HTTP-Roundtrip). Liefert das dekodierte JSON-Payload zurück.
*
* @return array<string, mixed>
*/
function postCartUpdate(array $payload): array
{
$request = request();
$request->replace(array_merge([
'action' => 'updateCart',
'shipping_is_for' => 'abo-ot-customer',
'is_abo' => '1',
], $payload));
$request->headers->set('X-Requested-With', 'XMLHttpRequest');
$response = app(OrderController::class)->performRequest();
return $response->getData(true);
}
function findYardRows(int $productId, bool $addon): Collection
{
return Yard::instance('shopping')->search(function ($item) use ($productId, $addon) {
return (int) $item->id === $productId && (bool) ($item->options->abo_addon ?? false) === $addon;
});
}
beforeEach(function () {
$this->shippingCountry = makeOneTimeCartEnv();
$yard = Yard::instance('shopping');
$yard->destroy();
$yard->setShippingCountryWithPrice($this->shippingCountry->id, 'abo-ot-customer');
});
afterEach(function () {
Yard::instance('shopping')->destroy();
});
it('liefert das Einmal-Sortiment (show_on 3) für Abo-Zusatzartikel', function () {
expect(ProductOrderContext::oneTimeShowOnIds())->toBe(['3']);
});
it('legt mit abo_addon=1 eine getrennte Einmal-Cart-Zeile an', function () {
$product = makeProduct(['3'], 25.50, 19);
$result = postCartUpdate(['product_id' => $product->id, 'qty' => 2, 'abo_addon' => 1]);
expect($result['response'])->toBeTrue();
$rows = findYardRows($product->id, true);
expect($rows)->toHaveCount(1)
->and((int) $rows->first()->qty)->toBe(2)
->and((bool) $rows->first()->options->abo_addon)->toBeTrue();
});
it('hält Abo-Zeile und Einmal-Zeile desselben Produkts getrennt', function () {
$product = makeProduct(['3', '12'], 90, 19);
postCartUpdate(['product_id' => $product->id, 'qty' => 1]);
postCartUpdate(['product_id' => $product->id, 'qty' => 3, 'abo_addon' => 1]);
$aboRows = findYardRows($product->id, false);
$addonRows = findYardRows($product->id, true);
expect($aboRows)->toHaveCount(1)
->and((int) $aboRows->first()->qty)->toBe(1)
->and($addonRows)->toHaveCount(1)
->and((int) $addonRows->first()->qty)->toBe(3)
->and($aboRows->first()->rowId)->not->toBe($addonRows->first()->rowId);
});
it('lehnt ein Normalsortiment-Produkt ohne abo_addon-Flag im Abo-Cart weiter ab', function () {
$product = makeProduct(['3'], 25.50, 19);
$result = postCartUpdate(['product_id' => $product->id, 'qty' => 1]);
expect($result['message'] ?? null)->toBe(__('msg.cart_product_not_allowed_for_order_type'))
->and(Yard::instance('shopping')->content())->toHaveCount(0);
});
it('lehnt ein reines Abo-Produkt als Einmal-Artikel ab', function () {
$product = makeProduct(['12'], 90, 19);
$result = postCartUpdate(['product_id' => $product->id, 'qty' => 1, 'abo_addon' => 1]);
expect($result['message'] ?? null)->toBe(__('msg.cart_product_not_allowed_for_order_type'))
->and(Yard::instance('shopping')->content())->toHaveCount(0);
});
it('entfernt mit qty=0 nur die Einmal-Zeile, die Abo-Zeile bleibt', function () {
$product = makeProduct(['3', '12'], 90, 19);
postCartUpdate(['product_id' => $product->id, 'qty' => 1]);
postCartUpdate(['product_id' => $product->id, 'qty' => 2, 'abo_addon' => 1]);
postCartUpdate(['product_id' => $product->id, 'qty' => 0, 'abo_addon' => 1]);
expect(findYardRows($product->id, true))->toHaveCount(0)
->and(findYardRows($product->id, false))->toHaveCount(1);
});