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
  #11  
Old 09-26-2012, 07:22 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Quote:
Originally Posted by totaltec
Make sense?


Hmm, I think I follow. Ne is for negative, so you are basically saying not to include that, but what does the ne '' do? If negative nothing?


Thanks!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #12  
Old 09-26-2012, 07:25 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

ne is for "not equals" (!=). I am saying if this not equals nothing, display it, else display that. There are a thousand ways to word these things, you can test for positive or negative and go from there. Finding the best way, now that is an art.
__________________
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:
Pyro (09-26-2012)
  #13  
Old 09-26-2012, 08:20 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Hmm, not equals makes more sense.


This thread threw me off. http://forum.x-cart.com/showthread.php?t=60942


The guy asked about negative and you responded ne.



Thanks again for all of the help. I think I understand this now (or at least 1000x more than I did before).
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #14  
Old 09-26-2012, 09:27 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Sorry Mike, one more question for you about the variables.


Does everything have to be defined?

I used {$order|@print_r} to print the variables and I see nothing related to count.


I guess what I am asking is can I count the number of each SKU and use that number in a basic math problem?


Here is an example of the logic that I am thinking:

HTML Code:
{foreach from=$products item=product} {if $product.productid eq 8} {assign var=count8 value=(count($product.productid eq 8))} {/if} {if $product.productid eq 2} {assign var=count7 value=(count($product.productid eq 7))} {/if} {/foreach} {if $count8 ne '' and $count7 ne ''} Text[{$count7}*17]+[{$count8}*27] {elseif $count7 ne ''} Text{$count7}*17 {elseif $count8 ne ''} Text{$count8}*27 {else} Go get a boat, and some $*%# life jackets, loser! {/if}


(Just incase I randomly became a genius at this in 4 posts, I checked to see if my attempt at pseudo code worked. Its safe to say it didn't for those of you that may try it in the future. )
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #15  
Old 09-27-2012, 04:54 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

To get the total number of rows in the products array, try {$products|@count}

To know what the current index of the array is use {$smarty.foreach.myproducts.index} -to use .index or .iteration you need to name your foreach loop.
Example:
Quote:
{foreach from=$products item=product name=myproducts}
{$smarty.foreach.myproducts.index}
{/foreach}
Be warned that some of this is on the fringe of needing to be done in PHP. Smarty is a template engine used for presentation of data. Using it to perform logical operations is against the principles behind smarty. (purist nonsense to some)

Are you perhaps trying to determine how many of a certain product they bought? Then you would use {$product.amount}
__________________
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
  #16  
Old 09-27-2012, 08:02 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 totaltec
Are you perhaps trying to determine how many of a certain product they bought? Then you would use {$product.amount}




Mike,


That is exactly what I am trying to do. I have 2 products that I am interested in counting on the invoice, multiplying each by a set number, and then adding the mathematical products together, so that my end result is one number.

I think you may even tear up on this one, but I managed to come up with what I think is the correct smarty math function (or at least it is pretty close). {math equation="(( y * 9 ) + ( z * 18 ))" y=$county z=$countz}




As such, I have edited my code to be this:


HTML Code:
{foreach from=$products item=product} {if $product.productid eq 1} {assign var=orderedy value={$product.amount}} {/if} {if $product.productid eq 7 or $product.productid eq 5 or $product.productid eq 6} {assign var=orderedz value={$product.amount}} {/if} {/foreach} {if $orderedy ne '' and $orderedz ne ''} text{math equation="(( y * 9 ) + ( z * 18 ))" y=$county z=$countz} {elseif $orderedy ne ''} text{math equation="( y * 9 )" y=$county} {elseif $orderedz ne ''} text{math equation="( z * 18 )" z=$countz} {else} Go get a boat, and some $*%# life jackets, loser! {/if}



I tested the code with an order that had 1 prodid=6 and the only output was
Code:
}
. Any idea where I went wrong? I think the issue is with how I am using $product.amount.







-------------------------------Edit-----------------------

I noticed that I was not defining the countz and county variables anywhere, so I revised my code to this, but I still get the same output.

Code:
{foreach from=$products item=product} {if $product.productid eq 1} {assign var=orderedy value={$product.amount}} {/if} {if $product.productid eq 7 or $product.productid eq 5 or $product.productid eq 6} {assign var=orderedz value={$product.amount}} {/if} {/foreach} {if $orderedy ne '' and $orderedz ne ''} text{math equation="(( y * 9 ) + ( z * 18 ))" y=$orderedy z=$orderedz} {elseif $orderedy ne ''} text{math equation="( y * 9 )" y=$orderedy} {elseif $orderedz ne ''} text{math equation="( z * 18 )" z=$orderedz} {else} Go get a boat, and some $*%# life jackets, loser! {/if}

