Advertisement:

Author Topic: how to add a function? or extend it?  (Read 2213 times)

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
how to add a function? or extend it?
« 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>
« Last Edit: June 18, 2014, 11:18:04 pm by design »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: (teseo!! help needed) how to add a function? or extend it?
« Reply #1 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

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: how to add a function? or extend it?
« Reply #2 on: June 18, 2014, 11:47:41 pm »
so close I can taste it!!


it still shows an inline display none

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: how to add a function? or extend it?
« Reply #3 on: June 19, 2014, 12:12:24 am »
And isn't that the desired effect? ???

Regards

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: how to add a function? or extend it?
« Reply #4 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
« Last Edit: June 19, 2014, 01:40:03 am by design »

itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: how to add a function? or extend it?
« Reply #5 on: September 30, 2014, 07:18:00 am »
Were you able to get this working? if yes - can you please help?

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: how to add a function? or extend it?
« Reply #6 on: October 02, 2014, 07:25:24 pm »
yes..let me find the code. BRB, sorry I forgot to update this thread :-(  :-X

design

  • Hero Member
  • *****
  • Posts: 2619
  • Osclass 3.5 MAC/PC w/ Modern Browsers
Re: how to add a function? or extend it?
« Reply #7 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 } ?>

itcafeonline

  • Full Member
  • ***
  • Posts: 245
Re: how to add a function? or extend it?
« Reply #8 on: October 02, 2014, 10:52:24 pm »
Thank You - design...

Will test this out..