Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Configurable Products? 
 
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: 193)
 
Magento Community Magento Community
Magento Community
Magento Community
 
jacanterbury
Jr. Member
 
Total Posts:  8
Joined:  2010-06-15
 
webbuddy - 01 September 2008 02:32 PM


After you have imported your Configurable/Simple Products. you need to go into Admin>Catalog>Products and edit your Configurable Products at the “Associated Products” Tab (right at the bottom) and select the simple products associated with your configurable one.  All of this is covered in one o the video tutorials as well.  I dont know that there is an easier way to associate the two in a csv or XML.  I have done all my associating manually as above.

Thanks for this.  When edit the configurable product and look at the “Associated products” tab as suggested, the imported (but as yet un connected) simple products don’t appear , however if I hit the ‘Reset filter’ button, all priducts are displayed so I can then type in part of the product anme in the ‘name’ column and hit ‘search’ - this then brings up all the relevant simple products and any not currently connected don’t have the check box selected. Selecting this and doing a save finally connects the simple product with the configurable one so that it appears in the webstore.

Question - is there an easier way to show ALL the relevant associated products rather than the method I’ve just described as its not really practical if you have lots of products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcellk
Jr. Member
 
Total Posts:  1
Joined:  2010-09-09
London, UK
 

Hi folks,

Still getting Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() ?

The adapter needs to be reset before calling the saveRow() method on the $adapter object.

Try this:

$importData = $batchImportModel->getBatchData();
try {
$adapter = Mage::getModel($batchModel->getAdapter());
$adapter->setBatchParams($batchModel->getParams());
$adapter->saveRow($importData);
} catch (Exception $e) {
Mage::log($e->getMessage());
continue;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
emmenko
Sr. Member
 
Total Posts:  96
Joined:  2010-10-20
 
marcellk - 09 September 2010 04:35 AM

Hi folks,

Still getting Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts() ?

The adapter needs to be reset before calling the saveRow() method on the $adapter object.

Try this:

$importData = $batchImportModel->getBatchData();
try {
$adapter = Mage::getModel($batchModel->getAdapter());
$adapter->setBatchParams($batchModel->getParams());
$adapter->saveRow($importData);
} catch (Exception $e) {
Mage::log($e->getMessage());
continue;
}

Hi everybody,

I’m getting problems with the cron_import_products.php (for more infos, see this thread)
Anyway, when I try to fix this error

Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getUsedProducts()

I get another error

Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load Loaded successfully: “/Users/path/to/magento/var/import/import_products.csv”. Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse Found 13 rows. Starting catalog/convert_adapter_productimport :: parse ROW 13, PARENT SKU 11285, PRODUCT SKU 1285-5200-17-xl - SQLSTATE[23000]: Integrity constraint violation: 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 CASCA) Done

plus if I run an import in backend I get this error

<br /> <b>Fatal error</b>: Call to a member function getId() on a non-object in <b>/Users/path/to/magento/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php</b> on line <b>267</b><br />

What???
Until I didn’t apply these changes the import was fine, but now I have to delete all product and re-import all to fix that...and of course delete your changes....what can I do to fix that?

Thx

Nicola

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jamesbeat
Jr. Member
 
Total Posts:  1
Joined:  2009-02-19
 

After 3 Days of trying hard, the Product Import finally worked and I just want to share my solution.

The scenario was as follows:
Exporting 330 Simple and 50 Configurable Products from a Magento 1.3.3.0 Installation to a Fresh 1.4.4.1 Install (because both magento connect and pear upgrade attempts failed).

The way it finally worked:

