I have a system which has a set of products of three "types":
- Simple products without associated products;
- Group products;
- Simple products, which are associated to group products.
I need to:
- convert type 1 into bundle product and create associated simple product.
- convert type 2 into bundle product and keep it's associated simple products.
I know already about this extension http://www.magentocommerce.com/magento-connect/displaze-change-product-type.html but seems be capable of only converting simple -> bundle
, while I also need grouped -> bundle
conversion.
UPDATE 2:
Since it is not possible to change product types with avs-fastsimpleimport
, I removed anything about it from the question.
UPDATE 1:
Based on this questions and answers I made up my solution: 1, 2, 3, 4.
Here is the MySQL update code, which actually does the trick for me:
/*
* preparing list of simple products,
* which are not associated with any other
* complex products (group, bundle, configurable and so on)
*/
SET @simpleSkuList = (
SELECT
GROUP_CONCAT(sku)
FROM
catalog_product_entity
WHERE
type_id = 'simple'
AND LENGTH(sku) = 8
AND(
entity_id NOT IN(
SELECT DISTINCT
(product_id)
FROM
catalog_product_super_link /* associated product ids of configurable */
UNION
SELECT DISTINCT
(linked_product_id)
FROM
catalog_product_link /* associated product ids of grouped */
UNION
SELECT DISTINCT
(child_id)
FROM
catalog_product_relation /* associated product ids of bundled and grouped */
)
)
GROUP BY type_id
);
/* changing simple products type to be 'bundle' products */
UPDATE
catalog_product_entity
SET
type_id = 'bundle'
WHERE find_in_set(sku, @simpleSkuList);
And the question now sound like, does anybody think that this MySQL query can be improved somehow?
Best Answer
Ok, seems like my solution haven't caused much issues on our system so far.
So, this MySQL code does actual trick:
We also doing the same for group products, but at the same time removing all custom options from group product itself. As well as removing all child-to-parent relations. We don't care about these relations - they will be re-created on import. But we have to keep products, since they have media files attached, which is not part of the import.