Page 1 of 1

XML import - zero values converted to empty string

Posted: 20 Jan 2024, 09:25
by michal.riha
Hi,

I am trying to import products using the XML format. I have exported current products to get a template file, added my products and than tried to import the file back. However the import fails - the UI does not show anything but I get 500 HTTP error with this message

Code: Select all

{
    "error": true,
    "code": 0,
    "message": "Incorrect integer value: '' for column 'stockstatus_a_id' at row 1"
}
This is how the elements for each product look like. I have not touch those so they are the same as they were generated during export.

Code: Select all

    ...
    <stockstatus_a_id>0</stockstatus_a_id>
    <stockstatus_n_id>0</stockstatus_n_id>
    ....
I think the problem is in the import procedure

Code: Select all

admin/layouts/product_import.php@527

Code: Select all

    // correct simple xml
    foreach($data as $k => $v) {
        if (empty($v)) {
            $data[$k] = '';
        }
    }
This code converts 0 and '0' to empty string ('') which results in setting column stockstatus_a_id to invalid value.

This code is the same in versions 4.0.9, 4.0.10 and 5.0.0b20.

Re: XML import - zero values converted to empty string

Posted: 20 Jan 2024, 14:56
by Jan
Hi, can you send me your XML, to test it. Maybe there should be some additional check.

Jan

Re: XML import - zero values converted to empty string

Posted: 22 Jan 2024, 08:13
by michal.riha
Hi,

Here is the sample file https://pastebin.com/cgbPC2Vr

I have removed attributes nad specification to keep it simple. There are two products with the same SKU but with different languages.
I thing the problem occurs when the product is updated by the import.

I have made sure, that those two products are not in db (no product with these SKUs and IDs) and than tried the following:
  • When I set import column to SKU, import fails on the second product (the first product is imported). Probably because of the duplicate SKU.
    When I set import column to ID, both products are imported.
I than tried to import the same file again, and the import fails right on the first product. This happens for both import column options.

Re: XML import - zero values converted to empty string

Posted: 22 Jan 2024, 13:32
by Jan
Hi, thank you for the info and the file, should be OK in 5.0.0 Beta22:

https://github.com/PhocaCz/PhocaCart/re ... Beta22.zip

Jan

Re: XML import - zero values converted to empty string

Posted: 22 Jan 2024, 17:48
by michal.riha
Thank you

Re: XML import - zero values converted to empty string

Posted: 25 Jan 2024, 00:44
by Jan
OK