I've been experiencing the same issues, but have looked at the source code and have found answers to your (and mine) questions.
- When importing Attributes (Name:Type:Position, ...)* (in the source code called 'AttributeGroup', inside `if (isset($info['group'])) {`) the position is global, not on a per product/combination basis.
- When importing those attributes, the position is only stored ON CREATE. If the Attribute already exists, the position is not updated. You will have to go to Catalog -> Attributes & Features and will have to manually drag and drop the attributes in your desired order (after import).
- When importing Values (Value:Position, ..)* (in the source code called 'ProductAttribute', inside `if (isset($info['attribute'])) {`) the values position is global, not on a per product/combination basis.
- When importing those values, the positions is only stored ON CREATE. If the Value already exists, the position is not updated. You will have to go to Catalog -> Attributes & Features -> View Your Feature and will have to manually drag and drop the values in your desired order (after import).
-
After importing EACH VALUE (for EACH COMBINATION), they execute something called cleanPositions. Which makes sure every imported Value position is correctly incremental. Meaning: if you import e.g. Attributes Color:color:1,Something:select:2 with Values Red:3,Some value:2 and then another line with Color:color:3,Something:select:4 and Blue:2,Some value:1 this is what will happen (in order):
Color is permanently set to position 1 on the initial Color create (if it did not yet exist) and is later not updated to have position 3.
Something is stored with position 2 (if did not yet exist). Later it is not updated to get position 4.
Red was initially stored with position 3 (if it did not yet exist) and is then 'cleaned', so it gets position 1 as well.
Some value was initially stored with position 2 (if it did not yet exist) and is then 'cleaned', so it gets position 1 as well.
Blue was stored with position 2 (if it did not yet exist) and then 'cleaned', but keeps 2 because Red already has 1 (forced incremental). Now blue and red are reversed.
Some value was already stored with position 1, so it's not updated. - When importing Combinations, if you select Delete all combinations before import that completely scrambles your attributes too. Some values get deleted. Values positions change. It's a mess.
Maybe a possible solution for you would be to make the first row of the Combinations csv be a dummy product (non-active) with all possible attributes and its positions in a single cell and all possible values and its positions in a single cell?
Or maybe create a separate file for the attributes-import which fakes to be a combinations csv, but with all lines linked to the same dummy product and every line exists to create the attributes and its values? Example attached. Import that file before importing your real Combinations. If you do, you don't have to put your Attribute type & positions and your Value positions in your real combinations import. Just say 'Color' and 'Red', without ":color:1" and ":3".
The source code is here:
Attributes (Name:Type:Position,...) https://github.com/PrestaShop/PrestaShop/blob/c2e72f28c95f14a85fff1a43e862e826c162f1c9/controllers/admin/AdminImportController.php#L2667
Values (Value:Position,...) https://github.com/PrestaShop/PrestaShop/blob/c2e72f28c95f14a85fff1a43e862e826c162f1c9/controllers/admin/AdminImportController.php#L2728
AttributeGroup::cleanPositions() https://github.com/PrestaShop/PrestaShop/blob/c2e72f28c95f14a85fff1a43e862e826c162f1c9/classes/AttributeGroup.php#L384
ProductAttribute::cleanPositions() https://github.com/PrestaShop/PrestaShop/blob/c2e72f28c95f14a85fff1a43e862e826c162f1c9/classes/ProductAttribute.php#L367