avstudnitz / AvS_FastSimpleImport

Wrapper for Magento ImportExport functionality, which imports products and customers from arrays
308 stars 146 forks source link

Config with more than 1 simple associated product won't assign to category #249

Open WinstonN opened 9 years ago

WinstonN commented 9 years ago

Hello

When I import configurable products if the config has more than one simple associated product the config won't get added to a category. I have tracked it down to this class app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php and the code is

                // 3. Categories phase
                $categoryPath = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
                if (!empty($rowData[self::COL_ROOT_CATEGORY])) {
                    $categoryId = $this->_categoriesWithRoots[$rowData[self::COL_ROOT_CATEGORY]][$categoryPath];
                    $categories[$rowSku][$categoryId] = true;
                } elseif (!empty($categoryPath)) {
                    $categories[$rowSku][$this->_categories[$categoryPath]] = true;
                } elseif (array_key_exists(self::COL_CATEGORY, $rowData)) {
                    // BUG: unset category
                    //$categories[$rowSku] = array();
                }

After commenting out L1038 it works as expected

The code is present in the develop branch also. I'm not sure why that elseif exists, but if you want me to create a PR let me know

Thank you for this module though - I love it!

Winst

avstudnitz commented 9 years ago

@WinstonN Can you show us the import array?

WinstonN commented 9 years ago

@avstudnitz Sure, I dumped $rowData for you

2015-08-26T17:19:06+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => P145901_GREEN_One-Size
    [_type] => simple
    [_attribute_set] => Site
    [name] => Internal ProdName exmpl ACCESSORIES
    [description] => Descrip exmpl ACCESSORIES are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [short_description] => Descrip exmpl ACCESSORIES are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [url_key] => P145901_GREEN_One-Size
    [status] => 1
    [visibility] => 1
    [_product_websites] => base
    [_category] => 
    [supplier] => Supplier and Manufacturer
    [manufacturer] => Supplier and Manufacturer
    [weight] => 0
    [site_gender] => 
    [site_colour] => 
    [site_accessories] => One Size
    [site_bags] => 
    [site_belts] => 
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 219
    [price] => 384
    [cost] => 145.92
    [special_from_date] => 2015-08-26
    [tax_class_id] => 2
    [is_in_stock] => 1
    [qty] => 1
    [_super_attribute_code] => 
    [_super_products_sku] => 
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => 
    [page_layout] => 
)

2015-08-26T17:19:07+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => P145901_GREEN
    [_type] => configurable
    [_attribute_set] => Site
    [name] => Internal ProdName exmpl ACCESSORIES
    [description] => Descrip exmpl ACCESSORIES are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [short_description] => Descrip exmpl ACCESSORIES are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [url_key] => internal-prodname-exmpl-accessories
    [status] => 1
    [visibility] => 4
    [_product_websites] => base
    [_category] => 761
    [supplier] => Supplier and Manufacturer
    [manufacturer] => Supplier and Manufacturer
    [weight] => 0
    [site_gender] => MENS
    [site_colour] => GREEN
    [site_accessories] => 
    [site_bags] => 
    [site_belts] => 
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 219
    [price] => 384
    [cost] => 145.92
    [special_from_date] => 2015-01-01
    [tax_class_id] => 2
    [is_in_stock] => 1
    [qty] => 0
    [_super_attribute_code] => site_accessories
    [_super_products_sku] => P145901_GREEN_One-Size
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => Block after Info Column
    [page_layout] => 
)

