0

In my case I want to set backorder status to 1 (turn it on). I'm playing around in module-catalog/Controller/Adminhtml/Product/Save.php in the execute() function.

I can modify array $data with all new settings before the product will be saved. And for example if I change name it will take effect. But if I change ['stock_data']['backorders'] it will not.

So my question is how to set backorder status programmatically on product save? (simple product)

Here's short example of the array:

Array
(
    [product] => Array
        (
            [status] => 1
            [name] => Somedress-4
            [sku] => skudress-4
            [price] => 575.00
            ....
            [stock_data] => Array
                (
                    [item_id] => 87
                    [product_id] => 87
                    [stock_id] => 1
                    [qty] => 5
                    [min_qty] => 0
                    [use_config_min_qty] => 1
                    [is_qty_decimal] => 0
                    [backorders] => 1
                    [use_config_backorders] => 0
0

To set backorder status programmatically you need to override /module-catalog/Controller/Adminhtml/Product/Save.php and do this:

$stockData = ['backorders' => 0,
              'use_config_backorders' => 1];

$product->setStockData($stockData);

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.