The Akeneo PIM comes with a number of mass edit actions. It also comes with a flexible way to define your own mass edit actions on selected products.
The mass edit action uses the BatchBundle in order to run mass edit in the background. Readers and Writers are already created so in this cookbook we will focus on how to create a Mass Edit Action and create a Processor. For more information on how to create Jobs, Readers, Processors, or Writers please see /import_and_export_data/index
.
Tip
Operations are designed to build and transport the configuration (eventually via a form) that will be sent to the background job. No item is updated from here!
The first step is to create a new class in the Operation folder that extends AbstractMassEditOperation
and declare this new class as a service in the mass_actions.yml file.
../../src/Acme/Bundle/CustomMassActionBundle/MassEditAction/Operation/CapitalizeValues.php
- 2 things will be sent to the Job:
actions
: the raw configuration actions, you define what you want here. It will be available within your Job. That's whatgetActions()
is used for. Here actions are hard-coded, but it could be generated by another method or something else.filters
: the selection filter to tell the job which items it will work on. It's used by the Reader.
Once the Operation is created, you must register it as a service in the DI with the pim_enrich.mass_edit_action
tag:
../../src/Acme/Bundle/CustomMassActionBundle/Resources/config/mass_actions.yml
As you can see, the tag needs several parameters:
name
: Tag name to identify all mass edit operations in the PIMalias
: Alias of the operation, should be unique among your operationsacl
: The ACL the operation is linked todatagrid
: The datagrid name this operation appears onform_type
: The FormType name this operation uses to be configuredoperation_group
: The group the operation belongs to (to regroup operations, see below screenshot)
Note
The alias will be used in the URL (/enrich/mass-edit-action/capitalize-values/configure
)
For this step, you'll need to register a new form extension in /src/Acme/Bundle/CustomMassActionBundle/Ressources/config/form_extensions/mass_edit/product.yml
:
extensions:
pim-mass-product-edit-product-custom:
module: pim/mass-edit-form/product/custom
parent: pim-mass-product-edit
position: 210
targetZone: custom
config:
title: pim_enrich.mass_edit.product.step.custom.title
label: pim_enrich.mass_edit.product.operation.custom.label
labelCount: pim_enrich.mass_edit.product.custom.label_count
description: pim_enrich.mass_edit.product.operation.custom.description
code: custom
jobInstanceCode: custom
icon: icon-custom
The Mass Edit should be defined with at least code
, label
, icon
and jobInstanceCode
in the config array. The combination of the code
, label
and icon
define the Operation. The jobInstanceCode
is the code of the background job.
Then, you will have to create a requirejs module for this extension (/src/Acme/Bundle/CustomMassActionBundle/Ressources/public/js/mass-edit/form/product/custom.js
) :
'use strict';
define(
[
'underscore',
'pim/mass-edit-form/product/operation',
'pim/template/mass-edit/product/change-status'
],
function (
_,
BaseOperation,
template
) {
return BaseOperation.extend({
template: _.template(template),
/**
* {@inheritdoc}
*/
render: function () {
this.$el.html(this.template());
return this;
},
});
}
);
Finally, you will have to require your custom module into the /src/Acme/Bundle/CustomMassActionBundle/Ressources/config/requirejs.yml
.
config:
paths:
pim/mass-edit-form/product/custom: pimacme/js/mass-edit/form/product/custom
Well! Now the user can select the Operation to launch it. The Operation will send its config (filters
, and actions
) to a background job process. Now we have to write the Processor that will handle product modifications.
The Processor
receives products one by one, given by the Reader
:
../../src/Acme/Bundle/CustomMassActionBundle/Connector/Processor/MassEdit/Product/CapitalizeValuesProcessor.php
Again, register the newly created class:
../../src/Acme/Bundle/CustomMassActionBundle/Resources/config/processors.yml
Tip
The Step will run 3 steps: Read, Process & Write. In this cookbook, we use existing Reader and Writer.
We just wrote the Processor in the previous phase, so let's tell the Job which services to use!
First of all you need to define a new job as follows:
../../src/Acme/Bundle/CustomMassActionBundle/Resources/config/jobs.yml
Then you need to define your step with the proper Reader, Processor and Writer.
../../src/Acme/Bundle/CustomMassActionBundle/Resources/config/steps.yml
You also need to set job parameters:
../../src/Acme/Bundle/CustomMassActionBundle/Resources/config/job_parameters.yml
The Job has to be in your database, so add it to your fixtures:
../../src/Acme/Bundle/CustomMassActionBundle/Resources/fixtures/jobs.yml
Note
To better understand how to handle this, you can read this chapter: add-your-own-data
If your installation is already set up, use the akeneo:batch:create-job command:
php bin/console akeneo:batch:create-job "Akeneo Mass Edit Connector" "mass_edit_capitalize_values" "mass_edit" "mass_edit_capitalize_values" '{}' "Mass capitalize product values"
Warning
For Enterprise Edition version, see Phase 6 to add job profile permissions in pimee_security_job_profile_access table.
Once you have realized the previous operations (and eventually cleared your cache), you should see a new option on the /enrich/mass-edit-action/choose
page.
Akeneo will generate for you a translation key following this pattern: pim_enrich.mass_edit_action.%alias%.label
.
You may now define some translation keys (label, description, success_flash...
) in your translations catalog(s).
../../src/Acme/Bundle/CustomMassActionBundle/Resources/translations/messages.en.yml
In Enterprise Edition version, job profiles are managed with user groups permissions, so you need to add these permissions. To deal with these permissions, you have 3 tables:
akeneo_batch_job_instance
: which stores the job profilesoro_access_group
: which stored the user groupspimee_security_job_profile_access
: which stores the permissions (this table only exists in Enterprise Edition)
You have to get your job instance (job profile) code from the first table, get the user groups from your second table and then execute an insert SQL query to add these permissions. It will be something like:
INSERT INTO pimee_security_job_profile_access VALUES ('', <job_profile_id>, <user_group_id>, 1, 1);
The two last numbers means you give respectively 'edit' and 'execution' permissions. Otherwise add '0'.