samedi 3 janvier 2015

call all available options of product

There is a site on openkart engine which is available to add to the product. In the form of adding an item there is a tab Options. Where you can add the option by using the drop-down list. I want all the available options have been caused by force.


the page url "moidom.kiev.ua"


add product link http://ift.tt/1Bi6IV9


I want to call all the options available in separate blocks. Learning programming myself, please do not judge strictly. really need help.


so here my code


html.part



<div class="ms-options">
<p class="error" id="error_options"></p>


<div>
<?php foreach($options as $option) { ?>
<div id="<?php echo $option['option_id']?>"></div>
<?php echo addoption($option['option_id']) ?>
<?php } ?>
</div>
</div>


js.part (file)



$(function() {
function addoption(optionid) {

var option_id = optionid;
$.get($('base').attr('href') + 'index.php?route=seller/account-product/jxRenderOptionValues&option_id=' + option_id, function(data) {


$('div.'.optionid).append(data);
});
});
};
});


pls hlp!


this is original html code



<div class="ms-options">
<p class="error" id="error_options"></p>

<div class="options"></div>

<div>
<select name="options[0]" class="select_option">
<option value="0" disabled="disabled" selected="selected"><?php echo $ms_options_add; ?></option>
<?php foreach($options as $option) { ?>
<option value="<?php echo $option['option_id']?>"><?php echo $option['name']; ?></option>
<?php } ?>
</select>
</div>
</div>


js.file



$('body').delegate(".select_option", "change", function() {
$(this).children(':selected').attr('disabled', 'disabled');
var option_id = $(this).children(':selected').val();
var select = this;

$.get($('base').attr('href') + 'index.php?route=seller/account-product/jxRenderOptionValues&option_id=' + option_id, function(data) {
var lastRow = $(select).parents('.ms-options').find('.option:last input:last').attr('name');

if (typeof lastRow == "undefined") {
var newRowNum = 1;
} else {
var newRowNum = parseInt(lastRow.match(/[0-9]+/g).shift()) + 1;
}

var data = $(data);
data.find('input,select').attr('name', function(i,name) {
if (name) return name.replace('product_option[0]','product_option[' + newRowNum + ']');
});
$('div.options').append(data);
});
$(this).val(0);
});

Aucun commentaire:

Enregistrer un commentaire