WEB SYSTEMS PRO
E-commerce platform
€69.80

* Net price (excluding VAT)

SKU:WSP-175-PL
License
Web Systems Pro
Version
4.44.3.0.wsp
Update
07/13/2023


How to calculate discounts/bonuses for products?

A discount (or bonuses) can be awarded in various ways. The most important thing you need to understand:

To set a discount (bonuses) for products, you must create a discount rule.

In the rest of the article, we will only talk about discounts, as all settings for bonuses are identical.

In the discount rule, you need to specify how the fee will be calculated:

  • using a discount rule
  • using a product field

Setting discounts (bonuses) using a rule

When creating a discount rule, you can specify the discount (bonuses) as a percentage or a fixed value:


Note that for a fixed value, there is a setting Set discount for each item.

If you do not check this field, the discount will be associated with the entire order, not with each product.

Assume you have chosen a discount of 3$ and have not checked this field. After purchasing 5 products, the discount will not be 15$, but 3$.

Setting discounts (bonuses) using a product field

You can set discounts (bonuses) in the product itself. To do this, in the discount rule, select the value Product field "Discount":


Specify conditions if necessary. As a target, for example, select All products meeting the conditions.

Next, in the administrative section, open the product for which you want to set a discount.

Inside the product, there is a general field Discounts (Bonuses):


You can specify the value as a percentage or in currency.

Additionally, the discount can be set individually for each sku. To do this, go to the sku settings and find the same field Discount.


Consider the specifics of filling out the Discount (Bonuses) fields for sku.

1) If the field remains empty, then the general discount value specified for the entire product will be applied.

2) If you enter 0, the discount for that sku will not be applied, despite the general value specified for the entire product.

3) If you enter a discount value and also a general discount value, then only the discount for that set will be applied.

The for all sku field, which is next to the general discount field, allows for quick changes to discounts for all sku. After saving, the discount values for all sku will be changed.

Import/Export

You can change discounts/bonuses for products using CSV import if you use Product field.

Fields in the CSV file:


These fields are available for both the product (table shop_product) and the sku (table shop_product_skus).


Discounted price on the carta page

If you want the discounted price to appear on the page carta, use a special construction in the theme cart.html


Example

In the theme, do:

1) Find the code in the theme cart.html:


2) After it, you can add any construction.

Examples of constructions

− Output price with discount


− Output comparison price


− Output discount


− Output comparison price with additional HTML

The block will be hidden if the price is zero. Add a CSS class, remove the loader.


− Output discount value for one product item (do not multiply quantity)

The block will not be hidden if the discount is zero. Change the block tag. Change the ruble sign.


By default app Shopy-Script changes prices on the carta. To prevent the replacement of the discounted price, do not insert the above constructions into blocks of the class: item-total or s-product-total.
You can also remove these classes.


Plugin Optimization

This guide is intended for people with basic knowledge of HTML, Smarty, PHP. The creator of plugins does not perform free optimization and profiling work.

Plugin "Flexdiscount" uses the hook frontend_products to change product prices. This hook, due to its functions, is very often called in theme and plugin projects. For example, in product collections, total price, total discount. Some of these dialogs can be optimized.

Here are a few conclusions that activate discount calculations:

Smarty:


PHP:


Each clearing of the session shop/cart will also lower the calculation in order to update the information in the queries above.

Below you will find a list of recommendations regarding the optimization of plugins "Flexdiscount", theme projects and external plugins. Take care of the user's convenience.

Optimization recommendations

1) Disable or remove the plugin.

This option will significantly improve performance, as plugin will no longer use server resources to create discount systems.

2) Disable the setting "Change product prices to discount prices".


This setting uses the hook frontend_products and is the most resource-intensive.

If you stop here and decide to disable it, all the recommendations below will not be relevant to you.

3) "Ignore price changes in plugin below".


This setting is located under the setting "Change product prices to discount prices". It disables requests from plugins through the hook frontend_products.

Disable (check the checkboxes) as many plugins as possible. Pay attention to the sum of discounts for products and orders. If you get incorrect calculations, it means you should not disable plugins.

Theme projects

4) Pay attention to requests in loops.

This is strictly forbidden!

If you find a similar construction in the theme, change it immediately:


It is better to take it out of the loop and use only the variable $products inside the loop:


5) Reduce the number of calls to the order sum, order discount and product collection.

You can find this construction really often in themes:


Use variables instead of many calls:


6) Optimization of the product collection.

Some calls {$wa->shop->products(...)} can be executed without obtaining current information about discounts. By default, each call calculates discounts for products. If you only need product features or its name, disable discount calculation.

Use the option no_plugins_frontend_products. For example, such a construct:


Can be replaced with the following elements:


Or:


Replace with:


Or:


Replace with:


This option should be given as the 4th argument.

PHP files

