19

What is the correct procedure - rather than deleting the product and starting again to add or remove attributes to existing configurable products.

When creating a configurable product you are asked to choose which attributes to use for the product.

I have a lot of products i now need to remove some attributes for that were selected initially, and some that also need an attribute adding that were not initially selected.

Any help with this is appreciated - as deleting the products does not seem like the best approach to this. Especially as lots of other things are associated to the products.

  • The correct answer here is: delete the product and create a new one, but there are solutions for this problem (and I think modules) but I think you can google yourself, I don't have a solution for this in mind – Fabian Blechschmidt Apr 17 '13 at 13:26
  • Did you find a solution for this? Is the below answer the solution? Please give an update. – philwinkle May 16 '13 at 4:40
  • I havent tried it yet. But i will be testing this very soon. Thanks a lot for answering - I will mark as answered if it works – eleven11 May 16 '13 at 12:15
  • Like i had a color attribute and it was linked with all configurable product.In-case that attribute has been deleted. So that its not finding that linked attribute there & showing an error as "Notice: Undefined offset: 0 in /home/not1son/public_html/vendor/magento/module-configure-product/model/Product/Type/VariationMatrix.php on line 43". Need some help to handle this situation.Thanks in advance. – Bhagyashree May 24 '18 at 10:56
15

Here is what seams to work for me for to remove an attribute from the configurable product.
This is the scenario.
All the configurable products were created wrong with the attribute brand as a configurable attribute for about 50 configurable products having about 200 simple associated products.
All the simple products associated to a configurable attribute have the same brand. The idea is to remove brand from configurable attributes and assign it as a simple attribute to the configurable product with the value of one of the simple products.
Here is the code that does this. The code is ran one time only. It can be added in an upgrade script or a simple php file.

<?php
//==>this is required only if you use a simple php file
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
//<==

$brand = 'brand';
//get the attribute instance
$brandAttribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $brand);
//if this attribute exists
if ($brandAttribute->getId()){
    //make the attribute apply to al types of products in case it's not
    $brandAttribute->setApplyTo(null);
    $brandAttribute->save();
    $resource = Mage::getSingleton('core/resource');
    //get an object with access to direct queries
    $connection = $resource->getConnection('core_write');
    //get all configurable products - you can specify additional filters here
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToFilter('type_id', 'configurable');
    foreach ($collection as $product){
        //the configurable attributes are stored in the table 'catalog_product_super_attribute'
        //remove the attribute references from that table. 
        //The constraints will take care of the cleanup.
        $q = "DELETE FROM {$resource->getTableName('catalog_product_super_attribute')}
            WHERE attribute_id = {$brandAttribute->getId()} AND product_id = {$product->getId()}";
        $connection->query($q);
        //get the simple products in the configurable product
        $usedProducts =  $product->getTypeInstance(true)->getUsedProducts(null, $product);
        foreach ($usedProducts as $p){
            //identify the first simple product that has a value for brand 
            //set that value to the configurable product.
            if ($brandValue = $p->getData($brand)){
                Mage::getSingleton('catalog/product_action')
                    ->updateAttributes(array($product->getId()), array($brand=>$brandValue), 0);
                break;
            }
        }
    }
}

For the numbers listed above, this took about 15 seconds to run on my local machine (not a powerful one). I'm sure that this can be optimized. Most probably there is no need to get all simple products of a configurable product to get the brand value, but I didn't bother.

| improve this answer | |
  • 2
    I hate that it has to be done this way and there is no method to achieve the same thing but thanks for the information. – webnoob Aug 18 '14 at 10:44
  • @Marius, will this work for 1.9? – Magento Learner Mar 16 '16 at 8:01
  • @MagentoLearner. I don't know for sure but I have a hunch it does work. – Marius Mar 16 '16 at 8:01
  • @Marius, a very quick reply!!! thanks very much – Magento Learner Mar 16 '16 at 8:02
  • @Marius, Suppose I want to add one super attribute. By adding a row with product_id and attribute_id to the table catalog_product_super_attribute will work? Or else I need to modify other tables? Like in stackoverflow.com/a/13381381/1749007 – Magento Learner Mar 16 '16 at 9:48
