How to call a variable from an outside file

Hello,
It seems to me complicated and I wish someone could help.

I’m trying simply to populate information from backend to Front End, I have The tracking number information visible in my backend and I simply want to populate those information into my front End but I don’t know how, I’m using Symfony framework and Smarty

Here is my code form Backend:

{foreach $mp_seller_order_details as $mp_order_detail}
					<tr>
						<td>{$mp_order_detail.0.seller_shop}</td>
						<td>
							<span style="background:{if isset($mp_order_detail.0.ostate_name)}{$mp_order_detail.0.color}{else}{$currentState->color}{/if};color:white !important; border-radius: 5px; padding: 5px; ">
							{if isset($mp_order_detail.0.ostate_name)}
								{$mp_order_detail.0.ostate_name}
							{else}
								{$currentState->name}
							{/if}
							</span>
						</td>
						<td>{$mp_order_detail.0.tracking_url}</td>
						<td>{$mp_order_detail.0.tracking_number}</td>
						<td><a class="btn btn-default" target="_blank" href="{$link->getAdminLink('AdminSellerInfoDetail')}&id_seller={$mp_order_detail.0.id_seller}&viewwk_mp_seller"><i class="icon-search-plus"></i> {l s='View Seller' mod='marketplace'}</a></td>
						<td>
							<a data-id="{$mp_order_detail.0.id_seller}" class="btn btn-default wk-seller-prod" href="javascript:void(0);">
								<i class="icon-search-plus"></i> {l s='View Detail' mod='marketplace'}
							</a>
						</td>
						{hook h='displayAdminPsSellerOrderViewBody' idSellerCustomer=$mp_order_detail.0.seller_customer_id}
					</tr>

So I have this line <td>{$mp_order_detail.0.tracking_number}</td>

and I have the code from Front End:

    {foreach from=$order.shipping item=line}
      <tr>
        <td>{$line.shipping_date}</td>
        <td>{$line.carrier_name}</td>
        <td>{$line.shipping_weight}</td>
        <td>{$line.shipping_cost}</td>
        <td>{$line.tracking}</td>
      </tr>
    {/foreach}
  </tbody>
</table>



<div class="hidden-md-up shipping-lines">
  {foreach from=$order.shipping item=line}
    <div class="shipping-line">
      <ul>
        <li>
          <strong>{l s='Date' d='Shop.Theme.Global'}</strong> {$line.shipping_date}
        </li>
        <li>
          <strong>{l s='Carrier' d='Shop.Theme.Checkout'}</strong> {$line.carrier_name}
        </li>
        <li>
          <strong>{l s='Weight' d='Shop.Theme.Checkout'}</strong> {$line.shipping_weight}
        </li>
        <li>
          <strong>{l s='Shipping cost' d='Shop.Theme.Checkout'}</strong> {$line.shipping_cost}
        </li>
        <li>
          <strong>{l s='Tracking number' d='Shop.Theme.Checkout'}</strong> {$line.tracking}
        </li>

How can I get

{$mp_order_detail.0.tracking_number} to Work with </strong> {$line.tracking} from second code

I’m lost here, I tried to input the variable but it is always not recognized

What is $order in the bottom file? Is it the same as $mp_order_detail in the top file?

The easiest way to figure this out is to just dump the contents of $order and see what you have available

Either you have the value available there somewhere, or you find out you need to pass it explicitly from the controller to the view.

Hello dear @JimL thanks for your input.

So I created an sql query in my class file:

/// MY CODE
    public function getTrackingInformation($idOrder, $idSeller)
    {
        $result = Db::getInstance()->getValue('SELECT `tracking_number` FROM '._DB_PREFIX_.'wk_mp_seller_order_status WHERE `id_order` ='.(int) $idOrder.' AND `id_seller` ='.(int) $idSeller);

        if ($result) {
            return $result;
			var_dump($result);
        }

        return false;
    }
    // END OF CODE  

My question is, How to call that function into my order-detail.tpl file I tried this but it doesn’t work:

<li><strong>Tracking#</strong> {isset($getTrackingInformation)}</li>

Usually you don’t want your views to call backend code. Can’t you just call it in the controller and pass it to the view?

I still got no luck:
I updated my code and put it into the controller:

/// MY CODE
    public function getTrackingInformation($idOrder, $idSeller)
    {
        $TrackingNumberDetail = Db::getInstance()->getValue('SELECT `tracking_number` FROM '._DB_PREFIX_.'wk_mp_seller_order_status WHERE `id_order` ='.(int) $idOrder.' AND `id_seller` ='.(int) $idSeller);

        if ($TrackingNumberDetail) {
           
			$this->context->smarty->assign('TrackingNumberInfo', $TrackingNumberDetail->TrackingNumberInfo);
			
        }

        return false;
    }
    // END OF CODE  

My view:

`<li><strong>Tracking#</strong> {isset($TrackingNumberInfo)}</li>`

Nothing is displayed, can you help me please

Sorry I haven’t used Smarty for so long I no longer have any Smarty-fu. Hopefully someone else here can pitch in.

Are you able to pass through anything? Ie a simple string. Surely this app has lots of examples of data passed from the db via the controller to the view…?

Hi,
I’m still stuck, I did a test with a very simple function and it is still not showing anything or it throws an error : undefined index

public function SayHello (){
		$HelloWorld = "Hello World";
		$this->context->smarty->assign('HelloWorld' , $HelloWorld);
	}

View: <li><strong>Tracking#</strong> {$HelloWorld}</li>

Shows nothing, can you spot the error in this code?

Sponsor our Newsletter | Privacy Policy | Terms of Service