How to display a custom product in each color in a Magento product list?

I have a custom product that is available in different colors and sizes. I want a configurable product to appear once for each color. My idea is to assign one simple product of a configurable product in each color to the category of custom product. Then I want to change the listing so that the (color) simple product communicates with the main product (custom).

Another way would be to simply assign a custom product to a category and then list it several times in different colors. But I think it will be difficult.

Decision

Regards, I have lost my code. But here is how I dealt with this:

  • Set the visibility of all subordinate products to the "catalog" so that they are in the product list
  • Override the product model and 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); }

Thus, each subordinate product is associated with it as the main product. The hard part is attaching attributes to the URL. You can add # attributecode1 = value1 & attributecode2 = value2 in url to pre-select attribute selection fields. I only had this part quickly and dirty, and I'm sure someone can do it much better.

Example for selection:

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

+4
source share
2 answers

I don’t understand why you just don’t make a custom product based on the size for each color? This way, you don’t have to hack into the way Magento works.

If you create a simple product that is part of a custom product that is visible in the front end, it will not link to a custom product if it is part of one (as you found out). This does not make sense to you, because if your custom products are based on size and color, simple products will have a given size and color.

You would be made fully functional and without hacking if you just created a custom product for each shirt color. Then you can also use related products to show the other colors of the shirts.

The fewer hacks, the better. It's my opinion.

+1
source

One way is to make the size and color of part of the catalog number (or any unique identification number that you use for the product)

So, let's say you have a widget that comes in 2 colors and 3 sizes, and its catalog number is "qwe123". You enter the following 2 elements into the system along with the corresponding images. I assume you already have a way to handle the dimensions.

  qwe123-red
 qwe123-blue 

No additional program is required for this, but if you want to associate the other colors available on the product page, you will have to analyze the first part of the catalog number and search for those that match.

0
source

Source: https://habr.com/ru/post/1309951/