Im still a newbie learning things day by day. I have posted my question at the OpenCart forum website looking for help and now here in StackOverflow. I need your help guys.
Hi there, Im a newbie getting used to Opencart environment. I need help with product bands as I have attached in picture below.
I need the coming_soon option to overwrite the out_of_stock option settings. Its not working correctly as Im confused with the logic that has been made. Out_of_stock option works when there is only "0" quantity products. When we have a new product that is Coming_soon we would make that product quantity "0" as well but something is wrong here and the Coming_soon is not overwriting the Out_of_stock setting. I need some help here.
catalog/controller/product/category.php
/*OOS Band start*/
$optionsQty = 0;
$oosQty = 0;
foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option) {
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
foreach ($option['option_value'] as $option_value) {
$optionsQty++;
if ($option_value['quantity'] <=0) $oosQty++;
}
}
}
if ($optionsQty == $oosQty && $optionsQty > 0 ) {
$band_oos = true;
}
else $band_oos = false; /*OOS Band end*/
catalog/view/product/category.tpl
<div class="for_infine">
<?php if ($product['band_oos']) { ?>
<span class="band-oos"> </span>
<?php } ?>
<?php if ($product['band_free_shipping'] == 'Yes') { ?>
<span class="band-free-shipping"> </span>
<?php } ?>
<?php if ($product['band_new'] == 'Yes') { ?>
<span class="band-new"> </span>
<?php } ?>
<?php if ($product['band_coming_soon'] == 'Yes') { ?>
<span class="band-coming-soon"> </span>
<?php } ?>
<br />
catalog/controller/product/product.php
$this->data['options'] = array();
$optionsQty = 0;
$oosQty = 0;
foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
$option_value_data = array();
foreach ($option['option_value'] as $option_value) {
$optionsQty++;
if ($option_value['quantity'] <=0) $oosQty++;
if ((float)$product_info['special']) {
$price_original = $product_info['special'];
}else {
$price_original = $product_info['price'];
}
catalog/view/product/product.tpl
<div class="left">
<div class="heading" style="line-height: 27px; font-size: 25px;"><?php echo $heading_title; ?></div>
<?php if ($thumb) { ?>
<div class="image">
<?php if ($band_oos ) { ?>
<div class="oos_tab_large top-right-cnr"></div>
<?php } ?>
<?php if ($band_free_shipping == 'Yes') { ?>
<div class="free_shipping_tab_large top-right-cnr"></div>
<?php } ?>
<?php if ($band_new == 'Yes') { ?>
<div class="new_tab_large top-right-cnr"></div>
<?php } ?>
<?php if ($band_coming_soon == 'Yes') { ?>
<div class="coming_soon_tab_large top-right-cnr"></div>
<?php } ?>
Opencart out of stock warning can be disabled in settings:
Settings -> Your Store -> Edit -> Options -> Show Out Of Stock Warning
If you need both Stock Warning and Bands to work together you need to rethink new products adding with 0 quantity.
Related
i have a simple form where when a user selects a selectbox another selectbox will show values based on it, its a simple PHP page, so I just did it with the two selectbpxes in a simple page and its working fine as you can see here:
enter link description here
now I implemented it in my actual form in the website which is live here:
enter link description here
however this is giving me blank values, the codes are like below:
$(document).ready(function() {
$("#type").change(function() {
var val = $(this).val();
if (val == "2") {
$("#size").html("<?php
$ret = mysqli_query($con, "select * from modelssubcat where cat_id='2'");
while ($row = mysqli_fetch_array($ret)) {
?
> < option value = '<?php echo $row["subcat_name"];?>' > <?php echo $row["subcat_name"];?> < /option><?php }?>");
} else if (val == "3") {
$("#size").html("<?php
$ret = mysqli_query($con, "select * from modelssubcat where cat_id='3'");
while ($row = mysqli_fetch_array($ret)) {
?
> < option value = '<?php echo $row["subcat_name"];?>' > <?php echo $row["subcat_name"];?> < /option><?php }?>");
} else if (val == "4") {
$("#size").html("<?php
$ret = mysqli_query($con, "select * from modelssubcat where cat_id='4'");
while ($row = mysqli_fetch_array($ret)) {
?
> < option value = '<?php echo $row["subcat_name"];?>' > <?php echo $row["subcat_name"];?> < /option><?php }?>");
} else if (val == "5") {
$("#size").html("<?php
$ret = mysqli_query($con, "select * from modelssubcat where cat_id='5'");
while ($row = mysqli_fetch_array($ret)) {
?
> < option value = '<?php echo $row["subcat_name"];?>' > <?php echo $row["subcat_name"];?> < /option><?php }?>");
}
});
});
<?php
session_start();
include("inc/connection.php");
?>
<!DOCTYPE html>
<html lang="en" class="loading">
...........
<form method="post" enctype="multipart/form-data">
<div class="card-body">
<div class="card-block">
<div class="col-md-6">
<div class="form-group">
<label for="image">Category Name</label>
<select id="type" class="form-control" name="cat_id">
<option>--Select Category--</option>
<?php
$ret=mysqli_query($con,"select * from modelscat");
while ($row=mysqli_fetch_array($ret)) {
?>
<option value="<?php echo $row['cat_id'];?>">
<?php echo $row['cat_name'];?>
</option>
<?php }?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="image">SubCategory Name</label>
<select id="size" class="form-control" name="subcat_id">
<option>--Select Subcategory--</option>
</select>
</div>
</div>
.................
can anyone please tell me what is wrong in here, thanks in advance
I am new in jquery. I have done half of work. But I am not find any solution.
Here you see the image There are four Checkboxes Nail, Hair, Skin-care, Massage. I want when user click on Salon, Mobile beautician and Both above Nail checkbox would be ticked and when user click on Select your service Nail checkbox would be unchecked so this applies to all. I have done that but problem is that when I do select the item second time from nails the checkbox is not checked. Its working only one time. Please help me. Here I have code:-
Html:-
<div class="one-row">
<?php foreach ($services as $key => $allservices) {
if ($key <= 3) {
if (!empty($data['services'])) {
if (in_array($allservices['id'], $data['services'])) {
$checked = "checked";
} else {
$checked = "";
}
} else {
$checked = "";
} ?>
<div class="div_img_part-2">
<span class="img_part_class-2"><img src="{{ asset('images/ServiceImages/'. $allservices['image'])}}">
</span>
<span class="text_part_class-2">
<p class="custom-checkbox firstpart">
<input class="firstdisable" type="checkbox" id="{{ $key }}" name="services[]"
value="{{ $allservices['id'] }}" <?= $checked; ?>/>
<label for="{{ $key }}">{{$allservices['name']}}</label>
/p>
</span>
</span>
<select name="service_type[<?php echo $allservices['name']; ?>]" class="selectpicker">
<option value="">Select Your Sevice</option>
<option value="Salon" <?php if (!empty($data['service_type'][$allservices['name']])) {
if ($data['service_type'][$allservices['name']] == "Salon") { ?> selected
<?php }
} ?> >Salon
</option>
<option value="Mobile beautician" <?php if (!empty($data['service_type'][$allservices['name']])) {
if ($data['service_type'][$allservices['name']] == "Mobile beautician") { ?> selected
<?php }
} ?> >Mobile beautician
</option>
<option value="Both" <?php if (!empty($data['service_type'][$allservices['name']])) {
if ($data['service_type'][$allservices['name']] == "Both") { ?> selected
<?php }
} ?>>Both
</option>
</select>
</div>
<?php }
} ?>
</div>
I am using Laravel framework
here is my jQuery code:-
$('.selectpicker').selectpicker('refresh');
$(".selectpicker").on('change', function() {
var value = $(this).parents(".div_img_part-2").find(".selectpicker").val();
alert(value);
if (value == "") {
$(this).parents(".div_img_part-2").find("input[type='checkbox']").attr('checked', false);
if ($("input:checked").length == 0) {
$('.disable').prop('disabled', false);
$('.selectpicker').selectpicker('refresh');
}
} else {
$(this).parents(".div_img_part-2").find("input[type='checkbox']").attr('checked', true);
}
});
Use closest() and prop() instead of parent() and attr().
try this :
$(".selectpicker").on('change', function () {
var value = $(this).val();
if (value == "") {
$(this).closest(".div_img_part-2").find("input[type='checkbox']").prop('checked', false);
if ($("input:checked").length == 0) {
$('.disable').prop('disabled', false);
$('.selectpicker').selectpicker('refresh');
}
} else {
$(this).closest(".div_img_part-2").find("input[type='checkbox']").prop('checked', true);
}
});
I am using Laravel framework and some jquery code.
The problem is that, when i submit the data, it is successfully saved in session. when i get back to previous page, My select box shows the selected value but select-box is disabled. i am totally confused. what shall i do here?
Here is my HTML code:-
<div class="one-row">
<?php foreach ($services as $key => $allservices){
if($key <= 3){
if(!empty($data['services'])){
if(in_array($allservices['id'],$data['services'])) {
$checked = "checked";
} else {
$checked = "";
}
} else {
$checked = "";
}
?>
<div class="div_img_part-2">
<span class="img_part_class-2">
<img src="{{
asset('images/ServiceImages/'. $allservices['image'])}}"></span>
<span class="text_part_class-2">
<span class="check-box">
<input type="checkbox" name="services[]" value="
<?php echo $allservices['id']; ?>" <?= $checked; ?>><?php echo $allservices['name']; ?></span>
</span>
<select name="services[<?php echo $allservices['name'];?>]"class="selectpicker">
<option value="">Select Your Sevice</option>
<option value="Salon" <?php if(!empty($data['services'][$allservices['name']])){ if($data['services'][$allservices['name']] == "Salon") {?> selected
<?php } } ?> >Salon</option>
<option value="Mobile beautician" <?php if(!empty($data['services'][$allservices['name']])){ if($data['services'][$allservices['name']] == "Mobile beautician") {?> selected
<?php } }?> >Mobile beautician</option>
<option value="Both" <?php if(!empty($data['services'][$allservices['name']])){ if($data['services'][$allservices['name']] == "Both") {?> selected
<?php } } ?>>Both</option>
</select>
</div>
<?php } } ?>
</div>
And my Jquery Code looks:-
<script>
$(document).ready(function () {
$(".div_img_part-2 .selectpicker").attr("disabled",true);
$('.selectpicker').selectpicker('refresh');
$(".check-box input[type='checkbox']").on("change", function () {
if ($(this).prop("checked") == true) {
$(this).parents(".div_img_part-2").find(".selectpicker").removeAttr("disabled");
$('.selectpicker').selectpicker('refresh');
}else{
$(this).parents(".div_img_part-2").find(".selectpicker").attr("disabled",true);
$('.selectpicker').selectpicker('refresh');
}
});
});
</script>
Firstly Select
After Select(Edit)
Note:- when user selects the checkbox, the selectbox will be active at first time of registration. All my data are saved in session in Laravel please help me :(
You need to run this once the page is loaded:
$(".check-box input[type='checkbox']").trigger("change");
So the checkbox values will be recognised by the page.
I have a rental inspection page I wrote for my work. All the selected
work except anything with more than one. Like bedroom1,bathroom1, fireplace1
works fine as does all the others selections. But when bedroom2,3,4,5,
bathroom2,3,4,5 etc. are selected they do not work at all. I have a work around, just click on the first one then the 2nd etc. uses it.
I have included the bedroom.items.php file at the bottom.
Thanks in advance for any help.
<script type="text/javascript">
function fillSecondCombo()
{
var combo1 = document.getElementById('Combobox1');
var combo2 = document.getElementById('Combobox2');
var selected = combo1.options[combo1.options.selectedIndex].value;
if (selected == "attic")
{
<?php include_once "item.lists/attic.item.php"; ?>
}
else
if (selected == "basement")
{
<?php include_once "item.lists/basement.item.php"; ?>
}
else
if (selected == "bathroom1")
{
<?php include_once "item.lists/bathroom.items.php"; ?>
}
else
if (selected == "bathroom2")
{
<?php include_once "item.lists/bathroom.items.php"; ?>
}
else
if (selected == "bathroom3")
{
<?php include_once "item.lists/bathroom.items.php"; ?>
}
else
if (selected == "bathroom4")
{
<?php include_once "item.lists/bathroom.items.php"; ?>
}
else
if (selected == "bathroom5")
{
<?php include_once "item.lists/bathroom.items.php"; ?>
}
else
if (selected == "bedroom1")
{
<?php include_once "item.lists/bedroom.items.php"; ?>
}
else
if (selected == "bedroom2")
{
<?php include_once "item.lists/bedroom.items.php"; ?>
}
else
if (selected == "bedroom3")
{
<?php include_once "item.lists/bedroom.items.php"; ?>
}
else
if (selected == "bedroom4")
{
<?php include_once "item.lists/bedroom.items.php"; ?>
}
else
if (selected == "bedroom5")
{
<?php include_once "item.lists/bedroom.items.php"; ?>
}
else
if (selected == "cooling")
{
<?php include_once "item.lists/cooling.item.php"; ?>
}
else
if (selected == "diningroom")
{
<?php include_once "item.lists/diningroom.item.php"; ?>
}
else
if (selected == "electric")
{
<?php include_once "item.lists/electric.item.php"; ?>
}
else
if (selected == "water")
{
<?php include_once "item.lists/water.item.php"; ?>
}
else
if (selected == "gas")
{
<?php include_once "item.lists/gas.item.php"; ?>
}
else
if (selected == "exterior")
{
<?php include_once "item.lists/exterior.item.php"; ?>
}
else
if (selected == "foundation")
{
<?php include_once "item.lists/foundation.item.php"; ?>
}
else
if (selected == "garage")
{
<?php include_once "item.lists/garage.item.php"; ?>
}
else
if (selected == "heating")
{
<?php include_once "item.lists/heating.item.php"; ?>
}
else
if (selected == "interior")
{
<?php include_once "item.lists/interior.item.php"; ?>
}
else
if (selected == "kitchen")
{
<?php include_once "item.lists/kitchen.item.php"; ?>
}
else
if (selected == "laundry")
{
<?php include_once "item.lists/laundry.item.php"; ?>
}
else
if (selected == "roof")
{
<?php include_once "item.lists/roof.item.php"; ?>
}
else
if (selected == "waterhtr")
{
<?php include_once "item.lists/waterhtr.item.php"; ?>
}
else
if (selected == "livingroom")
{
<?php include_once "item.lists/livingroom.item.php"; ?>
}
else
if (selected == "fireplace1")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "fireplace2")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "fireplace3")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "fireplace4")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "fireplace5")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "fireplace10")
{
<?php include_once "item.lists/fireplace.items.php"; ?>
}
else
if (selected == "poolspa")
{
<?php include_once "item.lists/poolspa.item.php"; ?>
}
else
if (selected == "other")
{
<?php include_once "item.lists/other.item.php"; ?>
}
else
{
combo2.options.length = 0;
}
}
</script>
</head>
<body>
<div id="space"><br></div>
<div id="container">
<button id="AdvancedButton1" type="button" style="position:absolute;left:19px;top:119px;width:137px;height:44px;z-index:12;" onclick="window.location='main.php'" name="Your Account" value="">
<div style="text-align:center"><span style="color:#FFFFFF;font-family:Arial;font-size:16px"><b>Main Menu</b></span></div>
</button>
<button id="AdvancedButton2" type="button" style="position:absolute;left:176px;top:119px;width:124px;height:44px;z-index:13;" onclick="window.location='logout.php'" name="Logout" value="">
<div style="text-align:center"><span style="color:#FFFFFF;font-family:Arial;font-size:16px"><b>Logout</b></span></div>
</button>
<div id="wb_Form1" style="position:absolute;left:20px;top:209px;width:302px;height:574px;z-index:14;">
<form name="Form1" method="post" action="make.all.php" enctype="multipart/form-data" id="Form1" onsubmit="return ValidateForm1(this)">
<textarea name="a4" id="TextArea1" style="position:absolute;left:1px;top:275px;width:279px;height:143px;z-index:0;" rows="7" cols="32" tabindex="4"></textarea>
<div id="wb_Text5" style="position:absolute;left:4px;top:249px;width:152px;height:16px;z-index:1;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;">Notes: 300 Chars Max.</span></div>
<div id="wb_Text4" style="position:absolute;left:0px;top:164px;width:170px;height:16px;z-index:2;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;">Passed-Needs Repare-N/A:</span></div>
<select name="a2" size="1" id="Combobox2" style="position:absolute;left:0px;top:109px;width:280px;height:43px;z-index:3;" tabindex="2">
</select>
<div id="wb_Text3" style="position:absolute;left:4px;top:85px;width:140px;height:16px;z-index:4;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;">Item Being Inspected:</span></div>
<select name="a1" size="1" id="Combobox1" onchange="fillSecondCombo();return false;" style="position:absolute;left:1px;top:32px;width:279px;height:43px;z-index:5;" tabindex="1">
<option value="<?php include "$dirPath/all.areas.php"; ?>"></option>
</select>
<div id="wb_Text2" style="position:absolute;left:4px;top:0px;width:142px;height:16px;z-index:6;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;">Area Being Inspected:</span></div>
<div id="wb_Text1" style="position:absolute;left:4px;top:436px;width:59px;height:16px;z-index:7;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;">Photo:</span></div>
<input type="file" id="FileUpload1" style="position:absolute;left:2px;top:452px;width:279px;height:41px;line-height:41px;z-index:8;" name="userfile[]" tabindex="5">
<input type="submit" id="Button1" name="" value="Submit" style="position:absolute;left:44px;top:513px;width:102px;height:30px;z-index:9;" tabindex="6">
<select name="a3" size="1" id="Combobox3" style="position:absolute;left:0px;top:188px;width:280px;height:43px;z-index:10;" tabindex="3">
<option selected value="Passed">Passed</option>
<option value="Needs Repair">Needs Repair</option>
<option value="N/A">N/A</option>
</select>
</form>
</div>
<div id="wb_TextArt1" style="position:absolute;left:18px;top:8px;width:285px;height:100px;z-index:15;">
<img src="images/img0018.png" id="TextArt1" alt="Enter Inspection Data" title="Enter Inspection Data" style="width:285px;height:100px;"></div>
</div>
</body>
</html>
bedroom.items.php
combo2.options.length = 9;
combo2.options[0] = new Option("Electrical Wall Plugs", "Electrical Wall Plugs");
combo2.options[1] = new Option("Walls and Ceiling", "Walls and Ceiling");
combo2.options[2] = new Option("Floor Covering", "Floor Covering");
combo2.options[3] = new Option("Windows (curtains, blinds, etc...)", "Windows (curtains, blinds, etc...)");
combo2.options[4] = new Option("Doors", "Doors");
combo2.options[5] = new Option("Lighting/Light Fixtures", "Light Fixtures");
combo2.options[6] = new Option("Closet(s)", "Closet(s)");
combo2.options[7] = new Option("Smoke Detector(s)", "Smoke Detector(s)");
combo2.options[8] = new Option("Heating/Cooling", "Heating/Cooling");
I want to check if the value of the select field is some value and if it is, it needs to echo some text.
I use this code for input box in the form:
<li>
<div class="input-box">
<strong><?php echo $this->__('Would you recommend this product to a friend?') ?></strong>
<?php foreach ( $this->getOptions() as $option ): ?>
<label class="recommend">
<input type="radio" name="recommend" id="recommend_field
<?php echo $option['value'] ?>" class="radio-gender" value="
<?php echo $option['value'] ?>"
<?php if ($option['value'] == $value)
echo ' checked="checked"' ?> >
<?php echo $this->__($option['label']) ?></input>
</label>
<?php endforeach ?>
</div>
</li>
And I currently echo the entire value of the input box with this line:
<div id="reviewwriter">
<span class="recommendation">
<?php echo $this->getAnswer() ?>
</span>
</div>
Code is loaded by this php:
public function confRecommendItemsArray()
{
$resArray = array();
if (Mage::getStoreConfig('advancedreviews/recommend_options/recommend_field1')) {
$resArray[] = array(
'value' => 1,
'label' => Mage::getStoreConfig('advancedreviews/recommend_options/recommend_field1')
);
}
if (Mage::getStoreConfig('advancedreviews/recommend_options/recommend_field2')) {
$resArray[] = array(
'value' => 2,
'label' => Mage::getStoreConfig('advancedreviews/recommend_options/recommend_field2')
);
}
And
class AW_AdvancedReviews_Block_Recommend_Field extends Mage_Core_Block_Template
{
public function canShow()
{
return (Mage::helper('advancedreviews')->confShowRecommend()
&& count(Mage::helper('advancedreviews')->confRecommendItemsArray()));
}
public function getOptions()
{
return Mage::helper('advancedreviews')->confRecommendItemsArray();
}
}
The values of the select field are
1. Yes
2. No
I want to check if value is Yes and if so echo 'Value is Yes'.
And if value is No than echo ''.
See also this JSFiddle: http://jsfiddle.net/wL3xu9d7/1/
But I do not know why it is not working.
How can I achieve that?
i hope this solution you want...
<li>
<div class="input-box">
<strong><?php echo $this->__('Would you recommend this product to a friend?') ?></strong>
<?php foreach ( $this->getOptions() as $option ): ?>
<label class="recommend">
<input type="radio" name="recommend" id="recommend_field<?php echo $option['value'] ?>" class="radio-gender" value="<?php echo $option['value'] ?>"<?php if ($option['value'] == $value) echo ' checked="checked"' ?>><?php echo $this->__($option['label']) ?></input>
</label>
<?php endforeach ?>
</div>
</li>
add hidden field on answer
<div id="reviewwriter">
<span class="recommendation" id="reviewwriteranswer">
<?php echo $this->getAnswer() ?>
</span>
</div>
<script>
$$(".radio-gender").each(function(el) {
el.observe("click", function(event) {
if(el.checked)
{
sub = $('reviewwriteranswer').value;
sub ==sub =.trim();
if(el.value==sub)
{
$('reviewwriteranswer').update('value is yes');
}else {
$('reviewwriteranswer').update('value is No');
}
}
});
});
</script>
<scrip>
var allElements = document.body.getElementsByTagName("*");
for(var i = 0; i < allElements.length; i++) {
var text = allElements[i].innerHTML;
text=text.trim();
if (text == 'Yes') {
allElements[i].innerHTML = "Value is Yes";
}
if (text == 'No') {
allElements[i].innerHTML = "Value is No";
}
}
</scrip>