I'm trying to override a private function in Magento\ConfigurableProduct\Model\Product\Type\Configurable.

I want to remove the line:


private function getConfiguredUsedProductCollection(\Magento\Catalog\Model\Product $product)
    $collection = $this->getUsedProductCollection($product);
        ->setFlag('has_stock_status_filter', true)
    $requiredAttributes = ['name', 'price', 'weight', 'image', 'thumbnail', 'status', 'media_gallery'];
    foreach ($requiredAttributes as $attributeCode) {
    foreach ($this->getUsedProductAttributes($product) as $usedProductAttribute) {
    return $collection;

Any idea how to achieve this?

  • What class? I cant find this snippet in code. – Bartosz Herba Nov 14 '17 at 19:55
  • Sorry, Magento\ConfigurableProduct\Model\Product\Type\Configurable – MageDevBrossard Nov 14 '17 at 20:05
  • There is no such a method in this class nor in the whole magento 2. Are we talking about core magento 2? If so then what version? – Bartosz Herba Nov 14 '17 at 20:09
  • you can find it here github.com/magento/magento2/blob/… – MageDevBrossard Nov 14 '17 at 20:12

Ah, i see 2.0-develop branch. I do not want to talk about sense of overriding PRIVATE method in such an old instance of magento but in general, to override any class you must add in di.xml new preference eg.

<preference for="Magento\ConfigurableProduct\Model\Product\Type\Configurable" type="Vendor\Module\YourClass" />

Then extend parent class and override requested method. Of course, since you are trying to override something that is private in very core class of product type which does not even exists in current version of magento, you will encounter problems with another private methods in this class not even mentioning eventual upgrading to newest version.

In general, what you try to do makes no sense at all at least in context of given details.

| improve this answer | |
  • 1
    Thanks for your answer. i was clear in my question "override a private function" . Overriding a public function is not an issue for me. – MageDevBrossard Nov 14 '17 at 21:39

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.