Magento Forum

   
Configurable Products? 
 
plasmagunman
Jr. Member
 
Total Posts:  4
Joined:  2010-06-02
 
rich15swan - 21 June 2010 02:41 AM

@neuromancer8

I am currently having the same issue what was the solution that you came across?

for me the patch of @caligola worked like a charm:
in file app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php find the code

if ( !empty( $usingAttributeIds ) ) {
    $product 
-> getTypeInstance() -> setUsedProductAttributeIds$usingAttributeIds );
    
$product -> setConfigurableAttributesData$product -> getTypeInstance() -> getConfigurableAttributesAsArray() );
    
$product -> setCanSaveConfigurableAttributestrue );
    
$product -> setCanSaveCustomOptionstrue );
}
and replace it with
if ( !empty( $usingAttributeIds ) ) {
    $product 
-> getTypeInstance() -> setUsedProductAttributeIds$usingAttributeIds );
    
$attributes_array $product->getTypeInstance()->getConfigurableAttributesAsArray();
    foreach(
$attributes_array as $key => $attribute_value{
        $attributes_array[$key][
'label'$attribute_value['frontend_label'];
    
}
    $product 
-> setConfigurableAttributesData($attributes_array);
    
$product -> setCanSaveConfigurableAttributestrue );
    
$product -> setCanSaveCustomOptionstrue );
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
plasmagunman
Jr. Member
 
Total Posts:  4
Joined:  2010-06-02
 

instead of “category_ids” you can use “categories” to identify the category, the product belongs to. just put in there the name of the category, like “Main Category Name/Sub Category Name”.
a bug in the script prevents you from giving your main categories a name that ends with the letter “s”, to fix that enter app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php and replace the line

$categoryPathStr preg_replace'#s*/s*#''/'trim$categoryPathStr ) );
with
$categoryPathStr preg_replace'#\s*/\s*#''/'trim$categoryPathStr ) );
as a side effect the script will ignore any white spaces before and after the delimiter “/”, looks like this line of code was intended to do that ;-)

 
Magento Community Magento Community
Magento Community
Magento Community
 
plasmagunman
Jr. Member
 
Total Posts:  4
Joined:  2010-06-02
 

ok, i was working with the code from jwpadgett and it looks like he uploaded a new version of the script.
the patch for the “SQLSTATE[23000]” error is applied but i encountered a new (old) problem: the duplicating attributes error.
to fix this find the code

