elgentos / LargeConfigProducts

Large Configurable Products workaround for Magento 2
91 stars 28 forks source link

Be able to edit large config products in backend #39

Open peterjaap opened 5 years ago

peterjaap commented 5 years ago

...by removing the variations matrix in the edit screen. Here's some work on it I did so far;

Comment out in vendor/magento/module-configurable-product/etc/adminhtml/di.xml to remove the matrix variations grid from the product edit screen in the backend for configurables;

    <virtualType name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool">
        <arguments>
            <argument name="modifiers" xsi:type="array">
                <item name="configurable" xsi:type="array">
                    <item name="class" xsi:type="string">Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\Composite</item>
                    <item name="sortOrder" xsi:type="number">140</item>
                </item>
            </argument>
        </arguments>
    </virtualType>

Edit the PHP class that retrieves the variations (this is the memory culprit); \Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config\Matrix::getVariations add; return [];

Then we need to fix a small JS validation error: vendor/magento/module-configurable-product/view/adminhtml/web/js/variations/variations.js::exports.changeButtonWizard line 183 change to; if (this.variations && this.variations.length) {

This is where the simple products are connected to the configurable when it is saved; \Magento\ConfigurableProduct\Controller\Adminhtml\Product\Initialization\Helper\Plugin\Configurable::afterInitialize, that's a plugin for \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper::initialize

\Magento\Catalog\Controller\Adminhtml\Product:100 is where Magento builds up the product according to the POST request. The changes we just did cause Magento to de-couple the simples from the configurable since the POST param is empty.

In \Magento\ConfigurableProduct\Model\Product\TypeTransitionManager\Plugin\Configurable::aroundProcessProduct the configurable products is transitioned to a simple product since the attributes field is empty.

So we need to comment out $this->productTypeManager->processProduct($product); in \Magento\Catalog\Controller\Adminhtml\Product\Save to make sure a configurable product isn't converted to a simple product, which causes the product relations to be removed.

It would be great if we can do the above based on the number of childs the configurable have, and make this a configurable setting. For me, about 3000 products is where the server throws a memory limit error but this could be different for another server.

Obviously, this is just the happy path. I haven't done any testing at all whether it affects other parts of Magento.

zaiatsFlagbit commented 3 years ago

Hi @peterjaap Facing the same problem. Large configurable products 3k+ Did you consider paginating dataSet? not to load huge xml attaching json to document?

peterjaap commented 3 years ago

@zaiatsFlagbit no I hadn't considered that.

We're not using this extension anymore bytheway, @gaiterjones took over maintaining it.

gaiterjones commented 3 years ago

@zaiatsFlagbit I think paginating the variation data could be an option so the user loads the variations manually per variation page click.

I have not worked with a configurable product with more than 1000 variations before so have not seen any memory problems whilst creating variation data.

Can you provide more info as to your server RAM config, how much mem is available to PHP?

zaiatsFlagbit commented 3 years ago

@gaiterjones I created a module, implementing pagination for Large_Configurable_Products. I override Data_Provider, which forms product-matrix, slicing it in peaces by offset and limit params from FE. The dynamic-rows-extended.js holds some logic for pagination requests.

gaiterjones commented 3 years ago

@zaiatsFlagbit your module looks very interesting, great work - did you test it with this module too or are you happy to simply paginate the variations to improve loading? I will test it as soon as can.

zaiatsFlagbit commented 3 years ago

@gaiterjones - yes, I am using elgentos module alongside, but not as a dependency. At the moment testing new module flow. Upcoming changes.