Thanks!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #17  
Old 09-27-2012, 08:09 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

James I can't test the code right now. I am not at my normal IP address. I can tell you what looks suspicious to me:
{assign var=orderedy value={$product.amount}} --There is no need for those internal brackets. Since you are already inside the brackets with your assign, you don't use them again when accessing variables. Try fixing that and let me know.
__________________
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:
Pyro (09-27-2012)
  #18  
Old 09-27-2012, 08:29 AM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: Customize invoice based on product purchased

Mike,


Thanks! That definitely helped as it is now displaying a number at least!

On an invoice that has 5 of product#7 and 1 of product#6, the output is 18. (which is the output of the 1 product#6.)


It seems the issue is the or statement. It is not combining the count of each of the products in the or, but rather 1 of them.


It seems that I should switch which side of the equation the or is on.

This is my attempt, which only outputs "text" for an order with 5 product#7 and 1 product#6.




HTML Code:
{foreach from=$products item=product} {if $product.productid eq 1} {assign var=ordered1 value=$product.amount} {/if} {if $product.productid eq 5} {assign var=ordered5 value=$product.amount} {/if} {if $product.productid eq 6} {assign var=ordered6 value=$product.amount} {/if} {if $product.productid eq 7} {assign var=ordered7 value=$product.amount} {/if} {/foreach} {if $ordered1 ne '' or $ordered5 ne '' or $ordered6 ne '' or $ordered7 ne ''} text{math equation="(( w * 9 ) + ( z * 18 ) + ( y * 18 ) + ( z * 18 ))" w=$ordered1 x=$orderedz5 y=$ordered6 z=$ordered7} {else} Go get a boat, and some $*%# life jackets, loser! {/if}
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #19  
Old 09-27-2012, 09:46 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

Aha! I think I see it.

Smarty cannot use non integer variables in a math equation. Since some of your variables are not assigned like w=$ordered1 then it returns null. "null" doesn't add up and breaks the math equation.

You can handle this several ways by assigning a value of 0 to ordered1 etc, or by using |default:0 which is my preference.

Consider this code:
PHP Code:
{if $ordered1 ne '' or $ordered5 ne '' or $ordered6 ne '' or $ordered7 ne ''}
  
You bought {$ordered1|default:0boats, {$ordered5|default:0life jackets, {$ordered6|default:0anchors, and {$ordered7|default:0paddles!
   
You get {math equation="(( w * 9 ) + ( z * 18 ) + ( y * 18 ) + ( z * 18 ))" w=$ordered1|default:0 x=$ordered5|default:0 y=$ordered6|default:0 z=$ordered7|default:0points!
{else}
  
Go get a boat, and some $*%# life jackets, loser!
{/if} 

BTW, you also have a small typo: x=$orderedz5
__________________
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:
Pyro (09-27-2012)
  #20  
Old 09-27-2012, 11:54 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 totaltec
Aha! I think I see it.

Smarty cannot use non integer variables in a math equation. Since some of your variables are not assigned like w=$ordered1 then it returns null. "null" doesn't add up and breaks the math equation.

You can handle this several ways by assigning a value of 0 to ordered1 etc, or by using |default:0 which is my preference.



Brilliant! I was hoping it would just assume non intergers as 0, for purposes of math equations, but that obviously wasn't the case. Everything is working now. Thanks again.





Quote:
BTW, you also have a small typo: x=$orderedz5

THESE DAMN Z's!! I also noticed that it was outputting an unexpected number. Upon closer inspection:
Quote:
text{math equation="(( w * 9 ) + ( z * 18 ) + ( y * 18 ) + ( z * 18 ))" w=$ordered1 z=$orderedz5 y=$ordered6 z=$ordered7}
{else}

should have been:
Quote:
text{math equation="(( w * 9 ) + ( z * 18 ) + ( y * 18 ) + ( z * 18 ))" w=$ordered1 x=$orderedz5 y=$ordered6 z=$ordered7}
{else}


Hopefully that helps someone that comes along later.

P.S. for anyone that needs it, I added format="%.2f" to my code in order to display 2 decimal places (like you would need in the case of currency).

Code:
{math equation="(( w * 1.96 ) + ( x * 1.50 ) + ( y * 1.50 ) + ( z * 1.50 ))" w=$ordered1|default:0 x=$ordered5|default:0 y=$ordered6|default:0 z=$ordered7|default:0 format="%.2f"}
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote

The following user thanks Pyro for this useful post:
totaltec (09-27-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 01:01 AM.

   

 
X-Cart forums © 2001-2020