2015-08-26T17:19:07+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => P268590_GREEN_S
    [_type] => simple
    [_attribute_set] => Site
    [name] => Internal ProdName exmpl BELTS
    [description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [short_description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [url_key] => P268590_GREEN_S
    [status] => 1
    [visibility] => 1
    [_product_websites] => base
    [_category] => 
    [supplier] => Supplier and Manufacturer
    [manufacturer] => Supplier and Manufacturer
    [weight] => 0
    [site_gender] => 
    [site_colour] => 
    [site_accessories] => 
    [site_bags] => 
    [site_belts] => S
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 569
    [price] => 1,008.00
    [cost] => 383.04
    [special_from_date] => 2015-08-26
    [tax_class_id] => 2
    [is_in_stock] => 1
    [qty] => 1
    [_super_attribute_code] => 
    [_super_products_sku] => 
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => 
    [page_layout] => 
)

2015-08-26T17:19:07+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => P268590_GREEN_M
    [_type] => simple
    [_attribute_set] => Site
    [name] => Internal ProdName exmpl BELTS
    [description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [short_description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [url_key] => P268590_GREEN_M
    [status] => 1
    [visibility] => 1
    [_product_websites] => base
    [_category] => 
    [supplier] => Supplier and Manufacturer
    [manufacturer] => Supplier and Manufacturer
    [weight] => 0
    [site_gender] => 
    [site_colour] => 
    [site_accessories] => 
    [site_bags] => 
    [site_belts] => M
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 569
    [price] => 1,008.00
    [cost] => 383.04
    [special_from_date] => 2015-08-26
    [tax_class_id] => 2
    [is_in_stock] => 1
    [qty] => 1
    [_super_attribute_code] => 
    [_super_products_sku] => 
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => 
    [page_layout] => 
)

2015-08-26T17:19:07+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => P268590_GREEN
    [_type] => configurable
    [_attribute_set] => Site
    [name] => Internal ProdName exmpl BELTS
    [description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [short_description] => Descrip exmpl BELTS are a good example of a product that make's the dev feel particularly pretty,,, those were just some commas to try and break it _*_-- more random sings
    [url_key] => internal-prodname-exmpl-belts
    [status] => 1
    [visibility] => 4
    [_product_websites] => base
    [_category] => 761
    [supplier] => Supplier and Manufacturer
    [manufacturer] => Supplier and Manufacturer
    [weight] => 0
    [site_gender] => MENS
    [site_colour] => GREEN
    [site_accessories] => 
    [site_bags] => 
    [site_belts] => 
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 569
    [price] => 1,008.00
    [cost] => 383.04
    [special_from_date] => 2015-01-01
    [tax_class_id] => 2
    [is_in_stock] => 1
    [qty] => 0
    [_super_attribute_code] => site_belts
    [_super_products_sku] => P268590_GREEN_S
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => Block after Info Column
    [page_layout] => 
)

2015-08-26T17:19:07+00:00 DEBUG (7): Array
(
    [_store] => 
    [sku] => 
    [_type] => configurable
    [_attribute_set] => Site
    [name] => 
    [description] => 
    [short_description] => 
    [url_key] => 
    [status] => 
    [visibility] => 
    [_product_websites] => 
    [_category] => 
    [supplier] => 
    [manufacturer] => 
    [weight] => 
    [site_gender] => 
    [site_colour] => 
    [site_accessories] => 
    [site_bags] => 
    [site_belts] => 
    [site_boots] => 
    [site_bottoms] => 
    [site_bras] => 
    [site_cosmetics] => 
    [site_dresses] => 
    [site_flats] => 
    [site_fragrance] => 
    [site_glasses] => 
    [site_gloves] => 
    [site_hats] => 
    [site_heels] => 
    [site_jackets] => 
    [site_jeans] => 
    [site_jewellery] => 
    [site_knits] => 
    [site_lingerie] => 
    [site_maternity] => 
    [site_onesies] => 
    [site_rings] => 
    [site_sets] => 
    [site_shapewear] => 
    [site_shoes] => 
    [site_skincare] => 
    [site_sleepwear] => 
    [site_socks] => 
    [site_suits] => 
    [site_sunglasses] => 
    [site_swimwear] => 
    [site_ties] => 
    [site_tops] => 
    [site_trainers] => 
    [site_underwear] => 
    [site_wallets] => 
    [site_watches] => 
    [special_price] => 
    [price] => 
    [cost] => 
    [special_from_date] => 
    [tax_class_id] => 
    [is_in_stock] => 
    [qty] => 
    [_super_attribute_code] => 
    [_super_products_sku] => P268590_GREEN_M
    [custom_design] => 
    [custom_design_from] => 
    [custom_design_to] => 
    [custom_layout_update] => 
    [options_container] => 
    [page_layout] => 
)
WinstonN commented 9 years ago

Strange I see that last array item looks weird. That is a simple product...looks like some orphan data. Not sure where it comes from

After some investigation I see that those orphan items get's created in app/code/community/Ho/Import/Model/Import.php L576

$result = array('simple_sku1', 'simple_sku2', 'simple_sku3');
foreach ($result as $row => $val) {
    $itemRows[$storeCode][$row][$fieldName] = $val;
}

That bit of code there creates the orphan rows. I'm logging a bug for that with https://github.com/ho-nl/Ho_Import

I am not sure if this affects/ causes this issue. I'll have to investigate a bit more, but maybe you can spot something I am missing?

Thanks again,

Blow a kiss to the Netherlands, from me <3 Winst

avstudnitz commented 9 years ago

The orphan rows are totally correct - the Mage_ImportExport which is used internally uses them if there is more than one value for a column (i.e. more than one category, more than one child product, more than one of any other multiselect attribute values). Your array looks fine too. I tried to reproduce the error with the following array, but it all worked perfectly, all categories get assigned:

$data = array(
    array(
        'sku' => 'simple1',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 1',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
        'color' => 'red',
    ),
    array(
        'sku' => 'simple2',
        '_type' => 'simple',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'name' => 'Simple Product 2',
        'description' => 'Default',
        'short_description' => 'Default',
        'price' => 10,
        'weight' => 0,
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'qty' => 99,
        'is_in_stock' => 1,
        'color' => 'green',
    ),
    array(
        'sku' => 'configurable',
        '_type' => 'configurable',
        '_attribute_set' => 'Default',
        '_product_websites' => 'base',
        'price' => 10,
        'name' => 'Configurable Product',
        'description' => 'Default',
        'short_description' => 'Default',
        'status' => 1,
        'visibility' => 4,
        'tax_class_id' => 2,
        'is_in_stock' => 1,
        '_super_products_sku' => 'simple1',
        '_super_attribute_code' => 'color',
        '_category' => 1,
    ),
    array(
        'sku' => null,
        '_type' => 'configurable',
        '_attribute_set' => 'Default',
        '_product_websites' => null,
        '_super_products_sku' => 'simple2',
        '_category' => null, // tried another category here too
    ),
);

$time = microtime(true);

try {
    /** @var $import AvS_FastSimpleImport_Model_Import */
    $import = Mage::getModel('fastsimpleimport/import');
    $import->processProductImport($data);
} catch (Exception $e) {
    print_r($import->getErrorMessages());
}

This should be essentially the same as you are doing Which Magento version are you using?

avstudnitz commented 9 years ago

If you are interested in the internal format of Mage_ImportExport (which is used in AvS_FastSimpleImport and thus in Ho_Import too), have a look at http://www.integer-net.com/2012/04/04/importing-products-with-the-import-export-interface/.

WinstonN commented 9 years ago

@avstudnitz thanks for that. I am also using a PDF by Vinai http://netzarbeiter.com/media/MagentoImagine/ImportExport.pdf