Page 1 of 1

Subtract Stock Open cart set by default value

Posted: Fri Apr 21, 2017 7:31 pm
by marijan100
I have a problem with Opencart 1.5.6 version.

In admin panel for add/edit product, is always selected: "No" for field "Subtract Stock:"

I changed in:

admin/view/template/catalog/product_form.tpl

this:

Code: Select all

<select name="subtract">
                  <?php if ($subtract) { ?>
                  <option value="1"><?php echo $text_yes; ?></option>
                  <option value="0" selected="selected"><?php echo $text_no; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_yes; ?></option>
                  <option value="0" selected="selected"><?php echo $text_no; ?></option>
                  <?php } ?>
</select></td>
to:

Code: Select all

<select name="subtract">
                  <?php if ($subtract) { ?>
                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                  <option value="0"><?php echo $text_no; ?></option>
                  <?php } else { ?>
                  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                  <option value="0"><?php echo $text_no; ?></option>
                  <?php } ?>
</select>
And this works correctly, now is selected Yes by default for product.

But I cannot find solutio to do this for variations (Option tab).

There is selected "No" for all field "Subtract Stock:" for all variations.

Any advice how to put "Yes" for all field "Subtract Stock:" in Option tab?

Thank You.

Re: Subtract Stock Open cart set by default value

Posted: Thu Apr 27, 2017 6:07 am
by oc-extensions
Hi,

No no not like this. :)

If you already have products (already saved) with option "Subtract stock" = No and now you want to change all to "Subtract stock" = YES then is enough to update table product

In phpmyadmin run this command

Code: Select all

UPDATE product SET subtract=1
and will update option for all existing products

For new products if you want this option set to yes by default be sure that in admin/controller/catalog/product.php in function getFrom you have this:

Code: Select all

if (isset($this->request->post['subtract'])) {
	$this->data['subtract'] = $this->request->post['subtract'];
} elseif (!empty($product_info)) {
	$this->data['subtract'] = $product_info['subtract'];
} else {
	$this->data['subtract'] = 1;
}
Please notice $this->data['subtract'] = 1; which means subtract stock = yes by default

For Options:
To update already saved options run this mysql command

Code: Select all

UPDATE product_option_value SET subtract=1
and will change for all existing products

Then to add option subtract stock to yes as default do this step:
in admin/view/template/catalog/product_form.tpl find area:

Code: Select all

	html += '    <td class="left"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][subtract]">';

	html += '      <option value="1"><?php echo $text_yes; ?></option>';

	html += '      <option value="0"><?php echo $text_no; ?></option>';

	html += '    </select></td>';
and them modify only 1 line from

Code: Select all

html += '      <option value="1"><?php echo $text_yes; ?></option>';
to

Code: Select all

html += '      <option value="1" selected="selected"><?php echo $text_yes; ?></option>';
Good luck