File

src/converter/link-factory/fs-link-factory.ts

Description

This factory handles FirstSpirit links.

Index

Methods

Constructor

constructor(semanticPathService: SemanticPathService, productService: ProductService)
Parameters :
Name Type Optional
semanticPathService SemanticPathService No
productService ProductService No

Methods

Public createUrl
createUrl(templateUid: string, link: FsSearchLinkTemplate | FsProductLinkTemplate | FsCategoryLinkTemplate | FsContentLinkTemplate)

This method creates link metadata based on links from FirstSpirit. For this, it is used to transform the link metadata from FirstSpirit to metadata readable by Spartacus.

Parameters :
Name Type Optional Description
templateUid string No

The UID of the given link template.

link FsSearchLinkTemplate | FsProductLinkTemplate | FsCategoryLinkTemplate | FsContentLinkTemplate No

The FirstSpirit metadata for the link to be created.

Returns : LinkData

The transformed link which is returned.

import { Injectable } from '@angular/core';
import { ProductService, SemanticPathService } from '@spartacus/core';
import { LinkData } from '../teaser/fs-teaser.model';
import { FsCategoryLink } from './fs-category-link';
import { FsContentLink } from './fs-content-link';
import {
  FsSearchLinkTemplate,
  FsCategoryLinkTemplate,
  FsContentLinkTemplate,
  FsLinkFactoryInterface,
  FsProductLinkTemplate,
} from './fs-link.model';
import { FsProductLink } from './fs-product-link';
import { FsSearchLink } from './fs-search-link';

/**
 * This factory handles FirstSpirit links.
 */
@Injectable({ providedIn: 'root' })
export class FsLinkFactory {
  constructor(private semanticPathService: SemanticPathService, private productService: ProductService) {}

  /**
   * This method creates link metadata based on links from FirstSpirit.
   * For this, it is used to transform the link metadata from FirstSpirit to metadata readable by Spartacus.
   *
   * @param templateUid The UID of the given link template.
   * @param link The FirstSpirit metadata for the link to be created.
   * @return The transformed link which is returned.
   */
  public createUrl(
    templateUid: string,
    link: FsSearchLinkTemplate | FsProductLinkTemplate | FsCategoryLinkTemplate | FsContentLinkTemplate
  ): LinkData {
    let url: FsLinkFactoryInterface<any>;

    switch (templateUid) {
      case 'search_link':
        url = new FsSearchLink(link as FsSearchLinkTemplate, this.semanticPathService);
        break;

      case 'product_link':
        url = new FsProductLink(link as FsProductLinkTemplate, this.productService);
        break;

      case 'category_link':
        url = new FsCategoryLink(link as FsCategoryLinkTemplate, this.semanticPathService);
        break;

      case 'content_link':
        url = new FsContentLink(link as FsContentLinkTemplate, this.semanticPathService);
        break;

      default:
        console.warn(
          `No overlay implementation was found for the template '${templateUid}'! Please extend the FsTeaserOverlayFactory and add an implementation for this template uid`
        );
    }

    if (url != null) {
      return url.create();
    }
  }
}

results matching ""

    No results matching ""