View Single Post
  #8  
Old 09-26-2012, 06:20 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Customize invoice based on product purchased

James, in each template that you are working in you need to make sure that the variable you are trying to access is actually assigned, and that it contains the info you are looking for. Watch my tuts on webmaster mode to see how I would figure this out. Another way to check this is to use print_r Try just putting {$order|@print_r} to output the entire arrays contents.

The reason that your code is not working is very simple, $order does not actually contain the code you are looking for! In this template the products have been assigned to the $products array. To understand why, take a look at /common_files/customer/main/order_message.tpl look at the code that calls /common_files/mail/html/order_invoice.tpl
Line 42:
Quote:
{foreach from=$orders item=order}
{include file="mail/html/order_invoice.tpl" is_nomail='Y' products=$order.products giftcerts=$order.giftcerts userinfo=$order.userinfo order=$order.order}
<br />
See how the template include, also assigns the variable "products" to $order.products and reassigns "order" to $order.order? That is how the $products array gets populated, and the reason that $order mysteriously doesn't contain the products array.

Smarty is a very easy, forgiving language and it tolerates simple mistakes, but since you are bent on learning I want to point out the ones in this code. (Commented)
PHP Code:
{assign var="ordered8" value=0
{*
/* You can drop the "" quotes around ordered8,
after all you are assigning a variable not
passing a string. */
*}

{foreach 
from=$order.products item=product}
{*
/* Here is the important change: 
     $products instead of $order.products 
*/
*}

  {if 
$product.productid eq "8"}
  {*
/* again drop the quotes around 8, it is an integer. */*}

   {
assign var="ordered8" value=1
   {*
/* ditto */*}

  {/if}
{/foreach}  

{if 
$ordered8 eq 1}
  
extra thank you
{else}
no thank you for you
 
{/if}
{*
/* ^Straighten up that spacing soldier!
     Form up those lines! :-)
*/
*} 

Hope that explains it in a way that you can apply elsewhere. Have a good one!

-Mike
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote