Jump to content

[SOLVED] Need help figure out php code in module


augis2003
 Share

Recommended Posts

Hi,

i'm trying to make my first module. It will take customer address from order, and print postcode in order view.

My code looks like:

public function getCode()
	{

$add =( 'http://postit.lt/data/?address=' . $this->ad->address1 .' ' . "+" . ' ' . $this->ad->city . '' );
$url = str_replace(' ', '%20', $add);

$json = file_get_contents($url);

$result = json_decode($json, true);


if($result['total'] < 3) {
$suc = $result['data'][0]['post_code'];
echo "Pašto kodas yra: " . "LT-". $suc;
}else{
echo "Pašto kodas nerastas"; }
}
	
   function hookAdminOrder($params) {
    	$display = '
		
			<br /><fieldset style="width: 400px">
				<legend><img src="../modules/'.$this->name.'/logo.png" /> '.$this->l('Pašto Kodas').'</legend>
				<img src="../modules/'.$this->name.'/logo.png" />'.$this->l(' Pašto kodas yra: ').' ' . $this->getCode() .' ' . "TEXT NEED HERE" . '<br />
				 
			</fieldset>
		';
		return $display;
		
    }

My problem is about view in admin side, please see attachment post-619384-0-96964100-1380095737_thumb.png. Maybe someone can bring me idea what i'm doing wrong?

Share this post


Link to post
Share on other sites

you've got in code: 

<img src="../modules/'.$this->name.'/logo.png" />'.$this->l(' Pašto kodas yra: ').' ' . $this->getCode() .' ' . "TEXT NEED HERE" . '<br />

 

 

so it shows this text instead of function results

Share this post


Link to post
Share on other sites

But if i change to this:

function hookAdminOrder($params) {
    	$display = '
		
			<br /><fieldset style="width: 400px">
				<legend><img src="../modules/'.$this->name.'/logo.png" /> '.$this->l('Pašto Kodas').'</legend>
				' . $this->getCode() .'
				 
			</fieldset>
		';
		return $display;
		
    }

nothing changing, my function still show in top of form..post-619384-0-42743300-1380098882_thumb.png

Share this post


Link to post
Share on other sites

instead of echo use return, in code:

if($result['total'] < 3) {
$suc = $result['data'][0]['post_code'];
echo "Pašto kodas yra: " . "LT-". $suc;
}else{
echo "Pašto kodas nerastas"; }
}

change it to:

if($result['total'] < 3) {
$suc = $result['data'][0]['post_code'];
return "Pašto kodas yra: " . "LT-". $suc;
}else{
return "Pašto kodas nerastas"; }
}

will work :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More