7) Optimization of the product collection.

Similar to point 6.

Use the following construct:


8) Use additional parameters plugins.

Plugin "Flexdiscount" has parameters that help disable discount calculation in the frontend_products hook, if it is not necessary.

Use the following parameter to disable discount calculation.


The parameter blocks the frontend_products hook.

Do not forget to enable the hook again, otherwise it may break other plugins.

Let's take an example:


9) Use the deny rule instead of "Not equal".

In discount rules, instead of conditions with the "not equal" operator (for conditions from the Product group), it is better to create a deny rule.

This recommendation is important if the number of products with the "equal" operator will be less than with the "not equal" operator.


Plugin allows you to get a full report of all connections. To do this, you must perform profiling. Based on the profiling report, it will be clear which recommendation should be applied and where.


Profiling

The instruction is intended for people with basic knowledge of HTML, Smarty, PHP. The creator of plugins does not perform free work related to optimization and profiling.

The profiling report allows you to detect all sources of Flexdiscount calls. This information will help you find all low-performance areas. By following the optimization recommendations, you will reduce the server load.

How to perform profiling?

1) Open the plugins settings and enable the profiling mode.


2) If necessary, edit the settings and save them.


3) Create a specific cookie in the browser.


You must create a cookie named fl-profiling-1588100398736.

Open the page where you want to perform profiling.

Open the developer tools in Chrome using the F12 key on the keyboard. Select the Application tab. In the sidebar, open Cookies and select your domain.


To create a cookie, you need to double-click on the empty white field located under all cookies. Then you will be able to specify the cookie name.


Next, press TAB and enter the value "1".


4) Reload the page where you want to perform profiling.

5) Open the Logs application and find the log file flexdiscount.profile.log.

We recommend deleting it after each profiling session if you do not want to be confused by the data.

Decoding the profile report

The plugin can be called from 3 sources:

  • Plugins
  • Methods
  • Themes

Profiling hooks:

  • frontend_products
  • order_calculate_discount

Plugin has 3 tracking points:

  • Before plugin validation
    Called before plugin validation. This determines whether plugin can continue processing or not. You can estimate how many claims are received by plugins.
  • After plugin validation
    Called after plugins validation. You can estimate how many plugins were passed for validation.
  • Calculation
    The most important point. Called after the discount is calculated.

Let's look at the report.

1) The first lines contain information about the time of the call and the page that was profiled:


In our case, it is the product page.

2) Next, we can see the hook that was called, the number of calls that passed through the points, and the time spent on processing.


Here you can estimate the main load on plugins.

We see that there were 3 queries for discount calculation (the "Calculation" point). It took 0.04 sec.

6.3419342041016E-5. It is 6.34*10-5 sec.

This is a good result. There is nothing to optimize here. But let's continue.

Next comes the description of the sources.

The output is represented by a tree structure:

  • "-" one dash. The source of the request.
  • "--" two dashes. The tracking point through which the request passed.
  • .
  • "---" three dashes. Service header (Connection Statistics), after which the connection history (connection) is detailed.
  • "----" four dashes. Service information. Connection number and time spent on its handling. Then the connection history is detailed.
  • "-----" five dashes. The connection that started the plugin to work at the tracking point. The number of such connections depends on the "Depth" setting in the profile settings. It may happen that there are fewer results. This occurs when the connection history was small.

Consider part of the report.

3)


We can conclude that the call came from the method shopFrontendProductAction->prepareProduct(). This is a system method of the Shopy-Script application. We cannot change it.

It passed through all points only once. It was preceded by a chain of calls starting from waEvent->runPlugins().

4)


Plugin Badges was the next source. It tried to call the plugin twice, but did not bypass the first point. Plugin Flexdiscount filtered it out.

It is visible that the main reason for the invocation was the method shopCartItemsModel->getByCode() using the method shopCart->items(), which was invoked by the Badges plugin. If we refer to the article Optimization, on the list of queries we will find the method: (new shopCart())->items() - which activates the calculation of discounts.

5)


The next source is the plugin Flexdiscount. We will skip this part of the report, because the calls are system calls.

6)


Plugin Promos was also filtered.

7) Then we will only consider the point Calculation, because it is the most important.


Plugin was called twice from the product.html theme:

  • when displaying the list of recommended products: shopProduct->upSelling()
  • when retrieving the list of cross-selling products: shopProduct->crossSelling()

Find this call in the theme:


8)


The hook order_calculate_discount (main hook for calculating discounts) was called only once by the Promos plugin. It took 4.79*10-5 sec. All subsequent calls to this hook were not registered, because the plugin Flexdiscount buffered the results and did not perform any calculations.


In this way, we have seen all the calls to plugins discount. We can only disable the setting "Change product prices to discount prices" to optimize the plugin. This means that there will be no calls from 2 to 7 paragraph. Only the call order_calculate_discount will remain. How necessary this is depends on you.


