0

When importing a group product via Danslo Apiimport module which extends the core importexport module I get the following error:

Notice: Undefined index: entity_id  in app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php on line 127

The data that I'm importing is formatted in the following way (I've changed some data for privacy reasons):

array (size=21)
0 => 
array (size=26)
  'sku' => string 'ABC123' (length=6)
  'weight' => int 1
  '_attribute_set' => string 'Default' (length=7)
  '_product_websites' => string 'base' (length=4)
  'tax_class_id' => string '2' (length=1)
  'qty' => int 100000
  '_type' => string 'grouped' (length=7)
  'is_in_stock' => int 1
  'stockType' => string 'direct' (length=6)
  'image' => string '/products/ABC123.jpg' (length=41)
  'status' => int 1
  'taxClass' => int 2
  'price' => string '16.99' (length=5)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '10' (length=2)
  '_tier_price_price' => string '15.99' (length=5)
  'name' => string 'test product' (length=40)
  'description' => string 'some description.' (length=49)
  'short_description' => string 'short description...' (length=33)
  'url_key' => string 'test-url' (length=34)
  'colour' => string 'Red' (length=3)
  'pack-size' => string '40' (length=2)
  '_root_category' => string 'Default Category' (length=16)
  '_category' => string 'test category' (length=21)
  '_super_attribute_code' => string 'colour' (length=6)
1 => 
array (size=3)
  '_attribute_set' => string 'Default' (length=7)
  '_associated_sku' => string 'some_sku_3' (length=10)
  '_associated_default_qty' => int 1
2 => 
array (size=3)
  '_attribute_set' => string 'Default' (length=7)
  '_associated_sku' => string 'some_sku_2' (length=10)
  '_associated_default_qty' => int 1
3 => 
array (size=3)
  '_attribute_set' => string 'Default' (length=7)
  '_associated_sku' => string 'some_sku_1' (length=10)
  '_associated_default_qty' => int 1
4 => 
array (size=3)
  '_product_websites' => string 'base' (length=4)
  '_attribute_set' => string 'Default' (length=7)
  '_category' => string 'test category' (length=42)
5 => 
array (size=3)
  '_product_websites' => string 'base' (length=4)
  '_attribute_set' => string 'Default' (length=7)
  '_category' => string 'test category' (length=30)
6 => 
array (size=3)
  '_product_websites' => string 'base' (length=4)
  '_attribute_set' => string 'Default' (length=7)
  '_category' => string 'test category' (length=43)
7 => 
array (size=3)
  '_product_websites' => string 'base' (length=4)
  '_attribute_set' => string 'Default' (length=7)
  '_category' => string 'test category' (length=59)
8 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '14.99' (length=5)
9 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '14.99' (length=5)
10 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => int 1
  '_tier_price_price' => string '8.99' (length=4)
11 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => string '10' (length=2)
  '_tier_price_price' => string '8.49' (length=4)
12 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'base' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '7.99' (length=4)
13 => 
array (size=14)
  'sku' => string '' (length=0)
  'weight' => int 1
  '_attribute_set' => string 'Default' (length=7)
  '_product_websites' => string 'test' (length=4)
  'tax_class_id' => string '2' (length=1)
  'qty' => int 100000
  'image' => string '/products/ABC123.jpg' (length=41)
  'visibility' => int 4
  'status' => int 1
  'taxClass' => int 2
  'price' => string '106.99' (length=6)
  'name' => string 'Some product' (length=30)
  'description' => string 'some description.' (length=49)
  'url_key' => string 'some-url' (length=34)
14 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '10' (length=2)
  '_tier_price_price' => string '19.99' (length=5)
15 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '14.99' (length=5)
16 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '10' (length=2)
  '_tier_price_price' => string '19.99' (length=5)
17 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string 'all' (length=3)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '14.99' (length=5)
18 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => int 1
  '_tier_price_price' => string '8.99' (length=4)
19 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => string '10' (length=2)
  '_tier_price_price' => string '8.49' (length=4)
20 => 
array (size=5)
  '_attribute_set' => string 'Default' (length=7)
  '_tier_price_website' => string 'test' (length=4)
  '_tier_price_customer_group' => string '4' (length=1)
  '_tier_price_qty' => string '20' (length=2)
  '_tier_price_price' => string '7.99' (length=4)

