1

we are using an extension to upload the products through csv files.

Its working fine for simple product. But its giving error when we try to upload configurable product.... enter image description here

Error : Skip import row, product with duplicate attribute combination

In the following code ,the above error message is present. I want to know what wrong in excel sheet, so that its giving this error :

for ($i = $totalProcessedRows + 1; $i <= sizeof($data); $i++) {
                    if(strtolower($data[$i][0]) != "configurable" && $data[$i][0] != "") {
                        $attributeOptionCheck[] = $data[$i][10];
                        $associatedSkuCheck[] = $data[$i][5];
                        $totalProcessedRows++;
                    } else {
                        if(count($attributeOptionCheck) != count(array_unique($attributeOptionCheck))) 
                            $errors[] = Mage::helper('mpmassuploadaddons')->__('Skip import row, product with duplicate attribute combination');
                        elseif(count($associatedSkuCheck) != count(array_unique($associatedSkuCheck)))
                            $errors[] = Mage::helper('mpmassuploadaddons')->__('Skip import row,associated products with duplicate skus');
                        break;
                    }
                }

This is complete function for configurable products

public function importConfigurableProducts($profileId,$rowCount) {
        $helper = Mage::helper("mpmassuploadaddons");
        $collection = Mage::getModel('mpmassuploadaddons/profilesession')->getCollection()
                            ->addFieldToFilter('session_id',array('eq' => $profileId));
        $result = array();
        $data = array();
        $csvFile = "";
        $imgDir = "";
        if (count($collection) > 0) {
            foreach ($collection as  $value) {
                $csvFile = $value->getCsvFile();
                $imgDir = $value->getImageFile();
            }
            $targetPath = Mage::getBaseDir('media')."/marketplace/massuploaded/".$profileId;
            $csvPath = $targetPath.'/'.$csvFile;
            $fp = fopen($csvPath, 'r');
            while(!feof($fp) ){
                $data[] = fgetcsv($fp, 1024);
            }
            fclose($fp);
            $info = $data[$rowCount];
            $totalProcessedRows = $rowCount;
            $attributeOptionCheck = array();
            $associatedSkuCheck = array();
            $associatedSkuCheck[] = $info[5];
            $errors = array();
            for ($i = $totalProcessedRows + 1; $i <= sizeof($data); $i++) {
                if(strtolower($data[$i][0]) != "configurable" && $data[$i][0] != "") {
                    $attributeOptionCheck[] = $data[$i][10];
                    $associatedSkuCheck[] = $data[$i][5];
                    $totalProcessedRows++;
                } else {
                    if(count($attributeOptionCheck) != count(array_unique($attributeOptionCheck))) 
                        $errors[] = Mage::helper('mpmassuploadaddons')->__('Skip import row, product with duplicate attribute combination');
                    elseif(count($associatedSkuCheck) != count(array_unique($associatedSkuCheck)))
                        $errors[] = Mage::helper('mpmassuploadaddons')->__('Skip import row,associated products with duplicate skus');
                    break;
                }
            }
            if(empty($errors)) {
                $wholedata = array(
                        'category'                  =>      $info[1],
                        'name'                      =>      $info[2],
                        'description'               =>      $info[3],
                        'short_description'         =>      $info[4],
                        'sku'                       =>      $info[5],
                        'price'                     =>      $info[6],
                        'tax_class_id'              =>      $info[10],
                        'is_in_stock'               =>      $info[11],
                        '_super_attribute_code'     =>      $info[12],
                        'images'                    =>      $info[17]

                    );

                // $wholedata = array(
            //          'category'          =>      $info[0],
            //          'name'              =>      $info[1],
            //          'description'       =>      $info[2],
                //      'short_description' =>      $info[3],
                //      'sku'               =>      $info[4],
                //      'price'             =>      $info[5],
                //      'tax_class_id'      =>      $info[9],
                //      'is_in_stock'       =>      $info[10],
                //      'stock'             =>      $info[11],
                //      'weight'            =>      $info[12],
                //      'images'            =>      $info[13]
                // ); 
                if(isset($info[6])){
                    $specialdata=array(
                        'special_price'         =>      $info[7],
                        'special_from_date'     =>      $info[8],
                        'special_to_date'       =>      $info[9]
                    );
                    $wholedata=array_merge($wholedata,$specialdata);
                }

                if(isset($info[20])){
                        $systemattribute=$data[0][20];
                        $othersystemattribute=array(
                            $systemattribute => $info[20]
                        );
                        $wholedata=array_merge($wholedata,$othersystemattribute);
                }

                list($wholedata, $errors) = $this->validatePost($wholedata);
                if(empty($errors)) {
                    $customAttributeData = array();
                    $mediaTypeAttributedata = array();
                    if(isset($data[0][18])) {
                        $customAttributeCodes = explode('(', $data[0][18]);
                        if($customAttributeCodes[0] != "") {
                            list($customAttributeData, $errors) = $this->validateCustomAttributeValues($customAttributeCodes[0],$info[18]);
                            $mediaTypeAttributedata = $this->getMediaImageAttributesData($customAttributeCodes[0],$info[18]);
                        }
                    }
                    if(empty($errors)) {
                        $j = $rowCount;
                        for ($i = $j + 1; $i <= sizeof($data); $i++) { 
                            if(strtolower($data[$i][0]) != "configurable" && $data[$i][0] != "") {
                                $associateWholedata = array(
                                        'type_id'                       =>      $data[$i][0],
                                        'name'                          =>      $data[$i][2],
                                        'sku'                           =>      $data[$i][5],
                                        '_super_attribute_code'         =>      $data[$i][12],
                                        '_super_attribute_option'       =>      $data[$i][13],
                                        '_super_attribute_price_corr'   =>      $data[$i][14],
                                        '_super_attribute_qty'          =>      $data[$i][15],
                                        '_super_attribute_weight'       =>      $data[$i][16]
                                );
                                list($associateWholedata, $errors) = $this->validatePost($associateWholedata);
                                if(!empty($errors))
                                    break;
                            } else {
                                break;
                            }
                        }
                        if(empty($errors)) {
                            $profile = Mage::getModel('mpmassuploadaddons/profilesession')->load($profileId);
                            $additionalInfo = array(
                                    'type_id'               =>      'configurable',
                                    'userid'                =>      $profile->getSellerId(),
                                    'wstoreids'             =>      Mage::app()->getStore()->getStoreId(),
                                    'attribute_set_id'      =>      $profile->getAttributesetId()   
                            );
                            $wholedata = array_merge($wholedata,$additionalInfo);
                            $proid = $this->saveConfigNewProduct($wholedata); 
                            $objprod = Mage::getModel('catalog/product')->load($proid);
                            $websites = array();
                            foreach(Mage::app()->getWebsites(true) as $website) {
                              $websites[] = $website->getId();
                            }
                            $objprod->setWebsiteIds($websites)->save();
                            $marketplaceProduct = Mage::getModel('marketplace/product')->getCollection()
                                                        ->addFieldToFilter("mageproductid",array("eq" => $proid))
                                                        ->getFirstItem();
                            $marketplaceProduct->setUserid($profile->getSellerId())->save();
                            $totalProcessedRows = $rowCount;
                            $count = 1;
                            for ($i = $totalProcessedRows + 1; $i <= sizeof($data); $i++) { 
                                if(strtolower($data[$i][0]) != "configurable" && $data[$i][0] != "") {
                                    $associateWholedata = array(
                                            'type_id'           =>      'simple',
                                            'name'              =>      $data[$i][2],
                                            'sku'               =>      $data[$i][5],
                                            'stock'             =>      $data[$i][15],
                                            'weight'            =>      $data[$i][16],
                                            'status'            =>      1,
                                            'visibility'        =>      1,
                                            'mainid'            =>      $proid
                                    );
                                    $configProduct = Mage::getModel("catalog/product")->load($proid);
                                    $associatedPrice = $configProduct->getPrice();
                                    $configattr = Mage::getModel('catalog/product_type_configurable')->getConfigurableAttributesAsArray($configProduct);
                                    foreach (explode(',', $data[$i][12]) as $key => $attribute) {
                                        $optionIds = explode(',', $data[$i][13]);
                                        $optionId = $this->getAttributeOptionIdbyOptionText($attribute , $optionIds[$key]);
                                        $optionPrice = explode(',', $data[$i][14]);
                                        $associatedPrice = $associatedPrice + $optionPrice[$key];
                                        foreach ($configattr as $value) {
                                            if($value['attribute_code'] == $attribute) {
                                                $optionString = $attribute."|price|".$value['id']."|".$optionId;
                                            }
                                        }
                                        $associateWholedata[$attribute] = $optionId;
                                        $associateWholedata[$optionString] = $optionPrice[$key];
                                        $associateWholedata['price'] = $associatedPrice;
                                    }
                                    $this->quickcreate($associateWholedata);
                                    $totalProcessedRows++;
                                    $count++;
                                } else {
                                    break;
                                }
                            }
                            if(isset($info[17]) && $info[17] != "") {
                                $images = array_reverse(explode(',',$info[17])); 
                                foreach ($images as $image) {
                                    $objprod = Mage::getModel('catalog/product')->load($proid);
                                    $imgp = Mage::getBaseDir('media')."/marketplace/massuploaded/".$profileId."/".$imgDir."/"; 
                                    $checkimg = glob($imgp . $image);

                                    if(count($checkimg) != 0) {
                                        $filepath = $imgp.$image;
                                        $objprod->addImageToMediaGallery($filepath, array ('image','small_image','thumbnail'), true, false);
                                        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
                                        $objprod->save();   
                                    }               
                                }
                            }

                            try {
                                Mage::dispatchEvent('mp_add_customattribute_mass', array('product_id' => $proid,'customattribute' => $customAttributeData));
                                if(Mage::getModel('customattribute/customattribute')) {
                                    if(count($mediaTypeAttributedata)) {
                                        foreach ($mediaTypeAttributedata as $imageType => $image) {
                                            if($image != "") {
                                                $objprod = Mage::getModel('catalog/product')->load($proid);
                                                $imgp = Mage::getBaseDir('media')."/marketplace/massuploaded/".$profileId."/".$imgDir."/"; 
                                                $checkimg = glob($imgp . $image);

                                                if(count($checkimg) != 0) {
                                                    $filepath = $imgp.$image;
                                                    $objprod->addImageToMediaGallery($filepath, array ($imageType), true, false);
                                                    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
                                                    $objprod->save();   
                                                }   
                                            }           
                                        }
                                    }
                                }
                            } catch(Exception $e) {
                            }
                            if(isset($info[19]) && $info[19] != "") {
                                $wholedata['id'] = $proid;
                                $data = json_decode($info[19],true);
                                $i = 0;
                                foreach($data as $k => $d) {                                
                                    foreach ($d as $key => $value) {                                                
                                        if($key == 'values') {
                                            $wholedata['selectoptions'][$i] = $d[$key];
                                        } else {
                                            $wholedata['options'][$i][$key] = $value;
                                            $wholedata['options'][$i]['customoptindex'] = $i;
                                        }
                                    }
                                    $i++;                       
                                }
                                Mage::dispatchEvent('mp_customoption_setdata', $wholedata); 
                            }
                            $result['savedRows'] = $count;
                            $result['rowsCount'] = $totalProcessedRows;
                            $result['success'] = $helper->__("successfully saved.");
                        } else {
                            $result['savedRows'] = 0;
                            $result['rowsCount'] = $totalProcessedRows;
                            $result['errors'] = current($errors);
                        }
                    } else {
                        $result['savedRows'] = 0;
                        $result['rowsCount'] = $totalProcessedRows;
                        $result['errors'] = current($errors);
                    }
                } else {
                    $result['savedRows'] = 0;
                    $result['rowsCount'] = $totalProcessedRows;
                    $result['errors'] = current($errors);
                }
            } else {
                $result['savedRows'] = 0;
                $result['rowsCount'] = $totalProcessedRows;
                $result['errors'] = current($errors);
            }
        }
        return $result;
    }

