# Release Notes - Product Rounding Feature

**Date:** February 20, 2026  
**Feature:** Product Rounding for Romanian Plugin  
**Type:** Enhancement

---

## Overview

This release introduces a new configuration option that enables automatic product price rounding for the Romanian (RON) installment calculator. This feature ensures that product prices are always rounded up to the nearest value divisible by 5 before querying the installment rate table, resolving cases where products with prices not matching exact table values (e.g., 263 RON) would fail to display installment options.

---

## Problem Statement

The installment rate table contains values starting at 250 RON and increases in increments of 5 RON (250, 255, 260, 265, etc.). When a product price does not exactly match one of the values in the table (for example, 263 RON), the calculator does not display.

**Example of the issue:**
- Product price: 263 RON
- Issue: Calculator fails to appear because this value does not exist in the installment table
- Solution: Price is automatically rounded up to 265 RON to match table values

---

## What's New

### Product Rounding Configuration

**Location:** `Stores → Configuration → Sales → Payment Methods → Leanpay Installment price`

A new admin configuration field **"Enable Product Rounding"** has been added to control automatic price rounding behavior.

**How it works:**
- When enabled, product prices are automatically rounded **up** to the nearest value divisible by 5 before retrieving installment estimates
- Example: A product priced at 263 RON will be rounded to 265 RON to match the installment table values (250, 255, 260, 265, etc.)
- This feature **only applies to the Romanian (RON) plugin** and does not affect Slovenian or Croatian implementations

**Default behavior:** Disabled (opt-in feature)

---

## Technical Details

### Affected Components

- **Admin Configuration:** New field added to `etc/adminhtml/system.xml`
- **Helper Class:** `Helper/InstallmentHelper.php` - Added rounding logic
- **Methods Updated:**
  - `getLowestInstallmentPrice()` - Applies rounding before installment lookup
  - `getInstallmentList()` - Applies rounding before installment lookup  
  - `getToolTipData()` - Applies rounding before tooltip data retrieval

### Rounding Logic

The rounding algorithm uses ceiling division to always round up:
- Formula: `ceil(price / 5) * 5`
- Examples:
  - 263 RON → 265 RON
  - 252 RON → 255 RON
  - 250 RON → 250 RON (no change)
  - 251 RON → 255 RON
  - 249 RON → 250 RON

### Implementation Details

- Rounding is applied only when:
  1. Feature is enabled in admin configuration
  2. API endpoint type is Romanian (`API_ENDPOINT_ROMANIA`)
- Rounding occurs before database queries to ensure matching table values
- Original product price remains unchanged; rounding is only applied for installment calculations

---

## Configuration

### Enabling Product Rounding

1. Navigate to **Stores → Configuration → Sales → Payment Methods**
2. Expand **"Leanpay Installment price"** section
3. Set **"Enable Product Rounding"** to **"Yes"**
4. Save configuration
5. Clear cache if needed: `php bin/magento cache:clean`

### Scope

- Configuration is available at **Store View**, **Website**, and **Default** levels
- Can be configured independently per store/website
- Default value: `0` (disabled)

---

## Impact

### Benefits

- ✅ Ensures installment calculator displays for all eligible products within supported price range
- ✅ Resolves issue where products with prices not matching exact table values would fail to show installment options
- ✅ Maintains backward compatibility (disabled by default)
- ✅ Only affects Romanian plugin, preserving existing behavior for other regions
- ✅ No database schema changes required

### Compatibility

- ✅ Fully backward compatible
- ✅ No database schema changes required
- ✅ No impact on existing functionality when disabled
- ✅ Slovenian and Croatian plugins remain unaffected
- ✅ No breaking changes

---

## Testing Recommendations

### 1. Test with rounding disabled (default)
- Verify existing behavior remains unchanged
- Confirm calculator works for products with exact table values (250, 255, 260, etc.)
- Test products with non-matching prices (e.g., 263 RON) - should not display calculator

### 2. Test with rounding enabled
- Test product with price 263 RON → should round to 265 RON and display calculator
- Test product with price 252 RON → should round to 255 RON and display calculator
- Test product with price 250 RON → should remain 250 RON (no change)
- Test product with price 251 RON → should round to 255 RON
- Test product with price 249 RON → should round to 250 RON
- Verify calculator displays correctly for all test cases

### 3. Test multi-store/website
- Verify configuration can be set independently per store
- Confirm rounding only applies when enabled per store
- Test that Romanian store with rounding enabled works correctly
- Test that Slovenian store remains unaffected

### 4. Test other plugins
- Verify Slovenian plugin behavior unchanged
- Verify Croatian plugin behavior unchanged
- Confirm rounding logic only executes for Romanian API endpoint

### 5. Edge cases
- Test minimum price (250 RON) - should work correctly
- Test prices just below minimum - should not round below minimum
- Test maximum price - verify rounding doesn't exceed max order total

---

## Files Changed

```
app/code/Leanpay/Payment/
├── etc/
│   ├── adminhtml/
│   │   └── system.xml                    # Added "Enable Product Rounding" field
│   └── config.xml                        # Added default configuration value
└── Helper/
    └── InstallmentHelper.php             # Added rounding logic and methods
```

### Code Changes Summary

**New Methods:**
- `roundUpToNearestFive(float $price): float` - Private method for rounding logic
- `applyProductRounding(float $price): float` - Private method that applies rounding conditionally

**Modified Methods:**
- `getLowestInstallmentPrice()` - Now applies rounding before lookup
- `getInstallmentList()` - Now applies rounding before lookup
- `getToolTipData()` - Now applies rounding before lookup

**New Constants:**
- `LEANPAY_INSTALLMENT_ENABLE_PRODUCT_ROUNDING` - Configuration path constant

---

## Migration Notes

### For Existing Installations

No migration required. The feature is enabled by default and can be disabled via admin configuration.

### Upgrade Steps

1. Deploy updated code files
2. Clear Magento cache: `php bin/magento cache:clean`
3. (Optional) Enable feature in admin configuration if needed

---

## Known Limitations

- Rounding only applies to Romanian (RON) plugin
- Rounding always rounds up
- Feature must be explicitly enabled in admin configuration

---

--

## Related Documentation

- Admin Configuration Guide: `Stores → Configuration → Sales → Payment Methods → Leanpay Installment price`
- Romanian Installment Table: Values increment by 5 RON starting from 250 RON
