| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Conditional Test for Text String | ||||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() Hi,
I need to know how to test a variable for the first 10 letters of the variable string. For example, I have a variable that could have the following values. 1. Buy Now Get ... 2. Buy 3 Save ... 3. $1 OFF ... I need to test the first 10 characters for the Buy 3 Save $25.80 or it might say Buy 3 Save $16.80. In either case I need the {if} test to test for the Buy 3 Save presence and ignore the others. How would I do a partial text compare like that? Thanks, Randal
__________________
*********************** Visit Our Other Web Sites! ∙ Nutritional Herbs and Supplements <a href="http://www.theherbsplace.com"> The Herbs Place </a> ∙ Frugal Ideas and a Forum To Submit Your Questions <a href="http://www.thefrugallife.com"> The Frugal Life </a> ∙ Healthy and Natural Pet Products <a href="http://www.healthypetcorner.com"> Healthy Pet Corner </a> *********************** Joined 08/02/05 X-Cart Gold Version 4.3.2 Linux RedHat Enterprise |
|||||||
#2
|
|||||||||
|
|||||||||
![]() In PHP:
Code:
__________________
Richard Williams Rogue Wave Limited Initial Inventory Imports Daily Inventory Updates Daily Inventory Reports Drop Ship Support Order Export to Shipper/Supplier Shopping Feeds That Work Programming for X-Cart richard@roguewavelimited.com http://www.roguewavelimited.com |
|||||||||
#3
|
|||||||
|
|||||||
![]() In a Smarty template:
Code:
__________________
Manuka Bay Company X-Cart Version 4.0.19 [Linux] UGG Boots and other fine sheepskin products http://www.snowriver.com |
|||||||
#4
|
|||||||
|
|||||||
![]() Thanks for getting back to me. However, I am not getting it to work. Can you take a look at my work and see if something is wrong?
This is what is showing in the $sales array on the page I want the condition to work on name => Buy 3 - SAVE $11.25 - Glyco Essentials Here is my code on product.tpl {if $sales} {elseif $sales and $sales[sale].name|truncate:5 eq "Buy 3"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {else} {include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {/if} My logic: If $sales is present then don't show the Buy Now button at all unless the name is Buy 3. If no $sales is present then show the Buy Now button after all. Any help will be greatly appreciated. Thanks, Randal
__________________
*********************** Visit Our Other Web Sites! ∙ Nutritional Herbs and Supplements <a href="http://www.theherbsplace.com"> The Herbs Place </a> ∙ Frugal Ideas and a Forum To Submit Your Questions <a href="http://www.thefrugallife.com"> The Frugal Life </a> ∙ Healthy and Natural Pet Products <a href="http://www.healthypetcorner.com"> Healthy Pet Corner </a> *********************** Joined 08/02/05 X-Cart Gold Version 4.3.2 Linux RedHat Enterprise |
|||||||
#5
|
|||||||||
|
|||||||||
![]() That's almost it. Try this:
Code:
__________________
Richard Williams Rogue Wave Limited Initial Inventory Imports Daily Inventory Updates Daily Inventory Reports Drop Ship Support Order Export to Shipper/Supplier Shopping Feeds That Work Programming for X-Cart richard@roguewavelimited.com http://www.roguewavelimited.com |
|||||||||
#6
|
|||||||
|
|||||||
![]() Here is what I tried and it didn't work for some reason:
{if $sales and $sales[sale].name|truncate:5 eq "Buy 3"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {elseif $sales} {else} {{include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {/if} Everything works but the first condition. Using this code the buy now button doesn't display on anything that starts with Buy 3. Seems to me the string compare isn't working. However, I have looked on the smarty forum and haven't found anything like it yet. Please help me get this answer. Thanks, Randal
__________________
*********************** Visit Our Other Web Sites! ∙ Nutritional Herbs and Supplements <a href="http://www.theherbsplace.com"> The Herbs Place </a> ∙ Frugal Ideas and a Forum To Submit Your Questions <a href="http://www.thefrugallife.com"> The Frugal Life </a> ∙ Healthy and Natural Pet Products <a href="http://www.healthypetcorner.com"> Healthy Pet Corner </a> *********************** Joined 08/02/05 X-Cart Gold Version 4.3.2 Linux RedHat Enterprise |
|||||||
#7
|
|||||||
|
|||||||
![]() for the first condition remove the first $sales since its redundant...you check if an array exists and you call an array index
as for your main question, use Code:
if you use just truncate:5, what happens is that the string will get truncated to 5 characters INCLUDING the ellipses, ie: "Buy 3 blahblahblah" gets truncated to "Bu..." and fails the comparison to "Buy 3" |
|||||||
#8
|
|||||||
|
|||||||
![]() Thanks for the clarification on the ellipses. I changed the code but it still doesn't work.
Here is what I have: {if $sales[sale].name|truncate:5:"":true eq "Buy 3"} {include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {elseif $sales} {else} {include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"} {/if} I reread the material on smarty.net about truncate and now I see the ... but they sure didn't make a big emphasis of it. Glad you saw that. Thanks, Randal
__________________
*********************** Visit Our Other Web Sites! ∙ Nutritional Herbs and Supplements <a href="http://www.theherbsplace.com"> The Herbs Place </a> ∙ Frugal Ideas and a Forum To Submit Your Questions <a href="http://www.thefrugallife.com"> The Frugal Life </a> ∙ Healthy and Natural Pet Products <a href="http://www.healthypetcorner.com"> Healthy Pet Corner </a> *********************** Joined 08/02/05 X-Cart Gold Version 4.3.2 Linux RedHat Enterprise |
|||||||
#9
|
|||||||
|
|||||||
![]() before your code
put {$sales[sale].name} and see what gets outputted |
|||||||
#10
|
|||||||
|
|||||||
![]() I am not real strong on Smarty so here is what I did:
I put that variable in product.tpl which is where I have the code that I am testing - and it didn't show up. When I run webmaster mode it is there in this form: {$sales} Array (1) 0 => Array (9) sales_id => 224 sku => 14077-5 name => Buy 3 - SAVE $11.25 - Glyco Essentials productid => 604 price => 63.60 start => 1185660000 amount => 3 expires => 1186264800 active => Y this is showing on the page that has the Buy 3 in the name. When I put the code on the specials.tpl page which has the section and loop to read all the specials it outputted it fine. It shows only what you see above. I need to be on the product.tpl page because that is where the add to cart button is being displayed. Please tell me how to get this string compared properly. I appreciate your help and hope you can tell me what is wrong. Thanks, Randal
__________________
*********************** Visit Our Other Web Sites! ∙ Nutritional Herbs and Supplements <a href="http://www.theherbsplace.com"> The Herbs Place </a> ∙ Frugal Ideas and a Forum To Submit Your Questions <a href="http://www.thefrugallife.com"> The Frugal Life </a> ∙ Healthy and Natural Pet Products <a href="http://www.healthypetcorner.com"> Healthy Pet Corner </a> *********************** Joined 08/02/05 X-Cart Gold Version 4.3.2 Linux RedHat Enterprise |
|||||||
|
|||
X-Cart forums © 2001-2020
|