if ($importData['type'== 'configurable'{
    [
...]
            $attr_codes[] 
$cs_attr['attribute_id'];
and replace “attribute_id” with “attribute_code”.

 
Magento Community Magento Community
Magento Community
Magento Community
 
NETZKOLLEKTIV
Member
 
Avatar
Total Posts:  35
Joined:  2010-05-06
Erlangen, Germany
 

Using our commercial API extension package NETZKOLLEKTV Core API enables you to add configurable products via Magento Core API.

For more information see NETZKOLLEKTIV Core API

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tristan_Nguyen
Jr. Member
 
Total Posts:  4
Joined:  2010-06-20
 

Hello all, now i can run import product with Magento 1.4.1.0. Hope it can help you. Here my CSV file :

store,websites,attribute_set,type,category_ids,sku,config_attributes,has_options,name,url_key,meta_title,meta_description,thumbnail,small_image,image,gallery,gift_message_available,options_container,price,cost,weight,minimal_price,model,description,meta_keyword,short_description,custom_layout_update,color,status,tax_class_id,visibility,shirt_size,gender,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,low_stock_date,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,stock_status_changed_automatically,use_config_qty_increments,qty_increments,use_config_enable_qty_increments,enable_qty_increments,product_name,store_id,product_type_id,product_status_changed,product_changed_websites,associated
admin
,base,Shirts T,simple,4,1000-b,shirt_size,0,Testing-Name-b,,Testing-Name,The Only ChildrenPaisley T-Shirt,/fs_1011-blk.jpg,/fs_1011-blk.jpg,/fs_1011-blk.jpg,"/fs_1019-whtred.jpg,/fs_1006-blackpink.jpg",Use config,Block after Info Column,15,2,0.44,15,The Only ChildrenPaisley T-Shirt,Testing-Name,Testing-Name,Testing-Name,Block after Info Column,White,Enabled,Taxable Goods,Not Visible Individually,Medium,Mens,241,0,1,0,0,1,1,1,100,1,1,0000-00-00 00:00:00,,1,0,1,0,1,0,1,0,Testing-Name-b,0,simple,,,
admin,base,Shirts T,simple,4,1000-c,shirt_size,0,Testing-Name-c,,Testing-Name,The Only ChildrenPaisley T-Shirt,/fs_1011-blk.jpg,/fs_1011-blk.jpg,/fs_1011-blk.jpg,"/fs_1019-whtred.jpg,/fs_1006-blackpink.jpg",Use config,Block after Info Column,15,2,0.44,15,The Only ChildrenPaisley T-Shirt,Testing-Name,Testing-Name,Testing-Name,Block after Info Column,White,Enabled,Taxable Goods,Not Visible Individually,Large,Mens,241,0,1,0,0,1,1,1,100,1,1,0000-00-00 00:00:00,,1,0,1,0,1,0,1,0,Testing-Name-c,0,simple,,,
admin,base,Shirts T,configurable,4,1000,shirt_size,1,Testing-Name,,Testing-Name,The Only ChildrenPaisley T-Shirt,/fs_1011-blk.jpg,/fs_1011-blk.jpg,/fs_1011-blk.jpg,"/fs_1019-whtred.jpg,/fs_1006-blackpink.jpg",Use config,Product Info Column,15,2,0.44,15,The Only ChildrenPaisley T-Shirt,Testing-Name,Testing-Name,Testing-Name,Product Info Column,White,Enabled,Taxable Goods,"Catalog, Search",,Mens,0,0,1,0,0,1,1,1,100,1,1,0000-00-00 00:00:00,,1,0,1,0,1,0,1,0,Testing-Name,0,configurable,,,"1000-b,1000-c"

And PHP file.

File Attachments
Productimport.php  (File Size: 18KB - Downloads: 344)
 
Magento Community Magento Community
Magento Community
Magento Community
 
bolasevich
Sr. Member
 
Avatar
Total Posts:  235
Joined:  2008-03-04
Newington, CT USA
 

@Tristan Nguyen

I’ve had problems importing CSV’s that don’t use double qoutes “” around all fields and values. In your example your missing this. Try using openoffice.org scalc software its free and will restore and keep this format. I find it eliminates alot of issues FYI

Scott

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

@Tristan Nguyen

I’m trying to use your latest productimport.php with 1.4.1.1.  It successfully imports the first few simple products in my csv but when it runs into the first configurable product I get the following error:

Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() in C:\xampp\htdocs\magento\app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product\Type\Configurable\Attribute\Collection.php on line 161

I’m guessing one of the $product->getTypeInstance() calls is returning Mage_Catalog_Model_Product_Type_Simple mistakenly but I don’t see how because I know the $importData[’type’] == ‘configurable’.

Any ideas on how to solve this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
aronchi
Member
 
Avatar
Total Posts:  49
Joined:  2009-05-20
Reggio Emilia - Italy
 
gpcola - 01 August 2010 02:18 AM

@Tristan Nguyen

I’m trying to use your latest productimport.php with 1.4.1.1.  It successfully imports the first few simple products in my csv but when it runs into the first configurable product I get the following error:

Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() in C:\xampp\htdocs\magento\app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product\Type\Configurable\Attribute\Collection.php on line 161

I’m guessing one of the $product->getTypeInstance() calls is returning Mage_Catalog_Model_Product_Type_Simple mistakenly but I don’t see how because I know the $importData[’type’] == ‘configurable’.

Any ideas on how to solve this?

I also experienced this problem during a DataFlow product import session.

I debugged the core and it seems to me that the problem occurs because of the “true” parameter passed to the getTypeInstance method in the Collection class you mention.

Passing true returns a Simple product singleton type instance even when you deal with Configurable products and this seems to be the root of the problem.

To avoid this error I manually associated simple products to configurable one this way:

Mage::getResourceModel('catalog/product_type_configurable')
  ->
saveProducts($confProd$productIds);

where $confProd is the confugurable product instance and $productIds is the array containing all the simple products’s id to associate to the configurable one.
I tested this on 1.4.0.1 and 1.4.1.0 but pay attention on 1.3.2.4: the saveProducts method requires configurable product id as first parameter and not the object instance, so the code will be the following on 1.3.2.4

Mage::getResourceModel('catalog/product_type_configurable')
  ->
saveProducts($confProd->getId(), $productIds);

Hope this helps.

Sincerely, Alessandro

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

Hi Allessandro,

I tried your suggestion, updating the following line:

if (isset($importData['associated'])) {
                
//$product->setConfigurableProductsData($this->skusToIds($importData['associated'], $product));
                
Mage::getResourceModel('catalog/product_type_configurable')->saveProducts($product$this->skusToIds($importData['associated']$product));
            
}

But I\’m still experiencing this error:

Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() in C:\xampp\\htdocs\magento\app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product\Type\Configurable\Attribute\Collection.php on line 161

Also I have now noticed another error:

SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento/catalog_product_super_link`, CONSTRAINT `FK_SUPER_PRODUCT_LINK_ENTITY` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE C)

Did I update the correct line in the code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
aronchi
Member
 
Avatar
Total Posts:  49
Joined:  2009-05-20
Reggio Emilia - Italy
 
gpcola - 02 August 2010 03:32 PM

Hi Allessandro,

I tried your suggestion, updating the following line:


if (isset($importData['associated'])) {
                
//$product->setConfigurableProductsData($this->skusToIds($importData['associated'], $product));
                
Mage::getResourceModel('catalog/product_type_configurable')->saveProducts($product$this->skusToIds($importData['associated']$product));
            
}

But I\’m still experiencing this error:

Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() in C:\xampp\\htdocs\magento\app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product\Type\Configurable\Attribute\Collection.php on line 161

Also I have now noticed another error:

SQLSTATE[HY000]: General error: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento/catalog_product_super_link`, CONSTRAINT `FK_SUPER_PRODUCT_LINK_ENTITY` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE C)

Did I update the correct line in the code?

Hi,
did you call the save method on the configurable product before calling the saveProducts?
Regards, Alessandro

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

Hi,

Yeah I tried calling the save method before the saveProducts method but it made no difference.  What did make a difference, using the original code, was rerunning the import with the simple products pre-existing in the magento catalogue.  Then the import ran past the configurable product without fault, even adding the next set of simple/configurables too.  I’m wondering if there’s some timing issue going on here or whether it’s got something to do with the config_attributes value in some way?

 
Magento Community Magento Community
Magento Community
Magento Community
 
QuartSoft
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2010-05-26
 

Hi all! We’ve built an extension that helps to create simple products for configurables automatically: http://www.magentocommerce.com/magento-connect/QuartSoft/extension/3709/
Hope this will help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
gpcola
Sr. Member
 
Total Posts:  97
Joined:  2009-10-05
 

Well after many sessions testing I\’ve verified that the FIRST time in a session I run my import it fails as soon as it hits the first configurable product (doesn\’t matter which product, what the configurable attribute is or the values of the simple products in this attribute, just has to be a configurable product and the first configurable product in the import set) with the error message

Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() in C:\\xampp\\\\htdocs\\magento\\app\\code\\core\\Mage\\Catalog\\Model\\Resource\\Eav\\Mysql4\\Product\\Type\\Configurable\\Attribute\\Collection.php on line 161

The NEXT time I run the exact same import set in the same session it runs to completion with no errors and that\’s with many many different simple/configurable product sets, all with differing configurable attributes in the import. I\’m totally confused now!

 
Magento Community Magento Community
Magento Community
Magento Community
 
aronchi
Member
 
Avatar
Total Posts:  49
Joined:  2009-05-20
Reggio Emilia - Italy
 
gpcola - 03 August 2010 01:13 PM

I\’m totally confused now!

Hi,
if you like I can try to dig into the problem debugging the code.

I need you to share your code or, at least, the piece of code which produces the error above.
I also need to know exactly which Magento version you are working on.

Let me know.
Sicerely, Alessandro

 
Magento Community Magento Community
Magento Community
Magento Community
 
magento-deluxe
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2010-01-27
Berlin
 

Hey together,

It’s a shame for magento, that they are not able to re-import their own export files properly!

After founding this thread I’ve managed to import configurable and associated simple products, so thanks to all good posters!

I’ve written a script to update the pricing values of the super products, if you have imported the prices of the simple products. The code on the following page helped me developing it: Update Superproducts on the Fly

In my case, there is only one configurable attribute (picture_size). If you have more attributes, it’s getting more complex, but maybe you can use my code as orientation.

So here is my commented code. I will let it run after I imported the configurable and simple products, to set the pricing values of the attributes:

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app("admin");
$collectionConfigurable Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'));
// Loop over configurable products
foreach($collectionConfigurable as $product
{
    $product 
Mage::getSingleton("catalog/Product")->load($product->getId());
    
// get price of super product
    
$configurablePrice $product->getPrice();
    
// get childs of super product
    
$childProducts Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
    
// create array to mind prices of different sizes
    
$priceOfSize = Array();            
    foreach(
$childProducts as $childProduct{
        
// save prices of different sizes in array
        
$priceOfSize[$childProduct->getPictureSize()]=$childProduct->getPrice();
    
}
    
    
// get attributes array of super product
    
$associatedProducts $product->getTypeInstance()->getConfigurableAttributesAsArray($product);    
    
// loop over attributes of super product
    
for($j=0$jsizeof($associatedProducts) ; $j++)
    
{
        
// get attribute values
        
$attributeValues $associatedProducts[$j]["values"];
        
// loop over attribute values
        
for($k=0$ksizeof($attributeValues) ; $k++)
        
{
            
// set pricing_value for specific size, determined by the price of the simple product - price of configurable product
            
$attributeValues[$k]['pricing_value'ROUND($priceOfSize[$attributeValues[$k]["value_index"]] $configurablePrice,2);
        
}
        
// set manipulated values back on associated products
        
$associatedProducts[$j]["values"$attributeValues;
    
}
    
// set manipulated associated products back on super product
    
$product->setConfigurableAttributesData($associatedProducts);
    
// save manipulated super product
    
$product -> save();
}

?>

You’ll also find the script as attachment. Hope it helps!

File Attachments
update-super-products-prices.php  (File Size: 2KB - Downloads: 187)
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top