6

This requires direct edit of the database, and the first law of Magento is do not directly edit the database.

But if you're crazy enough to proceed, this was covered on StackOverflow a few months back:

ucts. I've tested the below DB workaround hack on CE 1.6.2 and it seems to be working:

  • Create attribute
  • Drag it to appropriate attribute set
  • Go to db editor or phpmyadmin, table ‘catalog_eav_attribute’ and look at the last one, note the ‘attribute id’, also note the product id -> go to catalog_product_entity and look for the configurable product you want, and note entity_id -> this is the product_id
  • Go to catalog_product_super_attribute and insert new record with product_id and attribute_id, note of the product_super_attribute_id
  • Go to catalog_product_super_attribute_label and insert new record with product_super_attribute_id and the value of your new attribute, like ‘Color’ or ‘Size’ which you used when adding the attribute in the admin
  • Go back to admin and click the configurable product, you will notice none of your child products is associated to your configurable product.
  • Click one of the child products, and select appropriate attribute value, you may also change the sku.
  • Export all child products and add the new attribute and sku values to it, import it back and you are done or you may have to manually change all in the admin without using the dataflow.

Credit: https://stackoverflow.com/questions/5658197/add-new-attribute-to-existing-configurable-product-magento

Untested - YMMV.

| improve this answer | |
3

To remove one super product attribute (as they are called) from all configurable products, you could execute this SQL query in the database:

DELETE FROM catalog_product_super_attribute
WHERE attribute_id = <id>;

Here, is the id of attribute stored in eav_attribute table regarding attribute_code. The table catalog_product_super_attribute links products to super product attributes. You can add and remove attributes to create configurable products there.

| improve this answer | |
  • 1
    To only remove the super product attribute from a specific single product you can extend the above SQL query to filter also on the product ID DELETE FROM catalog_product_super_attribute WHERE attribute_id = <attribute_id> AND product_id = <product_id>; – Judder Oct 20 '17 at 10:24
0

There is dirty hack to open configurable product then chose duplicate, select old and new attribute, duplicate is made without SKU, then delete original configurable product and simple products. After that you can give same SKU to duplicate. Then you just need to make new simple products.

It's fast workaround if there are not that many simple products.

| improve this answer | |
  • Not a proper answer – Deepak Rai May 10 '16 at 12:11
0

I have just managed to do this more cleanly using the Free Magmi import export tool in update mode. (understandinge version)

Export key fields, change configurable_attributes column settings to specify configurable attributes on simple and configurable SKUS then reimport using Magmi

As a former Oracle Consultant, I'd agree don't mess with the database, especially one as complex as the Magento data structure - better to use a tool that has been well tested to do this.

| improve this answer | |
0

I needed to remove an Attribute from being one of the "Configurable" attributes for a Configurable Product.

  • References above about catalog_product_super_attribute were correct. Using Navicat database tool I did sequentially a few things.

    For testing Changed the Attribute_Id, that changed it to another field being used in other products. (Confirmed that was the record at issue). Wrote Down, just in case, the full set of record data (product_super_attribute_id, product_id, attribute_id, position)

    Finally Deleted the record all together.

That did the trick. I also kept a note of what I did assuming I would need to do this again.

Again: Deleting the Record in "catalog_product_super_attribute" solved my issue which seemed related to others above.

Extra Info: to correlate "attribute_id" to the correct named list it is important to look at: catalog_super_attribute_label -> and correlate via product_super_attribute_id.
I had been searching for a related "attribute_id" field (yet to find).

"product_super_attribute_id" does the trick for telling you what the "attribute_id" actually is. (I would like to still find the "default" data set for "attribute_id" to see how the an attribute is first defined in the database).

| improve this answer | |

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.