The offending code is in the function below (I've added comments around the exact line).

public function saveData()
{
    $groupedLinkId = Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED;
    $connection    = Mage::getSingleton('core/resource')->getConnection('write');
    $resource      = Mage::getResourceModel('catalog/product_link');
    $mainTable     = $resource->getMainTable();
    $relationTable = $resource->getTable('catalog/product_relation');
    $newSku        = $this->_entityModel->getNewSku();
    $oldSku        = $this->_entityModel->getOldSku();
    $attributes    = array();

    // pre-load attributes parameters
    $select = $connection->select()
        ->from($resource->getTable('catalog/product_link_attribute'), array(
            'id'   => 'product_link_attribute_id',
            'code' => 'product_link_attribute_code',
            'type' => 'data_type'
        ))->where('link_type_id = ?', $groupedLinkId);
    foreach ($connection->fetchAll($select) as $row) {
        $attributes[$row['code']] = array(
            'id' => $row['id'],
            'table' => $resource->getAttributeTypeTable($row['type'])
        );
    }
    while ($bunch = $this->_entityModel->getNextBunch()) {
        $linksData     = array(
            'product_ids'      => array(),
            'links'            => array(),
            'attr_product_ids' => array(),
            'position'         => array(),
            'qty'              => array(),
            'relation'         => array()
        );
        foreach ($bunch as $rowNum => $rowData) {
            if (!$this->_entityModel->isRowAllowedToImport($rowData, $rowNum)
                || empty($rowData['_associated_sku'])
            ) {
                continue;
            }
            if (isset($newSku[$rowData['_associated_sku']])) {
                $linkedProductId = $newSku[$rowData['_associated_sku']]['entity_id'];
            } elseif (isset($oldSku[$rowData['_associated_sku']])) {
                $linkedProductId = $oldSku[$rowData['_associated_sku']]['entity_id'];
            } else {
                continue;
            }
            $scope = $this->_entityModel->getRowScope($rowData);
            if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $scope) {
                $productData = $newSku[$rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_SKU]];
            } else {
                $colAttrSet = Mage_ImportExport_Model_Import_Entity_Product::COL_ATTR_SET;

                 /**
                 * This is line 22
                 **/
                $rowData[$colAttrSet] = $productData['attr_set_code'];
                /**
                 * This is line 22
                 **/

      $rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_TYPE] = $productData['type_id'];
            }
            $productId = $productData['entity_id'];

            if ($this->_type != $rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_TYPE]) {
                continue;
            }
            $linksData['product_ids'][$productId] = true;
            $linksData['links'][$productId][$linkedProductId] = $groupedLinkId;
            $linksData['relation'][] = array('parent_id' => $productId, 'child_id' => $linkedProductId);
            $qty = empty($rowData['_associated_default_qty']) ? 0 : $rowData['_associated_default_qty'];
            $pos = empty($rowData['_associated_position']) ? 0 : $rowData['_associated_position'];

            if ($qty || $pos) {
                $linksData['attr_product_ids'][$productId] = true;
                if ($pos) {
                    $linksData['position']["{$productId} {$linkedProductId}"] = array(
                        'product_link_attribute_id' => $attributes['position']['id'],
                        'value' => $pos
                    );
                }
                if ($qty) {
                    $linksData['qty']["{$productId} {$linkedProductId}"] = array(
                        'product_link_attribute_id' => $attributes['qty']['id'],
                        'value' => $qty
                    );
                }
            }
        }
        // save links and relations
        if ($linksData['product_ids'] && $this->getBehavior() != Mage_ImportExport_Model_Import::BEHAVIOR_APPEND) {
            $connection->delete(
                $mainTable,
                $connection->quoteInto(
                    'product_id IN (?) AND link_type_id = ' . $groupedLinkId,
                    array_keys($linksData['product_ids'])
                )
            );
        }
        if ($linksData['links']) {
            $mainData = array();

            foreach ($linksData['links'] as $productId => $linkedData) {
                foreach ($linkedData as $linkedId => $linkType) {
                    $mainData[] = array(
                        'product_id'        => $productId,
                        'linked_product_id' => $linkedId,
                        'link_type_id'      => $linkType
                    );
                }
            }
            $connection->insertOnDuplicate($mainTable, $mainData);
            $connection->insertOnDuplicate($relationTable, $linksData['relation']);
        }
        // save positions and default quantity
        if ($linksData['attr_product_ids']) {
            $savedData = $connection->fetchPairs($connection->select()
                ->from($mainTable, array(
                    new Zend_Db_Expr('CONCAT_WS(" ", product_id, linked_product_id)'), 'link_id'
                ))
                ->where(
                    'product_id IN (?) AND link_type_id = ' . $groupedLinkId,
                    array_keys($linksData['attr_product_ids'])
                )
            );
            foreach ($savedData as $pseudoKey => $linkId) {
                if (isset($linksData['position'][$pseudoKey])) {
                    $linksData['position'][$pseudoKey]['link_id'] = $linkId;
                }
                if (isset($linksData['qty'][$pseudoKey])) {
                    $linksData['qty'][$pseudoKey]['link_id'] = $linkId;
                }
            }
            if ($linksData['position']) {
                $connection->insertOnDuplicate($attributes['position']['table'], $linksData['position']);
            }
            if ($linksData['qty']) {
                $connection->insertOnDuplicate($attributes['qty']['table'], $linksData['qty']);
            }
        }
    }
    return $this;
}

As suggested here I tried setting attr_set_code to null but that just causes an error on the next line. Can this issue be avoided in how I format the data or do I need to rewrite the core?

1 Answer 1

0

By placing the following code just above where $productData is declared in the else statement it should work.

$keys = array_keys( $newSku);
$productData = $newSku[ $keys[0] ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.