# Advanced Promotions

**Installation of Spurtcommerce Advanced Promotions Add-On**

**you can install this Add-on through following steps**

step 1: [<mark style="color:blue;">Setup an API (Step By Step)</mark> ](#setup-an-api-step-by-step)to add extension for admin

step 2: [<mark style="color:blue;">Admin setup</mark>](#admin-setup)

step 3: you can easily install admin storefront with[ <mark style="color:blue;">store setup</mark><mark style="color:blue;">**.**</mark> ](#store-setup)spurtcommerce provides 3 admin storefronts, built with [<mark style="color:blue;">Angular,</mark>](#store-setup) [<mark style="color:blue;">Flutter</mark>](#store-setup) and [<mark style="color:blue;">React.</mark>  ](#store-setup)

**About Addon :**

The Installation of Spurtcommerce Promotions add-on will enable the feature of creation of various promotions for the admin. When the plugin is installed, the multi-Vendor eCommerce site becomes ready for the admin to post promotions and get them displayed for the visitors to view.

**Features**&#x20;

* You can create promotions such as ‘Hot summer offer’ or ‘Christmas sale’, etc.
* &#x20;Easily map certain selected products to the promotions that they create.&#x20;
* Also, you may map one whole category for the promotions that they create. &#x20;
* provide an attractive title for that promotion. E.g., stylish women deal.&#x20;
* Define the position of the promotion for displaying it on the home page.

#### [<mark style="color:blue;">**Setup an API (Step By Step)**</mark>](#setup-an-api-step-by-step)

For setting up the API, you need to execute the following steps:

* Installing an extension&#x20;
* Run the application
* &#x20;Make the build

**Step 1 :** **Installing an extension**&#x20;

These are the steps that need to be executed for installation of the extension.

Usually spurcommerce comes packed in a zip, whose name ends in "promotions-addOn.zip".&#x20;

Extract the zip file and copy the content of api folder into the specified path

```
Path - <PROJECT_ROOT>/addon
```

**Step 2 : Run the application**

After you have completed the installation of the above mentioned steps, you can run the application and also view the changes

```
$ npm start serve
```

Once you execute the above command, add-on file will get integrated into the backend API.

**Step 3 : Make the build**&#x20;

These are the steps that need to be followed for generating the build.

To run the below command

```
$ npm run build
```

Then latest built files can be deployed into the server.

### [<mark style="color:blue;">**Admin Setup**</mark>](#admin-setup)

These are the steps that need to be followed to do the front end admin setup.

* Installing an extension&#x20;
* Update the configuration&#x20;
* Module Detail&#x20;
* Run the application&#x20;
* Make the build

**Step 1 : Installing an extension**

These are the steps that need to be executed for installation of the extension.

Usually spurtcommerce comes packed in a zip, whose name ends in "<mark style="color:green;">**promotions.addOn.zip"**</mark>.

Extract the zip file, open api folder and open addon folder within that and copy the content of addon folder into the specified path.

&#x20;                                                 **Path - \<PROJECT\_ROOT>/addon**

**Note**:

* &#x20;In addon folder if already a cms folder exists, Inside cms folder paste Widget-list and Widgets-layout folder. In cms routing file(cms.routing.ts) paste the below code.

```
export const cmsWidgetRoutes = [
    {
      path: 'widgets',
      loadChildren: () => import('./widgets/template/widget-list/widgets.module').then(m => m.WidgetsModule),
      canActivate: [AuthGuard],
      data: { permissionForHeader: 'cms-widgets', root: 'cms' }
    },
  ];


```

* In addon folder if cms folder doesn’t exists. Paste the cms folder in addon.

**Step 2 : Update the configuration**&#x20;

After the installation of the extension, you will have to update certain configurations into the default Spurtcommerce config files. For this, you need to follow the steps below.

1. **Update Reducer Config**

Import below line into the <mark style="color:green;">**add-ons/add-ons-reducer.ts**</mark>

```
 import * as fromWidgetList from 
  '../addon/cms/widgets/core/widget-reducer/widget.reducer'

```

&#x20;2\. **Add the reducer into the below object**

```
 widgetList: fromWidgetList.reducer
```

&#x20;3\. **After adding its looks like below**

```
export const AddOnReducers: ActionReducerMap<State> = {
     widgetList: fromWidgetList.reducer
};
```

&#x20;**Update State Config**

* &#x20;Import below line into the <mark style="color:green;">**add-ons/add-ons-state.ts**</mark>

```
Import {WidgetState}  
   ../addon/cms/widgets/core/widget-reducer/widget.state';

```

* Add the state into the below object

```
     widgetList:WidgetState;
```

* After adding its looks like below

```
export interface AddOnAppState {
   widgetList:WidgetState;
}


```

**Step 3** : Change the routing file<mark style="color:green;">**(cms.routing.ts)**</mark> Inside the <mark style="color:green;">**src/theme/default/admin/cms/cms.routing.ts**</mark>

* Import below line

```
import * as CmsRouting from '../../../../../addon/cms/blogs/cms.routing';
```

* Add these routes below the cmsRoutes array

```
cmsRoutes.forEach(data => {
  if (data && data.children) {
    console.log('data is',data.children);
    data.children.push(CmsRouting.cmsWidgetRoutes[0]);
  }
});

```

**Step 4 : Run the application**

After you have integrated the Widgets Module into Spurtcommerce, you can use the following command to run the application.

```
$ npm run large-serve
```

Once you execute the above command you can view the installed module in Spurtcommerce, within the page in which you have integrated.

**Step 5 : Make the build**

To run the below command

```
$ npm run large-build
```

Then the latest built files can be deployed into the server.

### [<mark style="color:blue;">store setup</mark>](#store-setup)

{% tabs %}
{% tab title="Angular" %}

These are the steps that need to be followed to do the front end store setup.

* Installing an extension&#x20;
* Update the configuration&#x20;
* Module Detail&#x20;
* Run the application&#x20;
* Make the build

**Step 1 : Installing an extension**

These are the steps that need to be executed for installation of the extension.

&#x20;Usually spurcommerce comes packed in a zip, whose name ends in "promotions.addOn.zip".&#x20;

&#x20;          Extract the zip file and copy the content of store-angular/add-ons folder into the specified path

**Path -  store-angular/add-ons**

<br>

<br>

**Step 2 : Update the configuration**&#x20;

After the installation of the extension, you will have to update certain configurations into the default Spurtcommerce config files. For this, you need to follow the steps below.

**Update Reducer Config**

* Import below line into the <mark style="color:green;">**add-ons/add-ons-reducer.ts**</mark>

```
 import * as fromWidgetListAndProduct from 
 './WidgetAndProduct/core/reducer/widgetListAndProduct.reducer' 
```

* **Add the reducer into the below object**

```
 widgetListAndProduct: fromWidgetListAndProduct.reducer

```

* **After adding its looks like below**

```
 export const AddOnReducers: ActionReducerMap<State> = {
                   widgetListAndProduct: fromWidgetListAndProduct.reducer
                                  }

```

**Update State Config**

* Import below line into the <mark style="color:green;">**add-ons/add-ons-state.ts**</mark>

```
 import { WidgetListAndProductState } from   
 './WidgetAndProduct/core/reducer/widgetListAndProduct.state';

```

* Add the state into the below object

```
        widgetListAndProduct:WidgetListAndProductState
```

* After adding its looks like below

```
      
     export interface AddOnAppState {
                             widgetListAndProduct:WidgetListAndProductState
                           }
```

**Update Effect Config**

* Import below line into the <mark style="color:green;">**add-ons/add-ons.effect.ts**</mark>

```
 import { WidgetListAndProductEffect } from                                                       
 './WidgetAndProduct/core/effects/widgetListAndProduct.effect';

```

* Add the effect into the below object

```
 WidgetListAndProductEffect

```

* After adding its looks like below

```
export const ADD_ON_EFFECT = [
    WidgetListAndProductEffect
 ];

```

**Update Component Config**

* Import below line into the add-ons/add-ons.shared.component

```
import { WidgetProductsComponent } from 
'./WidgetAndProduct/template/widget-products/widget-products.component';

```

* Add the following components into the below object

```
 WidgetProductsComponent
```

* After adding its looks like below

```
 export const ADD_ON_COMPONENTS = [
  WidgetProductsComponent
                                   ];
```

**Step 3 : Module Detail**

The modules pertaining to widgetlist and widgetproducts are listed below. You may use these modules, in any page of Spurtcommerce.

Also, you can find the steps below to use the modules in WidgetList and WidgetProducts in Spurtcommerce pages.

In the WidgeAndProducts addon having two components.&#x20;

&#x20;      1.WidgetProductsComponent

&#x20;       2.WidgetListComponent

**WidgetProductComponent**

```
Directive 
<app-widgets-products class="top-sell-prd" [productType]="'today deals'">
</app-widgets-prodWidgetProductComponentucts>

```

In the above directive have one input field

```
                  productType:String
```

**WidgetListComponent**&#x20;

This is a one page component. You can configure the route for this component. This component only works with widgetId ,because after clicking viewall link in home page then only the user can view widgetlist The route for this component:

```
Syntax:
				
{
    path: '', component: WidgetListComponent, pathMatch: 'full', data: {
      urls: [
        { title: 'Widget List', url: '/widget-list' },
      ]
    }
  },

```

Update Default routing file<mark style="color:green;">**(default.routing.ts)**</mark> Inside the <mark style="color:green;">**src/default/default.routing.ts**</mark>

* **Import below line**

```
  import * as widgetRoutes from 
  'add-ons/WidgetAndProduct/template/widget-list/widget-list.routing';

```

* **Add the blog routes in below the routes array**

```
routes.forEach(data => { 
                           if (data && data.children) {
                            console.log('data is',data.children);
                            data.children.push(widgetRoutes.widgetRoutes[0]);
                           }
                         });

```

**Step 4 : Run the application**

After you have integrated the WidgetList and WidgetProduct Module into Spurtcommerce, you can use the following command to run the application.

```
$ ng serve
```

Once you execute the above command you can view the installed module in Spurtcommerce, within the page in which you have integrated.

**Step 5 : Make the build**

To run the below command

```
$ ng build –prod
```

Then the latest built files can be deployed into the server.
{% endtab %}

{% tab title="Flutter" %}

These are the steps that need to be followed to do the front end store setup.

* Installing an extension&#x20;
* Update the configuration&#x20;
* Module Detail&#x20;
* Run the application&#x20;
* Make the build

**Step 1 : Installing an extension**

These are the steps that need to be executed for installation of the extension.

Extract the store-flutter folder  inside the folder go to (store-fluter → add-ons → WidgetsAndProducts folder) and copy the WidgetsAndProducts folder  and place the copied folder inside the project folder

**Add on location:**

projectFolder->lib->add-ons

**After placing it it will look like this**

projectFolder->lib->add-ons->WidgetsAndProducts

<br>

Once you finish these steps continue to the next step

**Step 2 : Update the configuration**

After extracting the add on zip file for changing the configurations in addons.dart, you have to follow the steps below:

**Go to**

<mark style="color:green;">**projectFolder->lib->add-ons->addonsshared.dart**</mark>

Then inside addonsShared array paste the following content

```
{"WidgetLists": SpurtWidgetList(), "data": ""},
```

After placing the above files it will look like this

```
List addonsShared = [
{"WidgetLists":Spurt WidgetList(), "data": ""},
];
```

Then give the following imports import 'package:spurtcommerce/addons/WidgetsAndProducts/widgetlists.dart';

Or&#x20;

There will be a popup for quick fix

Step 3 : Module detail

After executing the above mentioned steps, we have to place these below lines in the core folder to show the question and answer to the user.

WidgetLists Once you finished updating the configuration then in the *projectFolder->lib->main.dart* file update this line where you seem comfortable with

```
findMyClass("WidgetLists", {
"list": true
         }),
```

**Step 4 : Run the application**

After integrating the Rating and Review Module into Spurt Commerce, you can use the following commands to run the application in terminal.

```
$ flutter run
```

Or In **Run** menu select run without debugging In case if throws any exception

```
$ flutter run –no-sound-null-safety
```

Once you execute the above command you can view the installed module in Spurt Commerce, within the page in which you have integrate&#x64;**.**

**Step 5 : Make the build**&#x20;

In order to build, you need to run the following commands. In order to check the application, run the following commands and build the application.

```
$flutter build
```

If you want to split the abi then

```
$flutter build –split-per-abi
```

For bundle build

```
$flutter build appbundle
```

\ <br>
{% endtab %}

{% tab title="React" %}

These are the steps that need to be followed to do the front end store setup.

* Installing an extension&#x20;
* Update the configuration&#x20;
* Run the application&#x20;
* Make the build

**Step 1 : Installing an extension**&#x20;

These are the steps that need to be executed for installation of the extension.

<br>

Usually spurcommerce comes packed in a zip, whose name ends in "promotions-addOns.zip". Extract the zip file and copy the content of store-react/addOns into the specified path as given below&#x20;

**Path - addOns/WidgetsAndProducts**\
\
**Add on location:**

projectFolder-> addOns

**After placing it it will look like this**

projectFolder->addOns-> WidgetsAndProducts

**Step 2 : Update the configuration**

After the installation of the extension, you will have to update certain configurations into the default Spurtcommerce addonsconfig.js files. For this, you need to follow the steps below.

\
Once you finish the first Step now declare the necessary plugins in the addonconfig.js file

* **Import below line into the addonconfig.js**

```
import SpurtWidgetsAndProducts from './WidgetsAndProducts/Allwidgets'
```

```
import SpurtWidgetViewAll from './WidgetsAndProducts/widgetViewAll'

```

* **Add the SpurtWidgetsAndProducts plugin into the below object**<br>

```
export const AddonsComponent={
          	SpurtWidgetsAndProducts
           SpurtWidgetViewAll    
}
```

**Step 3 : Module Detail**

The modules pertaining to widgets are listed below. You may use these modules, in any page of Spurtcommerce.

\
&#x20;                     **SpurtWidgetsAndProducts Component:**

&#x20;     **{ConnectPlugin.SpurtWidgetsAndProducts &&        \<ConnectPlugin.SpurtWidgetsAndProducts />}**

**SpurtWidgetViewAll Component:**

**{ConnectPlugin.SpurtWidgetViewAll && \<ConnectPlugin.SpurtWidgetViewAll widgetId={widget} />  }**&#x20;

<br>

**Step 4 : Run the application**

After you have integrated the SpurtWidgetsAndProducts Module into Spurtcommerce, you can use the following command to run the application.

```
$ npm run dev
```

Once you execute the above command you can view the installed module in Spurtcommerce, within the page in which you have integrated.

**Step 5 : Make the build**

To run the below command

```
$ npm run build or yarn run build
```

Then the latest built files can be deployed into the server.<br>
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spurtcommerce.com/addons/marketing-related-addons/advanced-promotions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
