You are here

public function CommerceSmartImporerService::createProductRedirection in Commerce Smart Importer 8

Add redirections that will lead to product.

2 calls to CommerceSmartImporerService::createProductRedirection()
CommerceSmartImporerService::createNewProduct in src/Plugin/CommerceSmartImporerService.php
Creates product.
CommerceSmartImporerService::updateProduct in src/Plugin/CommerceSmartImporerService.php
Updates entity with given values.

File

src/Plugin/CommerceSmartImporerService.php, line 1529
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function createProductRedirection(Product $product_object, array $redirections) {
  $url = 'internal:' . $product_object
    ->toUrl()
    ->toString();
  foreach ($redirections as $redirection) {
    if (empty($redirection)) {
      continue;
    }
    if ($redirection[0] == '/') {
      $redirection = substr($redirection, 1);
    }
    Redirect::create([
      'redirect_source' => $redirection,
      'redirect_redirect' => $url,
      'language' => 'und',
      'status_code' => '301',
    ])
      ->save();
  }
}