1. Based on the wiki (http://www.magentocommerce.com/wiki/3_-_store_setup_and_management/import_export/how_to_automatically_import_simple_grouped_and_configurable_products)
I exported one simple.csv containing the simple products and one configurable.csv containing the Configurable Products.

2. I used following scheme (for the headers) to create a new and empty complete.csv (using openoffice):
sku,websites,store,has_options,type,attribute_set,config_attributes,news_from_date,categories,name,image,small_image,thumbnail,
options_container,status,visibility,weight,description,short_description,meta_keyword,qty,is_in_stock,assort,size,colour,
Wholesale,Normal,price,tax_class_id,associated

3. Then I started combining the simple.csv and configurable.csv into simple.csv by copy/pasting the matching column contents. This is the vital point - all my former attempts failed due to faulty csv struckture/contents. To make it clearly arranged I sorted both csv’s rows by “sku”. I also made sure that all simple product rows have to be listed first, followed by all configurable products rows.

Note that in my case the following columns had to be filled only for the Configurable Products and not for the simple products: config_attributes,image,small_image,thumbnail,colour,associated

4. I had to insert the Categories for the Products in the “categories” column in the following format: /Shop/Scarfs,/Shop/Scarfs/Silk (Where “Shop” is one level below my root category) This will categorize the Item under following categories: Shop/Scarfs and Shop/Scarfs/Silk

5. After that I manually entered the Product associations for the configurable products into the “associated” column, as in my case they were not exported by Magento 1.3.3.0. This was he most time consuming part. I selected the Configurable products’ “sku” value and searched for it in the whol csv, copied the matching “sku” rows and pasted them into the “asscoiated” column, separated by comma.

6. Then I created an import profile under System/Import/Export/Advanced Profiles using the attached Productimport.php and the xml available in the wiki mentioned above.

7. Then I ran the profile and voila: all products imported properly.

Maybe there are easier ways to achieve this, but this may be helpful for everyone, who was a bit lazy and did’nt do updates for about a year like me grin

File Attachments
Productimport.php  (File Size: 17KB - Downloads: 242)
 
Magento Community Magento Community
Magento Community
Magento Community
 
bokvis
Jr. Member
 
Total Posts:  25
Joined:  2010-10-04
Gloucester
 

Sorry to do this - i have posted this elsewhere on the forum, but without response. I am interested to hear how i can have Config Products with approx. 2000 different size variations - this is causing me a huge problem and would be gratly indebted to anyone able to shed some light on this. At the moment the only option i forsee is using simple product + custom option to do this - but then i loose other features i.e. stock management.

Overview :Current Magento setup: Configure Products + Simple Products (size variations)

Problem: Configurable product from 2000 simple products is causing an issue as Magento stops responding if i make configurable products from more than 500 simple products (size variations)

Error Message: Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 2186999 bytes) in /homepages/3/d347795961/htdocs/magento/lib/Zend/Db/Statement/Pdo.php on line 228

product name = test
Type= configurable
Associated products = 696 simple products

Error Message: Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 311296 bytes) in /homepages/3/d347795961/htdocs/magento/app/design/frontend/default/flp/template/catalog/product/price.phtml on line 290
Operating System:  1&1;Dual Core – L Dedicated Server
CPU: Opteron1216
Clock Rate: 2 x 2.4 GHz
Ram: 2GB (RAID 1 Software)
Memory: 40m

Comments:  I have been told by my developer that if i obtain a server with 312m memory or more – he recommended a company called www.bluehost.com – this should solve the problem? Is there a UK hosting company which i can get an unbaised recommendation

I have 3 products with numerous size variants in each – adding up to 2000 possibilities between the 3 different products. I also have 2 more products with approx 1500 size variants or possible combinations, which we have not even attempted to load yet due to the aforementioned.

My developer is now offering “Simple products with custom option” as a solution http://s347795977.websitehome.co.uk/magento/index.php/test-product-4158.html - this will however doing it this way will apparently not allow me to check stock – which will have direct bearing of trying to integrate Magento into the Sage Accounting package.......i am also not sure of what other problems or restrictions it will raise i.e changing pricing easily

Questions:
- Is it possible to have numerous variations (size combinations) on a specific product using Configure Products + Simple Products Setup
- This being the case, if i swop to another server package offering 312m or more – will this solve the problem – and more importantly allow me to lead the additional 1500 products on over and above the 2000 i am currently having a problem with.

Any advice or assistance regarding this matter would greatly be appreciated.
info@flexibleliningproducts.co.uk or through forum or phone 08452262478 or provide a contact number

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

Take a look to our Automatic Configurables extension: Automatic Configurables
This will help to create combinations automatically.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top