Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Smarty Variables in {php} Rate Topic   - - - - -

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 04 May 2010 - 02:39 PM #1

In version 1.3.5, I used the following to pull Smarty variables into some PHP code in a template:
{php}
global $smarty;
$skins = $smarty->_tpl_vars['skin_dir'];
{/php}
In version 2.0, this isn't working. Anyone know how I can use a Smarty variable inside {php}{/php} tags?
7 CS-Cart licenses - 2.2 through 4.2

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 04 May 2010 - 03:53 PM #2

Turns out I can do everything I needed to do with Smarty alone. However, the following code is returning the {else} result, and I know the file exists. Any ideas?
{if file_exists("/store/skins/basic/customer/images/head-profile-details.jpg")}
1
{else}
0
{/if}

7 CS-Cart licenses - 2.2 through 4.2

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 04 May 2010 - 04:26 PM #3

Dear silly Borat, you are going off your html or www folder, the proper way is to go from the root folder, it is not finding the file since the path is off. (you are confusing how browsers and php see paths)

do:

echo dirname(__file__); (or similar)

or look in phpinfo() for the actual path...

it will be like /var/www/mysite/htmldocs/store/skins/basic/customer/images/head-profile-details.jpg

Once you will find the FULL path to the file, use that. You can also use $_SERVER values..
PM me today for design/coding projects :P

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 04 May 2010 - 04:36 PM #4

To help you with your original question, do this:

{php}
echo '<pre>';
print_r(get_defined_vars());
{/php}

It will print a list of all smarty variables in the array and what values hold them. The list will be extensive but complete. Thus, then you can easily find your value and know how to access it.
PM me today for design/coding projects :P

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 04 June 2010 - 08:49 PM #5

I saw the list of all variables, and the one I need to access is: [this] => [_tpl_vars] => [cart] => [subtotal]

So, how do I get it's value into my {php} stuff?
7 CS-Cart licenses - 2.2 through 4.2

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 04 June 2010 - 09:32 PM #6

My untested but educated guess would be
{php}
echo $this->_tpl_vars['cart']['subtotal'];
{/php}

Checkout: http://forum.cs-cart...ead.php?t=17286
PM me today for design/coding projects :P

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 07 June 2010 - 12:57 PM #7

Do you have any idea where the shopping cart subtotal would be stored? When I access get_defined_vars() on a product page, the [cart] array is not present - even when I have items in my cart. My cart subtotal is $89.98, but that number is not in the get_defined_vars() text anywhere. Strange.
7 CS-Cart licenses - 2.2 through 4.2

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 07 June 2010 - 03:23 PM #8

That is weird. But the subtotal is in the [cart][subtotal]

[cart] => Array
.....(
..........[products] => Array
...............(
....................[3144010713] => Array
.........................(
..............................[product_id] => 29924
..............................[amount] => 1
..............................[product_options] => Array
...................................(
........................................[1502] => 12455
........................................[747] => 3185
........................................[795] => 3679
...................................)

..............................[price] => 259.99
..............................[stored_price] => N
..............................[extra] => Array
...................................(
........................................[product_options] => Array
.............................................(
..................................................[1502] => 12455
..................................................[747] => 3185
..................................................[795] => 3679
.............................................)

........................................[return_period] => 10
...................................)

..............................[stored_discount] => N
..............................[return_period] => 10
..............................[modifiers_price] => 0
..............................[is_edp] =>
..............................[edp_shipping] =>
..............................[base_price] => 259.99
..............................[display_price] => 259.99
.........................)

....................[3981506623] => Array
.........................(
..............................[product_id] => 29784
..............................[amount] => 1
..............................[product_options] => Array
...................................(
........................................[1048] => 7083
........................................[1049] => 7089
........................................[1050] => 7093
........................................[1051] => 7097
...................................)

..............................[price] => 59.99
..............................[stored_price] => N
..............................[extra] => Array
...................................(
........................................[product_options] => Array
.............................................(
..................................................[1048] => 7083
..................................................[1049] => 7089
..................................................[1050] => 7093
..................................................[1051] => 7097
.............................................)

........................................[return_period] => 10
...................................)

..............................[stored_discount] => N
..............................[return_period] => 10
..............................[modifiers_price] => 0
..............................[is_edp] =>
..............................[edp_shipping] =>
..............................[base_price] => 59.99
..............................[display_price] => 59.99
.........................)

...............)

..........[recalculate] =>
..........[user_data] => Array
...............(
...............)

..........[tax_subtotal] => 0
..........[discount] => 0
..........[total] => 319.98
..........[amount] => 2
..........[pure_subtotal] => 319.98
..........[subtotal] => 319.98
..........[use_discount] =>
..........[shipping_required] => 1
..........[shipping_failed] => 1
..........[stored_taxes] => N
..........[shipping_cost] => 0
..........[display_shipping_cost] => 0
..........[coupons] => Array
...............(
...............)

..........[free_shipping] => Array
...............(
...............)

..........[options_style] => F
..........[no_promotions] => 1
..........[promotions] => Array
...............(
...............)

..........[subtotal_discount] => 0
..........[shipping] => Array
...............(
...............)

..........[taxes] => Array
...............(
...............)

..........[display_subtotal] => 319.98
..........[payment_surcharge] => 0
.....)
PM me today for design/coding projects :P

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 07 June 2010 - 04:21 PM #9

For me, [cart][subtotal] shows up on the shopping cart page, but I don't get it on the home page, category pages, or product pages. Do you have the variable there?
7 CS-Cart licenses - 2.2 through 4.2

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 07 June 2010 - 04:47 PM #10

Ok, you owe me. :) I spent like 30 mins looking for a solution.

1) you are right, on categories the [cart] is not available.
2) however, you still see in the header the total for your cart
3) found that you can get that number with: {$smarty.session.cart.display_subtotal}
PM me today for design/coding projects :P

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 07 June 2010 - 06:20 PM #11

BUT... can you get the value of {$smarty.session.cart.display_subtotal} to work inside {php}{/php}? I tried, but I got an error message.
7 CS-Cart licenses - 2.2 through 4.2

 
  • TexasGuy
  • Senior Member
  • Members
  • Join Date: 18-Mar 10
  • 546 posts

Posted 07 June 2010 - 06:25 PM #12

My understanding:

{assign var="subtotal" value=$smarty.session.cart.display_subtotal}

{php}
echo $this->_tpl_vars['subtotal'];
{/php}
PM me today for design/coding projects :P

 
  • grayloon
  • Senior Member
  • Members
  • Join Date: 29-May 08
  • 450 posts

Posted 07 June 2010 - 06:30 PM #13

That works!

Pure genius.Thank you!
7 CS-Cart licenses - 2.2 through 4.2

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10673 posts

Posted 07 June 2010 - 08:17 PM #14

print_r($_SESSION['cart']) will show you what you need.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • pradeesh_72
  • Member
  • Trial users
  • Join Date: 15-Nov 17
  • 42 posts

Posted 26 December 2017 - 06:52 AM #15

May be a bit late, but good old {$var |@print_r} is the prettiest solution I guess.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 17613 posts

Posted 26 December 2017 - 01:19 PM #16

May be a bit late, but good old {$var |@print_r} is the prettiest solution I guess.

 

More readable way with CS-Cart function

{$var|fn_print_r}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 10673 posts

Posted 26 December 2017 - 07:12 PM #17

And if you don't want it blasting over your screen, you can put it in comment like:

<!-- {$var|print_r:true} -->

Then just use the browser inspector to see the results.  You don't destroy ajax response or other things this way.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.