How to Import Magento 2 Cart Price Rules

- E-Commerce, Magento 2

Cart Price Rules are an invaluable tool for running promotions. Having migrated from Magento 1 or other ecommerce platform to Magento 2 you can find yourself in need for the solution to migrate the coupon codes.

In this post we will show you how to import coupon codes and cart price rules to your Magento 2 store.


Guide list

How to Add and Import Magento 2 Cart Price Rules post continues the line of guides for Magento 2 import/export guide list. The other articles in the line are:


As you probably know native Magento 2 import procedure doesn’t let you import or export cart price rules. So, there should be another solution which is Improved Import and Export Magento 2 extension.

Latest 2.1.2 release brings in basic Cart Price Rules import. At the moment the extension offers to import your coupon codes, all its basic settings with customer group and website conditions. Complex product conditions will be added soon.

In addition to the cart price rule import the extension has another great deal to offer:

  • Import and export process automation with the help of cron scheduler;
  • Support of both CSV and XML file types;
  • Support of direct URL, Dropbox and Google Sheet import sources;
  • Import and export of categories, orders, CMS pages, and all native Magento 2 entities.

And many more. For the full list of features – visit the extension’s product page.

Buy Improved Import Magento 2 Extension

Sample cart price rule import table

To start the import process you will need a sample import table or a properly formatted CSV or XML draft which you will fill with the proper data. The best way to get the sample file is to visit Google Sheet Master Table FireBear team has composed for you.

In the Master Table you can find sheets with sample data covering all possible import entities, such as customers, categories, products, etс. Every attribute columns comes with the short description and value samples. Take full advantage.

Read more about Google Sheet Master Table

If, for some reason, you want to create an import table from a scratch – keep in mind the following requirements:

Character set Unicode (UTF-8)
Field separator Comma, Tab
Text delimiter

Cart Price Rule attributes

As with every Magento 2 import entity the cart price rules have a special attribute reference that you put into the table. Here is the full list of cart price rule attributes currently supported by Improved Import and Export extension.

Attribute name Reference Values Value example
name Rule Name. The name of the Cart Price Rule Can be any value 10% off
code Coupon Code. The coupon customers will need to enter at the cart page to apply the discount Can be any value. Leave empty if you use Auto Generation test10%off
uses_per_coupon Uses per coupon. The number of times the coupon can be applied to the cart Can be any numeral value 10
description Description of the cart price rule Can be any value A test 10% discount coupon imported with Improved Import and Export extension
from_date The date from which the cart price rule is active The date should be in the following format:

yyyy/dd/mm

For example:

If you want custom design applied from 10th of July 2019, the value should look like:

2019-10-07

2018-05-06
to_date The date to which the cart price rule is active The date should be in the following format:

yyyy/dd/mm

For example:

If you want custom design applied from 10th of July 2019, the value should look like:

2019-10-07

2018-10-06
uses_per_customer Uses per Customer. How many times a single customer can apply this very coupon code Can be any numeral value 20
customer_group_ids Customer Groups. The IDs of the customer groups that are eligible to apply this coupon code You can find IDs of the customer groups at Customers > Custom Groups > ID column of the group grid.

Use comma to separate multiple values

1,2,3
is_active Active. Defines if the cart price rule is enabled or disabled 0 – Cart Price Rule is disabled

1 – Cart Price Rule is enabled

1
stop_rules_processing Discard subsequent rules. Defines if only this very coupon can be applied. If enabled other coupon codes cannot be applied to the cart 0 – Discard subsequent rules disabled

1 – Discard subsequent rules enabled

1
sort_order Priority. Defines the order in which Cart Price Rules are applied to the cart. May be important if you offer several discounts at once. Can be any numeral value. The lower the value – the higher the priority. 10
simple_action Actions > Apply. Defines the type of the discount the coupon offers. Either a percent or fixed discount Allowed values:

to_fixed – fixed amount discount

cart_fixed – fixed amount discount for whole cart

by_percent – percent of product price discount

to_fixed
discount_amount Discount Amount. The amount of the discount customer gets by applying Cart Price Rule Can be any numeral value 15
discount_qty Maximum Qty Discount is Applied To. Maximum quantity if the product the discount can be applied to. Quantity exceeding the set value will not be discounted Can be any numeral value. 20
simple_free_shipping Free Shipping. Defines if the items that are a subject to the discount should be shipped for free Allowed values:

0 – No

1 – For matching items only

2 – For shipment with matching items

2
apply_to_shipping Apply to Shipping Amount. Defines if the discount should also be applied to the shipping price. 0 – no, the discount shouldn’t be applied to shipping

1yes, the discount is applied to shipping

0
times_used Defines how many times the coupon code has already been used Can be any numeral value 10
is_rss Public In RSS Feed. Defines if the Cart Price Rule should be published in the RSS feed 0 – no, don’t publish Cart Price Rule

1 – yes, publish Cart Price Rule

0
coupon_type Coupon. The type of the coupon code: 1 – no coupon code

2 – specific coupon code

2
use_auto_generation Use Auto Generation. Defines if the coupon codes should be automatically generated for this Cart Price Rule 0 – don’t use auto generation

1 – use auto generation

1
website_ids IDs of the websites the Cart Price Rule is applied to Website ID value 1

Now that you have all cart price rule attribute reference you can use them to compose your own import table or use Google Sheet sample table.

Importing Magento 2 cart price rules

The import table is ready either it is a sample, not it’s high time to proceed with learning how Improved Import and Export extension works.

If you decided to stick to sample Google Sheet table keep in mind that all the coupon codes are set as disabled there.

If you want sample rules to be enabled – change the value in the is_active column to ‘1’.

Step 1: creating the job and general settings

The import jobs introduced by the extension can be found under System > Improved Import / Export > Import Jobs. Here you will find an import job grid where you can manage all the created import jobs.

To create a new import job click ‘Add New Job’ button. At the New Job screen you will be greeted by the General Settings section.

Here, you will need to enable the job. Name it to identify it later in the grid. Decide if the job should run every set period or manually. And select the locale of the store you are importing coupons to. When done – scroll down to the next configuration section.

Step 2: setup job behavior and source

Below the General settings you will be asked to select the entity you are importing. We are importing Cart Price Rules, so let’s stick to it.

Below the Import Settings nested Import Behavior section.

At the Import Behavior you select what the extension should do with the data from the import table. As of version 2.1.2 you can only ‘Add’ cart price rules to the store.

In addition to the behavior you will need to select validation strategy and adjust field and multiple value separators. The separators may come in handy if you are using different from recommended import table formatting.

Now we only need to select the source from where the extension should fetch the import table.

Step 3: select import source

The last job setting will be to select the import source.

Here, you need to select the file format of the table. The extension supports either XML or CSV tables. Select where the table if located. At the screenshot above we have selected Google Sheet and pasted the link. And, at last, hit ‘Validate file’ button to let the extension ensure the table is properly formatted.

Use Image Import Source is only used for product import and will not be required while importing cart price rules.

Step 4: save and run the job

Now the job is ready the only thing you are left to do is hit ‘Save & Run’ button at the top right corner of the screen. Then, in the popover page hit ‘Run’ button. The extension will do the rest.

Once the button is hit the extension will perform the import procedure and provide you with the log file where you can check how the job went. If required you can find the log file at your store FTP: var/log/firebear.

That’s it. You have just learned how to import Cart Price Rules to your Magento 2 store. If you require instructions on how to import other entities such as products, categories or CMS pages, read the dedicated blog articles.