Discounted price in notifications


In notifications sent to users after successfully proceeding to checkout, we can display the discounted prices of products.

Let's look at the notification "Order Placed (Customer)". Go to the page


Work is required between this construction:


1) Change the price of each product. Find the construction:


It changes to the following:


2) Change the total price of each product. Find the construction:


It changes to the following:


Affiliate bonus in notifications


In the notifications sent to users after successfully proceeding to the checkout, we can display the affiliate bonus with plugins Flexdiscount.

Look at the notification "Order placed (Customer)". Go to the page


1) Find the construction:


BEFORE building add the code:


Badges


For each discount rule, you can set a badge that will appear on the catalog or product page.

The starting point depends on the theme project, as plugin uses standard functionality to display badges.

How can I pull out a badge?

  1. Enable the option "Change product prices to discount prices".


  2. Copy the text "Custom badge". Open "Shop -> Products". In the right sidebar, find "Badge - Custom". Copy the text


  3. Paste the badge text in any promotion


After completing all the steps, the badges will appear on the catalog and product pages.


Discount limit on products


You can limit the discount for each product individually or generally.

On the discount page, you will find the setting "Discount limit on product".

On the discounts page, you can find the setting "Discount limit on product". Activate it.

General

Select the "Formula" field. You will see how the discounted price will be limited.


Let's read the formula: The price of the product with the discount plugin will never be lower than the value "Purchase price + 5% of the purchase price".

Let's assume we have a product:

Price - $1000,
Purchase price (PP) - $500,
Discount - 60% of the product price.

We assume that the discount will be $600, and the product price will be $400.

According to the restrictions, the discounted product price will be $525.

Formula = PP + 5%*PP = 500 + 500 * 0.05 = $525 - the product price will never be lower than the specified value.

Individual discount limit

Select the "Product field".


Go to the Products tab, select any product, try to edit it. In the "Basic data" tab, you will find the "Minimum price" field.


Enter the value, make sure to check "for all sku", click save.

The minimum price will be set for each sku.


You can customize each sku.

NOTE! Plugin uses only sku values. Use the product field with the minimum price only to specify the value for all sku.

Import/Export

You can use import/export to change the minimum price value.

For sku use the fields:

- flexdiscount_minimal_discount_price - minimum price value. Must be numeric.
- flexdiscount_minimal_discount_currency - currency. 3 symbols.


Displaying available discounts using deny rules


Important! This setting does not affect deny rules. A product that should not have a discount will not receive it in any settings. This article is only about displaying the Available discounts block when using deny rules.

When using deny rules, you may find the Available discounts block in products that should not have discounts. On the cart page, these products will not have any discounts. Depending on your discount policy, this may or may not be appropriate.

To determine when to display the Available discounts block and when not to, there is a setting "Ignore conditions in deny rules".


Using this setting, you can choose which conditions to ignore in deny rules when showing available discounts. There are 3 groups of conditions:

  • Product conditions
  • Product properties conditions
  • cart conditions

See example.

Discount rule:


Deny rule:


The deny rule has a condition from the "Product properties" group (price condition).

Thanks to these settings, the product page will look similar to this:


The product will not receive any discount, but it will have the Available discounts block.

Change the settings


Product properties will not be ignored. In this case, the product will not have the Available discounts block, because the product will not pass the price validation.



How to create a package discount?


How does it work?

  1. Select the type of products that will be in the package and specify their quantity.
  2. Plugin filters products carta and tries to gather the package. If the products are sufficient to create the package, then plugin will count the package quantity.
  3. Depending on the specified goals, discounts will be set based on the number of packages.

How to create a package?

  1. Select that you intend to create a package from conditions.
    Settings packages - plugin Flexdiscount


  2. Notice that the background color of the condition block has changed. This is done for your convenience to understand that you are working with packages.

    - binding mode is active:
    Package mode is active - plugin Flexdiscount



    - Shared mode:
    Shared mode - plugin Flexdiscount


  3. Some packages are highlighted.

    Only highlighted conditions facilitate filtering products for the package. The rest are auxiliary.

    Some conditions, which have been noted - plugin Flexdiscount


    List of conditions that must be met by packages:

    • Quantity of product (you need to specify which product).
    • Quantity of all products from the category.
    • Quantity of all products from the category and subcategory.
    • Quantity of all products from the set.
    • Quantity of all products from the type.
    • Quantity of products with features.
  4. Each new product from the package must be created in a separate group of conditions.
    Group of conditions - plugin Flexdiscount


    Example of a package - plugin Flexdiscount


    In the above example, the set consists of 3 units of product 1, 2 units from the Promo set, 4 units from the Jewelry category.

Examples

Example 1

