protected function CommerceAutoSkuGeneratorBase::makeUnique in Commerce AutoSKU 8.2
1 call to CommerceAutoSkuGeneratorBase::makeUnique()
- CommerceAutoSkuGeneratorBase::generate in src/
Plugin/ CommerceAutoSkuGenerator/ CommerceAutoSkuGeneratorBase.php - Generates the SKU according to the settings.
File
- src/
Plugin/ CommerceAutoSkuGenerator/ CommerceAutoSkuGeneratorBase.php, line 53
Class
- CommerceAutoSkuGeneratorBase
- Places an order through a series of steps.
Namespace
Drupal\commerce_autosku\Plugin\CommerceAutoSkuGeneratorCode
protected function makeUnique(ProductVariationInterface $entity, $sku) {
// Strip tags.
$generated_sku = preg_replace('/[\\t\\n\\r\\0\\x0B]/', '', strip_tags($sku));
$output = $generated_sku;
$i = 0;
while (!$this
->isUnique($entity, $output)) {
$counter_length = mb_strlen($i) + 1;
$un_prefixed_max_length = 255 - $counter_length;
$sku = mb_strlen($generated_sku, 0, $un_prefixed_max_length);
$output = $sku . '_' . $i;
$i++;
}
return $output;
}