6

I want to remove all associated product from configurable product .

How can i do this

I m trying to do like this

$product = Mage::getModel('catalog/product')->load(11);
$product->getTypeInstance()->setUsedProductAttributeIds();
$product->save();

but its not working

2 Answers 2

7

use the below code:

Mage::getResourceSingleton('catalog/product_type_configurable')
    ->saveProducts($product, array());

Send saveProducts() second params as empty arrya

Your code like this:

$product = Mage::getModel('catalog/product')->load(11);
Mage::getResourceModel('catalog/product_type_configurable')
    ->saveProducts($product, array());
2
  • How can this be achieved in Magento 2?
    – Nausif
    Aug 1, 2017 at 10:01
  • @Nausif did you find this solution in Magento 2? If yes, can you guide... Jul 8, 2020 at 10:00
0

For those (like myself) who are here for a Magento2 answer:

If we're doing it programmatically using objectManager (I know, I know)

//Set up connection to Magento instance
use Magento\Framework\App\Bootstrap;
require '../app/bootstrap.php'; //My file is in the pub dir
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');

//Load the product
$productId = '12345';
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId); 

//Here's the clear bit (be careful with this)
$product->setAssociatedProductIds([]);
$product->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.