You are here

public function BulkCloneProduct::execute in Entity Bulk Clone 8

Executes the plugin.

Overrides ExecutableInterface::execute

1 call to BulkCloneProduct::execute()
BulkCloneProduct::executeMultiple in src/Plugin/Action/BulkCloneProduct.php
Executes the plugin for an array of objects.

File

src/Plugin/Action/BulkCloneProduct.php, line 58

Class

BulkCloneProduct
Entity Bulk clone of commerce product.

Namespace

Drupal\entity_bulk_clone\Plugin\Action

Code

public function execute($entity = NULL) {

  /** @var \Drupal\commerce_product\Entity\ProductInterface $entity */
  $replicator = \Drupal::service('replicate.replicator');
  $duplicate_entity = $replicator
    ->replicateByEntityId($entity
    ->getEntityTypeId(), $entity
    ->id());
  $title = $duplicate_entity
    ->getTitle();
  $duplicate_entity
    ->setTitle($title . ' - Bulk Cloned');
  $request_time = \Drupal::time()
    ->getRequestTime();
  $duplicate_entity
    ->setChangedTime($request_time);
  $duplicate_entity
    ->save();
}