Documentation Home

Importing Offer Codes

Activation

Admin Application

The admin based CSV import is enabled by default when the Import module is part of the project.

The API based import endpoints are disabled by default and can be enabled using @EnableFrameworkRestControllers in a servlet @Configuration class. Note that this will enable all framework API endpoints in the application. Please see the Full Framework Controller Documentation for more information.

Integration Application

If you are writing a custom integration application and would like to include this endpoint, you must explicitly define it as a bean using JavaConfig or XML configuration as so:

JavaConfig

@Configuration
public class MyIntegrationConfiguration {
    @Bean
    public AdminAdvancedOfferImportEndpoint adminAdvancedOfferImportEndpoint() {
        return new AdminAdvancedOfferImportEndpoint();
    }
}

XML

<beans>
    <bean class="com.broadleafcommerce.advancedoffer.admin.web.api.endpoint.AdminAdvancedOfferImportEndpoint" />
</beans>

Via the Admin

In order to to import offer codes in the admin, navigate to the $ on the left side navbar. Click that link and, in the open menu, click Offer Code Groups. From there select the offer code group that you'd like to import your offer codes into. Next, in the header of the grid of offer codes for the offer code group, click Import Codes. A popup window will display. From there select the file type of the file you're uploading. Next click the Choose File button which will prompt you to pick the file you want to import from your computer. Accept your choice and finally click upload.

Modifying offer codes via export and imports

To export the current offer codes for an offer group use the same instructions as noted above but instead of clicking Import Codes, click Export Codes. After the prompt is shown, choose the format you would like the export in and click the Shareable check box if this export should be available to be downloaded by other admin users that have read permission for offer codes. After clicking Export navigate to the settings tab (the cog, generally located at the bottom) on the left-hand navbar. In the menu that opens, click the My Exports option. On this page you can click the link to your export and it will be downloaded to your browser.

Next edit the offer code export however you'd like and save the modified file. This file can now be re-imported into the admin in order to update the records. To do so follow the instructions from above.

Via the REST API

First the admin has to be setup to accept REST calls without the normal Spring security and CSRF filters. To do so please reference the api setup for imports.

In order to actually hit the api refer to the AdminAdvancedOfferImportEndpoint class for the urls, but, by default, the url is /admin/api/import/offer/codes/{offer_code_group_id}?importType={import_type} where offer_code_group_id is the id of the offer code group that the offers should be imported into and import_type is the file type of the file that you are uploaded. By default the import type is CSV. Make sure that the request is a POST and is sent with basic authentication with credentials for an active admin user. Lastly send the file you wish to upload as the body of the request. On a successful request the endpoint will return a 200 status code with no body.

Out of box import format

As noted previously any fields can be added to the import file as long as the properties exist on OfferCode or an extension of OfferCode. By default the only value that is needed is offerCode. i.e.

offerCode
PROMO1
PROMO2
PROMO3

For updates the id needs to be there as well. i.e.

id,offerCode
1,PROMO1
2,PROMO2
3,PROMO3

By default, exporting from broadleaf will give the format

id,description,offerName,offerCode,emailAddress
1,SomePromo,PROMO,PROMO1,a@a.com
2,SomePromo,PROMO,PROMO2,a@a.com
3,SomePromo,PROMO,PROMO3,a@a.com

The email may be empty because the offer code may not have a specific email address that is required for that offer code. As noted before, only id and offerCode are needed for the import. Email is an optional field and if it is provided, it will be set as the required email for the offer code. The other fields are only on the export for visibility and readability purposes.