Jump to content

Combinations import - "Attribute(Position)" not working correctly


Recommended Posts

Hi all, 

I am trying to import a .csv file with the combinations of my products and I am unable to make the "Attibute (Position)" field to work properly. 

I have five possible attributes: Front, Depth, Diameter, Height and Thickness. Not all products have all (maximum 3 of those, indeed), but I want them to appear always in that order. So, for example, I configure the fields "Attribute" and "Values" in the following ways for three different products (each have many combinations of those attributes, of course. Just showing one example of each):

-Front:select:1,Depth:select:2,Thickness:select:5 --- 20mm:0, 10mm:1, 2.0mm:2

-Diameter:select:3,Thickness:select:5 --- 30mm:0, 2.5mm:1

-Height:select:4,Thickness:select:5 --- 40mm:0, 3.0mm:1

However, once the csv is imported, the thickness appears in the third position, as if the attributes are loaded in the order that they appear in the file ignoring the selected "Position". 

Is there anything that I am doing wrong here?

Thanks a lot for your help, 

Regards

image.png

Edited by Mikein (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

I am the only one for who the value "position" when importing a csv file doesn't make any sense at all?

It doeskin matter which number do I write, is is always imported in not the "correct" order. 

For example, this: 

-Front:select:1,Depth:select:2,Thickness:select:5

-Diameter:select:3,Thickness:select:5 

Makes this effect in the position of the attributes (in the menu Catalogue/Attributes)

Front --> Position: 1

Depth --> Position: 2

Thickness --> Position: 3 (it should be 5!)

Diameter --> Position: 4 (it should be 3!)

Any ideas? It looks like that Prestashop just import the attributes in the order it finds them.

 

 

 

Link to comment
Share on other sites

  • 8 months later...

Hi,

I've the same problem on a Prestastop v1.7.8.1.

Product ID;Attribute (Name:Type:Position);Value (Value:Position)
1;Feature:radio:1;30%:4
1;Feature:radio:1;5%:1
1;Feature:radio:1;10%:2
1;Feature:radio:1;20%:3

and

Product ID;Attribute (Name:Type:Position);Value (Value:Position)
1;Feature:radio:1;30%:1
1;Feature:radio:1;5%:2
1;Feature:radio:1;10%:3
1;Feature:radio:1;20%:4

have the same result : The feature with 30% value is always at first postion, even if is use Combination ID like :

Product ID;Attribute (Name:Type:Position);Value (Value:Position);Reference
1;Feature:radio:1;30%:4;COMB4
1;Feature:radio:1;5%:1;COMB1
1;Feature:radio:1;10%:2;COMB2
1;Feature:radio:1;20%:3;COMB3

 

Link to comment
Share on other sites

  • 1 year later...

@Mikein and @WeedY,


I've been experiencing the same issues, but have looked at the source code and have found answers to your (and mine) questions.

  1. 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. 
  2. 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).
  3. 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.
  4. 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).
  5. 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.
  6. 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

CombinationAttributesImport.ods

Edited by Ken-vdE (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Hi Ken-vdE

I finally had some time to review your analysis and I cannot agree more. What you describe in point 5 is exactly what I have experienced with the position attribute. 

So far I have "solved" it (or better said, handled) dragging manually Attributes and Values after importing them. This has the disadvantage that, as you said, if you delete all combinations before importing, everything gets mixed up again (as recently happened to me).

The dummy product with all the possible values and combinations is a good idea that I also came up with, but right now I have 36 different Attributes and some of them with more than 100 values (many depths, heights and lengths). It is a work to have it done and keep it updated. But considering the work it takes to rearrange all this... I think it's worth it. I will have a look to your CSV and think about how to configure my dummy product. EDIT: I guess I can download the current Attributes and Values list from my shops's database itself and work out a CSV file from there. At least I will have the current values arranged for the next "general import". 

Thanks a lot for your analysis! I think that Prestashop still have some work ahead regarding imports, as for example, an option for importing shipping costs!

Best regards,

 

Edited by Mikein (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...