Hello, e-Commerce enthusiast! Contribute to the 2023 edition happening this month. Click.

e-Commerce Advent Calendar

The e-Commerce geek's favorite time of year
2023 Edition

Magento 1: Shell script for converting configurable to grouped products

by Tsvetan Stoychev
ABOUT THE AUTHOR
Tsvetan Stoychev

Tsvetan currently works at Akamai, he is a creator of Basic RUM, Webperformance enthusiast, Magento addict since Magento CE 1.2.1.2 and creator of the e-Commerce Advent Calendar.

This is a repost of an article that was published on the Inchoo's blog a few years ago. The real original article: https://inchoo.net/magento/shell-script-for-converting-configurable-to-grouped-products

If there is one takeaway for the reader to take from this article is the importance of choosing the proper product type not only for Magento 1 but for any e-commerce platform. Each complex product type (configurable, grouped, bundle ...) has it's own pros and cons and choosing the correct product type can save a lot of time and help to focus on the important things.

Thankfully at the moment of working on this in 2015 I worked on a project that was just starting a re-launch development phase where we were updating the already 3 years old version of Magento 1 to the most recent version Magento at the moment. We had enough time for planning and discussion with the people from marketing, support, business intelligence and category management what features they actively use and what features they would like to go away.

One of the best decisions at that time was converting the Configurable products to Grouped products which simplified the shopping experience and introduced a much simpler process for the team to maintain product prices and quantities.

Happy reading!


A couple of weeks ago my colleague Attila Fabrik and I had a really complex but interesting task. We had to develop a shell script that converts configurable products to grouped products. Our Magento 1 catalog was special. It contained mostly configurable products and it seemed that using configurable products was a good idea 4 years ago when the shop was set up but the current business conditions were pushing us to look for other, more flexible options.

The script can be downloaded, cloned or installed via MODMAN from: https://github.com/ceckoslab/convert-configurable2grouped

Below I am showing a configurable product that is about to be converted and the grouped product that is the result of the converted configurable product. Basically, the main difference lies in the manner in which "add to cart" form is rendered.

Configurable product

Grouped product

Why convert?

So far so good, but you are probably wondering why we’ve ended up with this crazy idea to convert configurable products to grouped products?

1. We needed better control over the prices we showed on the configurable product page.

It’s well known that if we set a special price on an individual simple product, then this price is not shown on the configurable product page and it’s not used when the configurable product is added to the cart – but, this is exactly what we wanted. Having grouped products allowed us to have better price control because we’ve always wanted to use the prices of the linked simple products. As we know, price calculation of configurable products works in a different way. The only problem was that the grouped product renders the simple products in a table rather than in a select box. Changing the rendering from table to select box required minimal front-end work effort, so I am going to skip the explanation how we did it.

We had an extension installed that solved the pricing problems mentioned in point (1) but this extension was rewriting many classes and had many collisions with other extensions. We just wanted to make our shop use as many core features as possible, be more robust and less complex.

But again, why convert?

Why not delete the configurable products and import the same product data but for the grouped product type?

2. We wanted to keep the original products IDs!

Those IDs existed in product review tables, the URL rewrite table, external systems, product list widgets, static blocks, etc. Of course we could delete the configurable products and preserve their IDs for the next grouped products import, but this task was also time-consuming and could require the same amount of effort as converting the products.

What DB table operations are done while running the script?

catalog_product_entity:

  • updates type_id value from configurable to grouped
  • updates has_options to 0
  • updates required_options to 0

catalog_product_link:

  • creates required links between grouped and simple products

catalog_product_option_*:

  • deletes custom options because grouped products don’t have custom options

catalog_product_super_link and catalog_product_super_attribute:

  • deletes all rows related to the converted configurable product

catalog_product_entity_*:

  • deletes EAV catalog attribute values that were valid for the configurable product but are not required for the grouped product

catalog_product_link_attribute_int:

  • creates records that describe how the simple products are positioned on the grouped product page (ordered from lowest to highest price)

Usage:

php shell/convert-configurable2grouped.php convert_all

* After the script completes execution, you will see an information table about which products have been converted.

Example output after the script was run:

Room for improvement:

So far the script converts all configurable products and doesn’t offer the option to convert a predefined list of configurable products. Basically, I don’t have a problem with this because I really want to convert all configurable products but if you want to use a list of products, please modify the function CeckosLab_Convert_Configurable2Grouped::_getConfigurableProductIds()

The script doesn’t have a function for dry-running in order to show which products are going to be converted but if the community is interested, we could add such functionality.

The script removes a fixed number of eav attribute values that are redundant for grouped products. Those attribute codes are currently hardcoded inside the shell script because it works with the default attribute sets. The script doesn’t cover the cases where the catalog contains custom created attributes that are associated individually for configurable products but are not available for grouped products.

Special thanks:

Many thanks to my good friends from Inchoo who made it possible for this article to reach many Magneto community members! Many thanks to my colleague Attila Fabrik who made the proof of concept to this script! Many thanks to my Magento Community friend Alexander Turiak who made a very good code review of the shell script and suggested that I should show some visual feedback after the script gets executed.

Tsvetan Stoychev

Interested in submiting an article?

Please check our contribute page in case you are interest to submit an article.