Jump to content

[SOLVED] How can i pass variables to the view?


arkanimus

Recommended Posts

Hi all !!

 

in the controller i have the variable $cantidad , but the view did no take the value:

 

the file is : shopping-cart.tpl

 

<span id="total_price">{displayPrice price=($total_price-$cantidad)}</span>

 

Notice: Undefined index: cantidad in /var/www/mayorista10/cache/smarty/compile/2f5c149962cab8fc9bc0c9e32fc32772758fbf56.file.shopping-cart.tpl.php on line 356 Notice: Trying to get property of non-object in /var/www/mayorista10/cache/smarty/compile/2f5c149962cab8fc9bc0c9e32fc32772758fbf56.file.shopping-cart.tpl.php on line 356 $ 854

 

how can i solve it??

Edited by vekia (see edit history)
Link to comment
Share on other sites

 

If $smarty object is initiated inside your controller, you can then assign a new variable and it's value:

 

controller file:

$smarty->assign('cantidad','1234');

template file:

echo $cantidad //this sould echo '1234'

ups! smarty is no inicialized but my code is the following:

 

 Controller File:
    if(Tools::issubmit('ingresaCajas'))
        {
            $cantidad = Tools::getValue('txtCajas');
            echo 'Try cantidad'.$cantidad;     
        }

 can i write echo $cantidad into tpl file?
 
Thank's 4 reply
Edited by arkanimus (see edit history)
Link to comment
Share on other sites

 

ups! smarty is no inicialized but my code is the following:

 

 Controller File:
    if(Tools::issubmit('ingresaCajas'))
        {
            $cantidad = Tools::getValue('txtCajas');
            echo 'Try cantidad'.$cantidad;     
        }

 can i write echo $cantidad into tpl file?
 
Thank's 4 reply

 

 

definitely NOT echo $cantidad; in .tpl

in .tpl you have to use {$cantidad}

Link to comment
Share on other sites

Solved:
 
In the View:
 
 
<form action="{if $opc}{$link->getPageLink('order-opc', true)}{else}{$link->getPageLink('order', true)}{/if}"  method="post" id="formcajas"><fieldset>


<h4><label for="lblCajas">{l s='Cajas'}</label></h4>
<p>
<input type="text" class="cajas" id="txtCajas" name="txtCajas"/>
</p>          
<p class="submit"><input type="hidden" name="ingresaCajas" /><input type="submit" name="ingresaCajas" value="{l s='OK'}" class="button" /></p>
</fieldset>
</form>


<span id="total_price">{displayPrice price=($total_price-$cantidad2)}</span>
 
In the Controller:

 if(Tools::issubmit('ingresaCajas'))
        {
            $cantidad = Tools::getValue('txtCajas');
            echo 'Try cantidad'.$cantidad;     
        }


$this->context->smarty->assign('cantidad2', $cantidad); 

Thank you!

Edited by arkanimus (see edit history)
Link to comment
Share on other sites

  • 3 months later...
Hi ,

 

I need help, there's my problem :

 

in the  order page  there's this sentence " Your cart contains products x "  I want to change it to  " Your cart contains items x and x products " for example if my order contains 3 products ( same product quantity 3) the sentence becomes " Your cart contains 3 items and 1 product " ,  in the folder  classes file Cart.php I added this function to count the number of products :

 

public function NbrProducts ()

{ If (! $ This-> id)

return 0;

Cart :: getNbrProducts return ($ this -> id) ;

}

public static function getNbrProducts ($ id)

{If ( isset ( self :: $ NbrProducts [$ id] ) && self :: $ NbrProducts [$ id] ! == Null)

return self :: $ NbrProducts [$ id] ;

self :: $ NbrProducts [ $ id ] = (int) Db :: getInstance () -> getValue ('

SELECT COUNT (DISTINCT ` ` id_product )

FROM '. _DB_PREFIX_ . ' Cart_product `

WHERE ` id_cart ` = ' . (Int) $ id

) ;

return self :: $ NbrProducts [$ id] ;

}

 

I do not know what the next step to see the query result in the shopping- cart.tpl file ?

I hope you understand me , and that someone can help me!

 

thank you!

Link to comment
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
×
×
  • Create New...