Imagine that our package should consist of the following structure: product A - 3 units, product B - 2 units, product C - 1 unit. Briefly: 3A + 2B + 1C

Consider the situation when:

a) The discount is set only for the package.

Example of a package discount goal - plugin Flexdiscount


b) The discount is set for a product that is not included in the package.

Example of a product discount goal - plugin Flexdiscount


  • Create a discount rule
    Example of a product discount goal - plugin Flexdiscount


  • Imagine that cart consists of products: 7A + 6B + 3C + 5D
  • How many packages are in cart?
    The correct answer is 2. Because 2 * (3A + 2B + 1C) = 6A + 4B + 2C
    Why not 3 packages? Because we need 9 units of product A, which is impossible in our case.
  • What will the discount be?
    a) If the discount is set only for the package. In this case, the discount will be set for products 6A + 4B + 2C
    b) If the discount is set for a product that is not included in the package. In this case, the discount will be set for products 2D, because there are 2 packages in cart.

Example 2

We need to set a discount on the package: Jacket, Pants, Raincoat. Some products are in the same categories, some are not. The only difference is the features of these products:

Product type


Discount rule:

Example (2) rule for package discount - plugin Flexdiscount


Example 3

Buy any smartphone, and you will receive any accessories as a gift. Buy 1 smartphone - receive 1 accessory for free, buy 2 smartphones - receive 2 accessories for free.

Discount rule:

Example (3) rule for package discount - plugin Flexdiscount



Character of conditions "Does it have active rules with discounts/affiliates?"


Conditions Has active discount rules and Has active affiliate rules check the rules that are before them.

Rule checking method


The above image highlights the rules that will be checked for discounts.

If you create another group:


In case of moving the rule outside the group


Basic points:

1) If a rule is in a group, its checking range is limited to that group.

2) If a rule is not in any group, all other rules that are before it, including groups, are checked.

What is checked?

If a discount specified in the fields is applied to products, it is considered that there is an active discount rule.


Important, all rules should have in goals All products that meet the conditions. Move all conditions from goals to the appropriate blocks

Everything works the same way with bonuses.


How to embed the coupon generator in Mailer?


  1. Create a coupon generator.
  2. Create a block flexdiscount.mailer in Site -> Blocks:

    Note that instead of the number 1, you must provide the ID of your generator.
  3. Copy the block code and paste it into news mailer


List of all discount conditions


The conditions for granting discounts are divided into groups:

1. Product

  • Product category
  • Product category and subcategories
  • Product set
  • Product type
  • Single product
  • Product features
  • Product parameters

2. Product properties

  • Product name
  • SKU code
  • SKU name
  • Product summary
  • META title
  • META keywords
  • META keywords
  • META description
  • Product description
  • Product creation date
  • Product age
  • Product edit time
  • Does the product have a video?
  • Does the product have an image?
  • Product rating
  • Number of product ratings
  • Product price
  • Product comparison price
  • Product purchase price
  • Product price - Product purchase price
  • Product price - Product purchase price (in percentage of the price)
  • Product comparison price - Product price
  • Product comparison price - Product price (in percentage of the comparison price)
  • Minimum product price
  • Maximum product price
  • Number of inventory statuses
    For the selected period of time, for any inventory status
  • Total sales for the period..
  • Total number of sales for the period..
  • Last change in product inventory statuses X days ago
  • Product services
  • Tags products

3. Cart

  • Total quantity of all products
  • Quantity of product
  • Quantity of products in category
  • Quantity of products in category and subcategories
  • Quantity of products in set
  • Quantity of products in type
  • Quantity of all products in category
  • Quantity of all products in category and subcategories
  • Quantity of all products in set
  • Quantity of all products in type
  • Quantity of products with features
  • Quantity of unique positions
  • Order price without discount
  • Order price with discount
  • Total price of all products
  • Total price of products in category
  • Total price of products in category and subcategories
  • Total price of all products with features
  • Total sum of feature values
  • Price of each product
  • Services

4. User

  • User category
  • User
  • User country and region
  • User city
  • User creation date
  • User data
    Last name, First name, email, client type and other contact fields

5. Completed orders

  • Sum of all orders
  • Sum of orders for the period...
  • Number of all orders
  • Number of orders for the period..
  • Orders have product
  • Orders have product for the period..
  • Orders have product in category
  • Orders have product in category and subcategories
  • Orders have product in category for the period..
  • Orders have product in category and subcategories for the period..

6. Date and time

  • Date
  • Day of the week
  • Hour

7. Variables

  • Cookie
  • Session
  • $_GET
  • $_POST
  • $_SERVER
  • Coupon
  • Do partners use?
  • Is there an active coupon?

8. Site store

  • Site store
  • Client source
  • Payment
  • Delivery
  • Does it have active discount rules?
  • Does it have active partner rules?