Migrate not updating commerce_stock field; always referring to old revision?

Created on 3 December 2012, over 12 years ago
Updated 4 May 2025, about 1 month ago

I've got a regular migrate task running that should do the following:

  1. Move an uploaded XML file into place
  2. Read XML file and either import new products or update existing ones
  3. Update stock levels as part of import task

We use commerce_stock to manage the stock levels.

However, we've recently hit a problem whereby the stock levels are not being updated from the XML, no matter what happens. This is especially a concern when products are out of stock.
The XML correctly reads zeroed or negative stock values, but no matter what happens, the new stock level is somehow either not being pulled from the XML, or not being saved as part of the migrate.

Upon looking at the migrate map table, I noticed that something like 85% of our 9000 or so products have the needs_update flag set, and no matter how many times I run a migrate update, this remains.

For example:

select * from migrate_map_my_import where needs_update = 1 limit 10;
+-------------------+---------+---------+--------------+---------------+-----------------+
| sourceid1         | destid1 | destid2 | needs_update | last_imported | rollback_action |
+-------------------+---------+---------+--------------+---------------+-----------------+
| PCUINFPEPKN       |    1386 |    1396 |            1 |             0 |               0 |
| PCUINFPKBHH       |    1389 |    1399 |            1 |             0 |               0 |

and so on for about 7500 rows.

When I look at one of the products that has negative stock:

select * from field_revision_commerce_stock where entity_id = 3586;
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+
| entity_type      | bundle  | deleted | entity_id | revision_id | language | delta | commerce_stock_value |
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+
| commerce_product | product |       0 |      3586 |        3596 | und      |     0 |                   22 |
| commerce_product | product |       0 |      3586 |        9234 | und      |     0 |                   22 |
| commerce_product | product |       0 |      3586 |        9605 | und      |     0 |                   22 |
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+

However, after I edit said product by hand:

select * from field_revision_commerce_stock where entity_id = 3586;
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+
| entity_type      | bundle  | deleted | entity_id | revision_id | language | delta | commerce_stock_value |
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+
| commerce_product | product |       0 |      3586 |        3596 | und      |     0 |                  -32 |
| commerce_product | product |       0 |      3586 |        9234 | und      |     0 |                   22 |
| commerce_product | product |       0 |      3586 |        9605 | und      |     0 |                   22 |
| commerce_product | product |       0 |      3586 |       10375 | und      |     0 |                  -32 |
+------------------+---------+---------+-----------+-------------+----------+-------+----------------------+

This is especially weird. Note that it has not just updated the latest revision, but the oldest as well.

Referring back to the map table:

select * from migrate_map_my_import where destid1 = 3586;
+-------------------+---------+---------+--------------+---------------+-----------------+
| sourceid1         | destid1 | destid2 | needs_update | last_imported | rollback_action |
+-------------------+---------+---------+--------------+---------------+-----------------+
| PQSFLIDXXXX       |    3586 |    3596 |            1 |             0 |               0 |
+-------------------+---------+---------+--------------+---------------+-----------------+

I don't know about you, but is that behaviour of retaining the oldest revision ID in there deliberate?

If it'll help, the XML structure is like so:

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <MyData>
    <UniqueID>P158699XXXX</UniqueID>
    <ProductCode>MYSKU</ProductCode>
    <ProductTitle>MY PRODUCT NAME</ProductTitle>
    <MinQuantity>0</MinQuantity>
    <MaxQuantity>0</MaxQuantity>
    <Weight>0</Weight>
    <Column1>2</Column1>
    <ZRRP>0.0000</ZRRP>
  </MyData>
</DocumentElement>

and the mapping for this field is
$this->addFieldMapping('commerce_stock', 'Column1')->xpath('Column1')->defaultValue(0);

I'm rather confused by this and I'm wondering if anyone else has had the same problems. If you think this is a problem with migrate or commerce_stock, feel free to reassign.

💬 Support request
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇦🇺Australia geoffreyr Sydney, AU / Gadigal country

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024