Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Customize invoice based on product purchased

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-19-2012, 05:42 PM
 
chiactivate chiactivate is offline
 

Senior Member
  
Join Date: Feb 2007
Location: Canada
Posts: 148
 

Default Customize invoice based on product purchased

Anyone know how to customize this?

I want to show the different message in the invoice based on the product.

After customer has completed the order, an invoice be show at the thank you page and another email will be send by email.

How can I.

add message A invoice A (product A)
add message B in invoice B (product B)

is there a solution already?
__________________
www.ChiMassager.com
X-cart Version 4.44

www.SEOMarketing30days.com
--> Download FREE SEO marketing Ebook (valued $50)
Attract more visitors and sales with top 5 most powerful SEO marketing strategies. Converting visitors into buyers, not just traffic!
Reply With Quote
  #2  
Old 09-20-2012, 04:53 AM
  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

You would need to loop through all the products in the order with a foreach loop, and write an if statement inside the loop that tested for the productids.
__________________
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

The following user thanks totaltec for this useful post:
chiactivate (09-20-2012)
  #3  
Old 09-20-2012, 10:17 AM
 
chiactivate chiactivate is offline
 

Senior Member
  
Join Date: Feb 2007
Location: Canada
Posts: 148
 

Default Re: Customize invoice based on product purchased

thanks Total Tech!

How do I create that loop with if statement and how to find the productids?

I know how how to create a new invoice.
__________________
www.ChiMassager.com
X-cart Version 4.44

www.SEOMarketing30days.com
--> Download FREE SEO marketing Ebook (valued $50)
Attract more visitors and sales with top 5 most powerful SEO marketing strategies. Converting visitors into buyers, not just traffic!
Reply With Quote
  #4  
Old 09-20-2012, 10:38 AM
  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

I am a little crunched for time so I am going to try and guide you through without testing what I am telling you, if it doesn't work, don't despair, just let me know. All of this is pseudo code.

First look at: /common_files/customer/main/order_message.tpl

Look for: {foreach from=$orders item=order}

Right under this is the included invoice template {include file="mail/html/order_invoice.tpl"...

We want to switch between templates so setup an if statement:
PHP Code:
{if $some_var eq 1}
  {include 
file="mail/html/special_invoice.tpl"...
{else}
  {include 
file="mail/html/order_invoice.tpl"...
{/if} 

Above that we need to test for the product, right after the foreach statement that loops through the orders, start another one and check for the product id. if it is found assign the $some_var we referenced in our if statement:
PHP Code:
{assign var="some_var" value=0}
{foreach 
from=$order.products item=product}
  {if 
$product.productid eq 23}
   {
assign var="some_var" value=1}
  {/if}
{/foreach} 

Make sense?
__________________
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

The following 2 users thank totaltec for this useful post:
chiactivate (09-20-2012), Pyro (09-26-2012)
  #5  
Old 09-20-2012, 11:11 AM
 
chiactivate chiactivate is offline
 

Senior Member
  
Join Date: Feb 2007
Location: Canada
Posts: 148
 

Default Re: Customize invoice based on product purchased

You are awesome! Many thanks!!!!

Will try it and let you know whether it works
__________________
www.ChiMassager.com
X-cart Version 4.44

www.SEOMarketing30days.com
--> Download FREE SEO marketing Ebook (valued $50)
Attract more visitors and sales with top 5 most powerful SEO marketing strategies. Converting visitors into buyers, not just traffic!
Reply With Quote
  #6  
Old 09-26-2012, 09:29 AM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Quote:
Originally Posted by chiactivate
You are awesome! Many thanks!!!!

Will try it and let you know whether it works



Did Mike's example end up working for you? I am looking to do something similar.


I will give it a try when I get home in a few hours, but I just wanted to see how things ended up for you.

Thanks!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote

The following user thanks Pyro for this useful post:
chiactivate (10-11-2012)
  #7  
Old 09-26-2012, 03:36 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Mike,

Thank you for the base that you provided. Could you please see where I am going wrong?

My scenario is that I want to display a certain message if a certain product is ordered.

As such, I have gone right to mail/html/order_invoice.tpl .


Here is the code that I am currently trying. The values in red are values that I have tried in with quotes and without quotes, but I get the same result either way.


Code:
{assign var="ordered8" value=0} {foreach from=$order.products item=product} {if $product.productid eq "8"} {assign var="ordered8" value=1} {/if} {/foreach} {if $ordered8 eq 1} extra thank you {else} no thank you for you {/if}





The output is always "no thank you for you", even if product 8 was ordered and is on the invoice.


Is there anything that you can see that I am missing?


Thank you very much for any guidance!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote

The following user thanks Pyro for this useful post:
chiactivate (10-11-2012)
  #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

The following 2 users thank totaltec for this useful post:
chiactivate (10-11-2012), Pyro (09-26-2012)
  #9  
Old 09-26-2012, 06:44 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Mike,


Thank you for the detailed reply. I know you are busy and the help is greatly appreciated. I have watched a few of your videos and I will definitely give the smarty one a try.


As for this code, this is what I have ended up with.


Code:
{assign var=ordered817 value=0} {foreach from=$products item=product} {if $product.productid eq 8 or $product.productid eq 1 or $product.productid eq 7} {assign var=ordered8 value=1} {/if} {/foreach} {if $ordered817 eq 1} extra thank you {else} {/if} {assign var=ordered234 value=0} {foreach from=$products item=product} {if $product.productid eq 2 or $product.productid eq 3 or $product.productid eq 4} {assign var=ordered8 value=1} {/if} {/foreach} {if $ordered234 eq 1} some other thank you {else} {/if}



This code appears to have the desired effect; however, is there a better way to condense the two? The only way I can see doing it is by using a few ifelse statements, but that causes its own issue. Doing it that way would mean that I would have to define all of the possible combinations and all of the outputs.


Thanks again!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote

The following user thanks Pyro for this useful post:
chiactivate (10-11-2012)
  #10  
Old 09-26-2012, 06:54 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, you are welcome. If you have a large volume of special messages then you should try to find a php solution, like assigning the message to each product in the db. Then you can just loop through the products and foreach output the products special message.

Let's just do it like this (untested psuedo code):
HTML Code:
{foreach from=$products item=product} {if $product.productid eq 8 or $product.productid eq 1 or $product.productid eq 7} {assign var=ordered8 value="You bought a boat!"} {/if} {if $product.productid eq 2 or $product.productid eq 3 or $product.productid eq 4} {assign var=ordered7 value="You bought some life jackets!"} {/if} {/foreach} {if $ordered8 ne '' and $ordered7 ne ''} You bought some life jackets and a boat! {elseif $ordered8 ne ''} {$ordered8} {elseif $ordered7 ne ''} {$ordered7} {else} Go get a boat, and some $*%# life jackets, loser! {/if}
Make sense?
__________________
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

The following 2 users thank totaltec for this useful post:
chiactivate (10-11-2012), Pyro (09-26-2012)
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:31 AM.

   

 
X-Cart forums © 2001-2020