Hi,
I'm looking for a solution to hide the product options in the view product that have a stock of 0.
I use stock quantities for sizes of clothing but do not want the option to be available if the stock is 0.
Any ideas?
Many thanks
It is in model/catalog/product
The way it works is like this -
The .tpl template files calls the "controller" file which then calls the "model" file which calls the database to get the data.
So, you want option_value['quantity']
In default/template/product.tpl wrap an if statement around the options section to only show options with stock, like this:
About line 55 in 1.4.9.1, you will see the block of code for options. In there, you will see the select statement. wrap the if statement around the second forech. the first foreach is for the options. the second foreach is for option_value which is the one we want.
Like this:
Now we have to go to the product.php controller file to tell it about this new thing called quantity
Find the block of code starting
See the 2 x foreach again. In the block of code for $option_value_data[] = array(, put in there one for quantity. Just copy the name line and change it to quantity.
Now we need to go to the model field to get the data. See how it says $this->model_catalog_product->getProductOptions in the controler file.
That means go to model/catalog/product.php to the getProductOptions function
So off we go to model/catalog/product.php and find the getProductOptions function. And again we see those 2 x foreach.
In the second foreach, because the first one is for options. We want option Value which is the second one. So in the array for $product_option_value_data[] = array, stick in a row for quantity. Again, just copy the name one and change name to quantity.
That should be about it. UNTESTED
The way it works is like this -
The .tpl template files calls the "controller" file which then calls the "model" file which calls the database to get the data.
So, you want option_value['quantity']
In default/template/product.tpl wrap an if statement around the options section to only show options with stock, like this:
About line 55 in 1.4.9.1, you will see the block of code for options. In there, you will see the select statement. wrap the if statement around the second forech. the first foreach is for the options. the second foreach is for option_value which is the one we want.
Like this:
Code: Select all
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<?php if ($option_value['quantity'] > '0' ) { ?> // only show option if has stock
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?> // end only show option if has stock
<?php } ?>
</option>
<?php } ?>
</select>
Find the block of code starting
Code: Select all
$options = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
Now we need to go to the model field to get the data. See how it says $this->model_catalog_product->getProductOptions in the controler file.
That means go to model/catalog/product.php to the getProductOptions function
So off we go to model/catalog/product.php and find the getProductOptions function. And again we see those 2 x foreach.
In the second foreach, because the first one is for options. We want option Value which is the second one. So in the array for $product_option_value_data[] = array, stick in a row for quantity. Again, just copy the name one and change name to quantity.
That should be about it. UNTESTED
Thank you so much JTY, the instructions were very clear.
I did have to make 1 alteration (nothing major) in model file you have to copy a different piece of the array as the name has a join in it.
Here are the files affected an what i have change for anyone else who wants to do this.
catalog/view/theme/default/template/product/product.tpl
Find:
Replace with:
catalog/controller/product/product.php
Find:
Replace with :
catalog/model/catalog/product.php
Find:
Replace with:
And that's it.
All credit goes to JTY for this mod.
I did have to make 1 alteration (nothing major) in model file you have to copy a different piece of the array as the name has a join in it.
Here are the files affected an what i have change for anyone else who wants to do this.
catalog/view/theme/default/template/product/product.tpl
Find:
Code: Select all
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
</option>
<?php } ?>
</select>
Code: Select all
<select name="option[<?php echo $option['option_id']; ?>]">
<?php foreach ($option['option_value'] as $option_value) { ?>
<?php if ($option_value['quantity'] > '0' ) { ?> // only show option if has stock
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
<?php echo $option_value['prefix']; ?><?php echo $option_value['price']; ?>
<?php } ?>
<?php } ?>
</option>
<?php } ?>
</select>
Find:
Code: Select all
foreach ($option['option_value'] as $option_value) {
$option_value_data[] = array(
'option_value_id' => $option_value['product_option_value_id'],
'name' => $option_value['name'],
'price' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
'prefix' => $option_value['prefix']
);
}
Code: Select all
foreach ($option['option_value'] as $option_value) {
$option_value_data[] = array(
'option_value_id' => $option_value['product_option_value_id'],
'name' => $option_value['name'],
'quantity' => $option_value['quantity'],
'price' => (float)$option_value['price'] ? $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : FALSE,
'prefix' => $option_value['prefix']
);
}
Find:
Code: Select all
foreach ($product_option_value_query->rows as $product_option_value) {
$product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'name' => $product_option_value_description_query->row['name'],
'price' => $product_option_value['price'],
'prefix' => $product_option_value['prefix']
);
}
Code: Select all
foreach ($product_option_value_query->rows as $product_option_value) {
$product_option_value_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value_description WHERE product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'name' => $product_option_value_description_query->row['name'],
'quantity' => $product_option_value['quantity'],
'price' => $product_option_value['price'],
'prefix' => $product_option_value['prefix']
);
}
All credit goes to JTY for this mod.
Who is online
Users browsing this forum: Bing [Bot] and 41 guests