Skip to content

Grouped products code incorrect for child items with different batches in export #126

@rofokken

Description

@rofokken

Problem:

Grouped child products have not the correct group code and are missing on the website search.
When you export a lot of products where you have configurables and simple childs. When not in the same export batch products are not properly related with group_code

Step to reproduce

  1. Add 1 configurable product with 2 child products.
  2. Set product export batch size to 2.
  3. Run export

One product simple will have a group code the other will not. Or both simples do not depending on sort.

Working:

Both simple and configurable products exist in te same batch

Failing:

Configurable and related simple products are in different batches.

Quick fix

Update batch size to the number of products you are exporting

Permanent fix

Make group functionality working across batches. Do not make simple group code dependable on configurable in the same batch.

Fix for this specific problem:

diff --git a/Model/Write/Products/ExportEntity.php b/Model/Write/Products/ExportEntity.php
index 0950f42..0acf18a 100644
--- a/Model/Write/Products/ExportEntity.php
+++ b/Model/Write/Products/ExportEntity.php
@@ -250,6 +250,15 @@ class ExportEntity
      */
     public function getGroupCode(): int
     {
+        if ($this->groupCode === 0) {
+            try {
+                $groupCode = (int)$this->getAttribute('parent_id', false);
+                $this->groupCode = $groupCode;
+            } catch (\Exception $e) {
+                // ignore, all is lost
+            }
+        }
+        
         return (int)$this->helper->getTweakwiseId(
             $this->getStore()->getId(),
             $this->groupCode ? $this->groupCode : $this->getId()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions