Osclass forums

Support forums => Themes => Twitter => Topic started by: design on June 18, 2014, 10:17:56 pm

Title: how to add a function? or extend it?
Post by: design on June 18, 2014, 10:17:56 pm
I am trying to work on the price fields error that occurs in twitter related themes.
so the error:

when you select on a category and if the price should not be shown it should hide the price field.

I have narrowed it down to a script in the core, but I don't want to change the core-- duh!

so how do I bring that function over into the themes function?

here is the cores syntax(is that the right term?) that I want into the theme

Code: [Select]
static public function plugin_post_item($case = 'form') {
?>
<script type="text/javascript">
var catPriceEnabled = new Array();
<?php
$categories Category::newInstance()->listAll(false);
foreach($categories as $c) {
echo 'catPriceEnabled['.$c['pk_i_id'].'] = '.$c['b_price_enabled'].';';
}
?>

    $("#catId").change(function(){
        var cat_id = $(this).val();
        <?php if(OC_ADMIN) { ?>
        var url = '<?php echo osc_admin_base_url(true); ?>';
        <?php } else { ?>
        var url = '<?php echo osc_base_url(true); ?>';
        <?php ?>
        var result = '';

        if(cat_id != '') {
if(catPriceEnabled[cat_id] == 1) {
$("#price").closest("div").show();
} else {
$("#price").closest("div").hide();
$('#price').val('') ;
}

            $.ajax({
                type: "POST",
                url: url,
                data: 'page=ajax&action=runhook&hook=item_<?php echo $case;?>&catId='   cat_id,
                dataType: 'html',
                success: function(data){
                    $("#plugin-hook").html(data);
                }
            });
        }
    });
    $(document).ready(function(){
        var cat_id = $("#catId").val();
        <?php if(OC_ADMIN) { ?>
        var url = '<?php echo osc_admin_base_url(true); ?>';
        <?php } else { ?>
        var url = '<?php echo osc_base_url(true); ?>';
        <?php ?>
        var result = '';

        if(cat_id != '') {
if(catPriceEnabled[cat_id] == 1) {
$("#price").closest("div").show();
} else {
$("#price").closest("div").hide();
$('#price').val('') ;
}

            $.ajax({
                type: "POST",
                url: url,
                data: 'page=ajax&action=runhook&hook=item_<?php echo $case;?>&catId='   cat_id,
                dataType: 'html',
                success: function(data){
                    $("#plugin-hook").html(data);
                }
            });
        }
    });
</script>
<div id="plugin-hook">
</div>
Title: Re: (teseo!! help needed) how to add a function? or extend it?
Post by: teseo on June 18, 2014, 10:39:52 pm
Hi :)

I couldn't see anything there requiring other ItemForm class functions or properties, so I think it could work just like that, copy the whole function static public function plugin_post_item($case = 'form') in your theme functions.php renaming the function, i.e. cust_plugin_post_item:

Code: [Select]
function cust_plugin_post_item($case = 'form') {
ant then change in item-post.php:

Code: [Select]
                        if($edit) {
                            ItemForm::plugin_edit_item();
                        } else {
                            // ItemForm::plugin_post_item(); // Vanilla
                           cust_plugin_post_item();

                        }

Regards
Title: Re: how to add a function? or extend it?
Post by: design on June 18, 2014, 11:47:41 pm
so close I can taste it!!


it still shows an inline display none
Title: Re: how to add a function? or extend it?
Post by: teseo on June 19, 2014, 12:12:24 am
And isn't that the desired effect? ???

Regards
Title: Re: how to add a function? or extend it?
Post by: design on June 19, 2014, 12:16:00 am
no, if the category selected has the price enabled it should show it and it's not.


maybe this? in function


if(cat_id != '') {
         if(catPriceEnabled[cat_id] == 1) {
            $("#price").closest("div").show();
         } else {
            $("#price").closest("div").hide();
            $('#price').val('') ;
         }
I try so many things.... head exploded..try tomorrow
Title: Re: how to add a function? or extend it?
Post by: itcafeonline on September 30, 2014, 07:18:00 am
Were you able to get this working? if yes - can you please help?
Title: Re: how to add a function? or extend it?
Post by: design on October 02, 2014, 07:25:24 pm
yes..let me find the code. BRB, sorry I forgot to update this thread :-(  :-X
Title: Re: how to add a function? or extend it?
Post by: design on October 02, 2014, 07:57:45 pm
there is a JS one also, but I can't find it. this goes in item.php or depending on your theme

<?php if ( osc_price_enabled_at_items() && osc_item_price() != '' ) { ?>
        <strong>
        <?php printf( '%s', osc_format_price(osc_item_price()) ); ?>
        </strong>
<?php } else { ?>
         <strong><?php _e( 'Ask seller for price', ‘your theme ); ?></strong>
<?php } ?>
Title: Re: how to add a function? or extend it?
Post by: itcafeonline on October 02, 2014, 10:52:24 pm
Thank You - design...

Will test this out..