one more related function for configurable products :

public function getConfigurableSuperAttributes() {
        $allowedSets = explode(',',Mage::getStoreConfig('marketplace/marketplace_options/attributesetid'));
        $attributeCodes = array();
        foreach ($allowedSets as $attributeSetId) {
            $attributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
            $attributeCodes[$attributeSetId] = array();
            $temp = array();
            foreach($attributes as $attribute) {
                $data = Mage::getModel('catalog/resource_eav_attribute')->load($attribute['attribute_id']);
                if($data['frontend_input'] == 'select' && $data['is_user_defined'] == 1 && $data['is_configurable'] == 1&& $data['is_visible'] == 1 && $data['is_global'] == 1) {
                    array_push($temp, $data['attribute_code']);
                }
            }
            $attributeCodes[$attributeSetId] = implode(",",$temp);
        }
        return json_encode($attributeCodes);
    }

This is complete code of that file : http://pastebin.com/vZsf0kZG

  • Could you add a log from the final data you are trying to import please? Will be easier to determine what is wrong. – Toon Van Dooren Jan 24 '16 at 19:04
  • When i tried to import the products, we are not getting any errors in log folder. – Baby in Magento Jan 27 '16 at 5:33
  • have you used UTF8 encode for the CSV ? – Chamal Chamikara Jan 27 '16 at 6:35
  • I'll be honest, looking at the module you're using, it doesn't look like something I'd feel comfortable using. Does the developer not offer you any support? – thebluefox Jan 27 '16 at 12:11
  • @ChamalChamikara i tried that, but it did't worked. – Baby in Magento Jan 27 '16 at 12:13
2
+50

i think problem with

$attributeOptionCheck[] = $data[$i][10];

when i see the other code for attribute option code is 12. 10 is for the tax_class_id. you can check this code.

'tax_class_id'              =>      $info[10],
'is_in_stock'               =>      $info[11],
'_super_attribute_code'     =>      $info[12],

$attributeOptionCheck[] = $data[$i][12];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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