Product Group Editing saves group products with the standard OpenCart function editProduct() of admin/model/catalog/product.php, the same function that saves the product form. Most modules that change the product form or react to a product save work with group editing without changes. This page explains the details for store owners and developers.
Quick check for store owners
If you use modules that add fields to products (extra prices, custom tabs, SEO fields, product labels and so on), do this test once:
- Make a database backup.
- Put two products into a group. Fill in the fields of the other module in both products, with different values.
- Open one of them, check only Price and save.
- Open the other product and check that the fields of the other module still have their values.
If the values are lost, try with Enable faster group editing switched off (the default, see Installation, Settings and Upgrading). If they are still lost, contact the author of that module or contact us: we can add support for its fields.
How a group product is saved
For every group product the module:
- Loads the product data:
getProduct()of the product model;- in the default (full) mode, also the data that the product form (
catalog/productcontroller,getForm()) prepares for this product, so fields that other modules add to the form data are included; - the data that
copyProduct()collects for the product (descriptions, categories, options, discounts and all other related data, plus the SEO URLs). The module patchescopyProduct()so that it returns this array instead of creating a copy.
- Replaces the checked values with the values posted from the form of the edited product.
- Calls
editProduct($product_id, $data).
So the $data array that editProduct() and its event handlers get for a group product is the full data of that product with the checked values replaced, like the post of its own product form.
What other modules should do
| Module stores its data in | Result of a group save |
|---|---|
Its own table, written in its own form handler or in an editProduct handler that reads $data |
Kept if the handler gets its values in $data: in the full mode from the form data of the product, in the fast mode only if copyProduct() returns them. A handler that deletes its rows when its key is missing in $data loses the data. |
A custom column of oc_product |
Kept: editProduct() updates only the standard columns. |
A custom column of oc_product_description, oc_product_option_value or another table that editProduct() deletes and inserts again |
Reset to the default value, unless the module also returns the column from the read methods (getProductDescriptions(), getProductOptions() and so on). A normal save of the product form in OpenCart has the same problem, so such a module usually already does this. |
Event handlers of admin/model/catalog/product/editProduct |
Run for every group product, with the data of that product. |
A module that adds a description column, for example, must return it in getProductDescriptions(); then the column is kept on a group save and the value can be copied with the per-language checkbox if the form field has a label.
Supported modules
| Module | Support |
|---|---|
Product Shipping Methods (product_smethods) |
The list of shipping methods can be copied like categories. |
Product Option Images (po_view, pov_image) |
The option view and the value images are copied with the options. |
Paid Customer Groups (is_group_product) |
The flag can be copied. |
For developers: the group API
The group model can be used by other modules:
getProductsInGroup() accepts optional join, where and sort SQL parts; the table alias is kpg. Check that the module is installed first, for example with \KaGlobal::isKaInstalled('ka_group_editing').
The group is stored in the table oc_ka_product_groups (token, product_id, added_at). token is the user_token of the admin session, so every login has its own group.
The list of supported arrays of the product form is returned by getRegisteredFields() of the same model. A single field of the form (a name without brackets) gets a checkbox automatically if its label has a for attribute. Its value is put into $data of the group product if the loaded data of that product has this key; the field is saved if editProduct() or a handler of the other module saves it.
Limitations to know
- No database transaction: the group products are saved one by one. If the save stops in the middle, the products saved before stay changed. OpenCart 3 tables are usually MyISAM, which has no transactions anyway.
- The save of a big group takes time: every product is loaded and saved completely, in the full mode also through the product form. On very big groups the PHP
max_execution_timeof your hosting can be the limit. - See Limitations, Troubleshooting and FAQ for more.