You are here

protected function CommerceAutoSkuGeneratorBase::isUnique in Commerce AutoSKU 8.2

Validate if sku is unique.

Parameters

ProductVariationInterface $entity: Product Variation.

string $sku: SKU.

Return value

bool TRUE if SKU unique FALSE otherwise.

1 call to CommerceAutoSkuGeneratorBase::isUnique()
CommerceAutoSkuGeneratorBase::makeUnique in src/Plugin/CommerceAutoSkuGenerator/CommerceAutoSkuGeneratorBase.php

File

src/Plugin/CommerceAutoSkuGenerator/CommerceAutoSkuGeneratorBase.php, line 44

Class

CommerceAutoSkuGeneratorBase
Places an order through a series of steps.

Namespace

Drupal\commerce_autosku\Plugin\CommerceAutoSkuGenerator

Code

protected function isUnique(ProductVariationInterface $entity, $sku) {
  $entities = $this->entityTypeManager
    ->getStorage($entity
    ->getEntityTypeId())
    ->loadByProperties([
    'sku' => $sku,
  ]);
  if (!$entity
    ->isNew()) {
    unset($entities[$entity
      ->id()]);
  }
  return empty($entities);
}