2

I have a custom product (configurables) importer from XML made by me. Things are not working fine. The products are created, but attributes and categories are not set properly. Maybe I'm missing some part, or not doing it right.

Categories tab of simple and configurable product are looking like this, though I have $product->setCategoryIds($o['categoryids']); where $o['categoryids'] = Array ( [0] => 190 ). 190 leads to Shop → Events → Homecoming.

Categories

Asociated products are correct, but if you pay attention at the color you see nothing there but it should be 'Print'.

Asociated products

The tab with custom options for simple product (style should not be there, and color must be Print, size - one of [00, 0, 2]):

Simple Custom

The tab with custom options for configurable product:

Configurable Custom

Full code of MainFormController.php (file with importing code) is on pastebin (Alert: Messy code where logic may not be found). First is called postAction method.

Contents of XML: http://pastebin.com/B7JaG1y9 (simplified: 1 product, 3 sizes and 1 color as trying to do in the code).

Create configurable product is called with the following args: enter link description here

Args for create simple product: http://pastebin.com/AVV2AE9Q

print_r($configurableProductsData): http://pastebin.com/WTpW8Q2F

print_r($attributesData): http://pastebin.com/VThyRP1F

Information about attributes (attributes and values): http://pastebin.com/ibB33Mku

Update 1

The problem with attributes was at:

$product->setData($key, $value);

When setting simple product attributes, you must pass the value id not the value itself.

$product->setData($key, $value_index);

Now remains the problem with the categories. A stange thing is that I created a simple product following the tutorial from http://www.danneh.org/2012/05/creating-products-programmatically-magento, and the same problem is there.

Update 2

Well, I added manually a product to Magento (tests for categories). And I saw that, even for that product the problem is. So I need to make a new question, because it's not related to configurable products.

1

The problem with attributes was at:

$product->setData($key, $value);

When setting simple product attributes, you must pass the value id not the value itself.

$product->setData($key, $value_index);

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.