Post by marijan100 » Fri Apr 21, 2017 7:31 pm

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.

Newbie

Posts

Joined
Wed Sep 10, 2014 5:35 pm

Post by oc-extensions » Thu Apr 27, 2017 6:07 am

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

Get 65% OFF for Top 10 OC2.x extensions from OC-Extensions.com


User avatar
Newbie

Posts

Joined
Fri Jan 06, 2012 11:31 pm
Who is online

Users browsing this forum: No registered users and 99 guests