CodeIgniter Forums
misc_helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: misc_helper (/showthread.php?tid=64483)

Pages: 1 2


misc_helper - malbe - 02-24-2016

Hello 

I'm new to CodeIgniter, so go easy on me, we've had an ecommerce system built using version 2  which after going through the code the developer had created a misc_helper which is used to get the price and suggested selling price for an item, now my PHP skills are a lot to be desired to say the least, I'm more front end stuff and it is beyond me what is actually happening and why the developer has done it this way, and I can't get hold of him to ask him!

Anyway in the view file we have the following line of code:
Code:
<p>Price: <?php $price = misc::display_price( $price, $user_no ); ?></p>
which produces the following when the view is rendered to the browser:

Price £9.99

Suggested Selling Price £29.99

From what I can see is it's related to this helper code below, what I would like to do is separate the two prices, output's to the view file so I can move them around the page where I need them but for the live of me I can't figure out how to do it?? 
I have attached the misc_helper.php so you can see the full code of how it is made up.
Code:
static function display_price( $oprice, $user_no ) {
if( !empty( $oprice ) ) {
$prices = self::get_available_prices( $oprice, $user_no );

echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

echo '<br/><br/>';

if( $prices[ 'charge_out' ] > 0 )
echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

return $prices[ 'price' ];
}

echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

return $oprice;
}

Thanks in advance, I don't normally ask for this type of help, but to be honest I've tried every way I know with my small amount of php knowledge to no avail, and it's driving me nuts.

.php   misc_helper.php (Size: 4.39 KB / Downloads: 88)

Cheers

Malc


RE: misc_helper - malbe - 02-25-2016

Hi can anyone help with this? or am I in the wrong forum if so can someone point me in the right direction to help with this..

All I require it to do is on the view page it displays as
Price £9.99

Suggested Selling Price £29.99

I need it to display as either Price & Suggested Selling Price as it does and Just price in a different location on the view page
sorry but I have no idea about CodeIgniter or helps and very limited knowledge of PHP

Regards

Malc


RE: misc_helper - Narf - 02-25-2016

I've moved your thread to the appropriate forum section, but be patient - everybody around here will only help you out of good will and if/when they have the time to do it. Sometimes you get quick replies and sometimes you have to wait a few days, it's not appropriate to bump a thread after less than 24 hours of inactivity.


RE: misc_helper - solidcodes - 02-25-2016

Not tested but try experimenting by removing the RETURN.
Code:
    static function display_price( $oprice, $user_no ) {
        if( !empty( $oprice ) ) {
            $prices = self::get_available_prices( $oprice, $user_no );

            echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

            echo '<br/><br/>';

            if( $prices[ 'charge_out' ] > 0 )
                echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

            //return $prices[ 'price' ];
        }

        echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

        return $oprice;
    }

or

Code:
    static function display_price( $oprice, $user_no ) {
        if( !empty( $oprice ) ) {
            $prices = self::get_available_prices( $oprice, $user_no );

            echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

            echo '<br/><br/>';

            if( $prices[ 'charge_out' ] > 0 )
                echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

            return $prices[ 'price' ];
        }

        echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

        //return $oprice;
    }

Try it.
It's not easy to debug the codes without seeing the actual live result.
But let me know the output.


RE: misc_helper - solidcodes - 02-25-2016

Or try by removing the echo

Code:
    static function display_price( $oprice, $user_no ) {
        if( !empty( $oprice ) ) {
            $prices = self::get_available_prices( $oprice, $user_no );

            //echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

            echo '<br/><br/>';

            if( $prices[ 'charge_out' ] > 0 )
                echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

            return $prices[ 'price' ];
        }

        echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

        return $oprice;
    }

or

Code:
    static function display_price( $oprice, $user_no ) {
        if( !empty( $oprice ) ) {
            $prices = self::get_available_prices( $oprice, $user_no );

            echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

            echo '<br/><br/>';

            if( $prices[ 'charge_out' ] > 0 )
                //echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

            return $prices[ 'price' ];
        }

        echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

        return $oprice;
    }

or

Code:
    static function display_price( $oprice, $user_no ) {
        if( !empty( $oprice ) ) {
            $prices = self::get_available_prices( $oprice, $user_no );

            echo '<strong>'.CURRENCY.number_format( $prices[ 'price' ], 2 ).'</strong>';

            echo '<br/><br/>';

            if( $prices[ 'charge_out' ] > 0 )
                echo 'Suggested selling price:<strong>'.CURRENCY.number_format( $prices[ 'charge_out' ], 2 ).'</strong><br/><br/>';

            return $prices[ 'price' ];
        }

        //echo '<strong>'.CURRENCY.number_format( 0, 2 ).'</strong>';

        return $oprice;
    }


Don't be afraid to experiment, but don't forget to backup the codes/files first.


RE: misc_helper - malbe - 02-25-2016

Thanks it's probably me not wording it right, I think you misunderstood

I want the Price & Suggested Selling price to remain where they are in the view.

What I'm trying achieve  see the attached image, so it will show the price and suggested selling price where they currently are on the page, then I can show ONLY the price somewhere else on the page, in this instance It's in red below the add to cart button as an example.

This is probably still as clear as mud to you? I can give you access to the development code to look at if that helps


RE: misc_helper - Diederik - 02-25-2016

Why not just copy the display_price function to a new function called display_suggested_price and have it only output the wanted data.

And choose what you want to do. In a helper you should choose if you want to use echo or return, not use both. Either call the helper function from within your viewfile and use echo in the hlper. Or use return in the function and have the output stored in a variable inside your controller and pass the variable to the viewfile so you can echo the variable there.


RE: misc_helper - malbe - 02-25-2016

Hi Diederik,

Can you give me an example as to be honest I haven't a clue wtf the developer has done, or much what you are saying I'm not a PHP or CodeIgniter expert at any level to be honest, so although I vagually understand what you mean I have no idea how to put it in to practice.
I just want to be able to separate the two so I can use them where ever I need them if that makes sense??

I am used to moving the code around the page such as if it was like these variables

<?php echo $price ['price']; ?>

<?php echo $ssprice ['suggested_selling_price']; ?>

Cheers

Malc


RE: misc_helper - solidcodes - 02-25-2016

@malbe

Did you tried my codes above?
What is the output/result when you do each of them?
Can you provide screen shots each of them?
Can you provide the URL?


RE: misc_helper - Diederik - 02-25-2016

I would suggest using something like the example below. The function returns the wanted data (a string containing the suggesting price) if it exists, otherwise it will return false. I rename the function from display_ to get_ to reflect the action of the function, it gets the data so you can use it (not display it immediately as the display_ naming would suggest).



PHP Code:
function get_suggested_price$oprice$user_no ) {

 
   if( !empty( $oprice ) ) {

 
       $prices self::get_available_prices$oprice$user_no );

 
       if$prices'charge_out' ] > ) {

 
           return CURRENCY.number_format$prices'charge_out' ], );        

        
}

 
   }

 
   return FALSE;