init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Cart\Model\Config\Backend;
|
||||
|
||||
use Magento\Framework\App\Config\Value;
|
||||
|
||||
/**
|
||||
* Normalizes the admin SKU list while preserving its display order.
|
||||
*/
|
||||
class RecommendedProductSkus extends Value
|
||||
{
|
||||
/**
|
||||
* Normalize commas and line breaks to one unique SKU per line.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function beforeSave()
|
||||
{
|
||||
$skus = preg_split('/[\r\n,]+/', (string)$this->getValue()) ?: [];
|
||||
$skus = array_values(array_unique(array_filter(
|
||||
array_map('trim', $skus),
|
||||
static fn(string $sku): bool => $sku !== ''
|
||||
)));
|
||||
$this->setValue(implode("\n", $skus));
|
||||
|
||||
return parent::beforeSave();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user