tags:

views:

617

answers:

4

I have a configurable product which is available in many different colors and sizes. I want the configurable product to appear once for every color. My idea is to assign one simple product of the configurable product in every color to the category of the configurable product. Then I want to change the listing, so that the (colored) simple product links to it's master product (the configurable one).

The other way would be, to just assign the configurable product to a category and then list it multiple times with different colors. But I think this would be to complicated.

Solution

Sincerely I have lost my code. But here is how I've managed it:

  1. Set visibility for all slave products to "catalog" so that they appear in the product listing
  2. Override the Product Model and it's getProductUrl function:

    public function getProductUrl($useSid = null) { $product = $this; $product->loadParentProductIds(); $parentIds = $product->getParentProductIds();

    if(count($parentIds) > 0 && $product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) { $parent = Mage::getModel("catalog/product")->setId($parentIds[0])->load(); return $this->getUrlModel()->getProductUrl($parent, $useSid); }

    return $this->getUrlModel()->getProductUrl($product, $useSid); }

This way each slave product links to it's master product. The tricky part is to attach the attributes to the url. You can add #attributecode1=value1&attributecode2=value2 to the url to preselect the attribute select boxes. I only had this part quick & dirty and am pretty sure someone can do this much better.

Example for preselection:

http://demo.magentocommerce.com/anashria-womens-premier-leather-sandal-7.html http://demo.magentocommerce.com/anashria-womens-premier-leather-sandal-7.html#502=43

A: 

One way would be to make the size and color part of the catalog number (or whatever unique identifying number you are using for the product)

So lets say you have a widget that comes in 2 colors and 3 sizes, and it's catalog number is "qwe123". You would enter the following 2 items into the system, along with appropriate images. I'm assuming you already have a way to deal with the sizes.

qwe123-red
qwe123-blue

There is no extra programing involved to do it this way, but if you want to link to the other colors that are available from the product page then you will have to parse out the first part of the catalog number and search for the ones that match.

Syntax Error
I can't change the SKU because it will be the EAN of the article (imported from inventory management). When I add a single product to the category, it does not link to it's master (configurable) product, but to a product detail page for itself.
Thomas
I just noticed you tagged this "Magento" which I know nothing about. So I don't think I will be much help. Sorry, I thought you were just writing php.
Syntax Error
My question was unclear, too.
Thomas
A: 

I don't understand why you just don't make a configurable product based on size for every color? That way you don't need to hack the way Magento works.

If you make a simple product that is part of a configurable product visible on the frontend, it will not link to a configurable product, if it is part of one (as you have found out). It wouldn't really make sense for you either because if your configurable products are based on size AND color, the simple products are going to have a set size and set color.

You would be done, fully functional, and hack-free if you just made a configurable product for each shirt color. Then, you can also use related products to show other shirt colors.

The less hacking, the better. That's my opinion.

Prattski
You're right with your advice, but the customer wants the color and the product to be configurable on the detail page. Anyway, yesterday I wrote a module to display the products as I want them to.
Thomas
A: 

Thomas,

Can you post your solution here? This would be a great!

Thanks

Sharon
Added my solution to the question.
Thomas
A: 

Hi Thomas,

This is great exactly what I need! but where would i put the code to attach the attribute id's to the url to preselect the options? Any help would be great! Thanks!

Justin
You can put it into an observer for the product_load_after event.
Thomas
awesome, got it! Do you happen to know how to change the base image of the configurable product to the base image of the simple product that was clicked?
Justin
No, haven't done that yet. But I think that's easily possible with some JS at the product view page.
Thomas
Thomas, I thought this too would be a simple task but I cannot get it to work. Do you have any idea exactly how you would go about this?
Justin