XML import - zero values converted to empty string

Phoca Cart - complex e-commerce extension
michal.riha
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 20 Jan 2024, 09:08

XML import - zero values converted to empty string

Post 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.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: XML import - zero values converted to empty string

Post by Jan »

Hi, can you send me your XML, to test it. Maybe there should be some additional check.

Jan
If you find Phoca extensions useful, please support the project
michal.riha
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 20 Jan 2024, 09:08

Re: XML import - zero values converted to empty string

Post 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.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: XML import - zero values converted to empty string

Post 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
If you find Phoca extensions useful, please support the project
michal.riha
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 20 Jan 2024, 09:08

Re: XML import - zero values converted to empty string

Post by michal.riha »

Thank you
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48386
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: XML import - zero values converted to empty string

Post by Jan »

OK
If you find Phoca extensions useful, please support the project
Post Reply