PDA

View Full Version : MivaScript: querying g.product_code


owen
06-24-06, 03:30 PM
It was suggested in another thread that I use this code to check whether a product code contained a certain letter:

<mvt:if expr="'A' CIN g.product_code ">
// do something
</mvt:if>
But this doesn't seem to be working. It seems to return true whether the product code is "A2456" or "G2456." Have I got the code wrong?

sebenza
06-24-06, 05:36 PM
Try this:

<mvt:if expr="'A' CIN g.Product_Code">

// do something

</mvt:if>

owen
06-24-06, 06:23 PM
Changing the case doesn't affect the output at all. It still evaluates true for both cases.

wmgilligan
06-24-06, 09:01 PM
Have you tried testing for a lowercase? Does it fail?

I also read on the forums somewhere lately that there may be an issue with CIN and IN.

Also - not sure if it makes a difference, but I always leave a space between the double quote and the start of the code.

Bill

Pete McNamara
06-25-06, 12:02 AM
FWIW, I have been unable to get this expression to function:

<mvt:if expr="'FRESH' CIN l.settings:product:code"> <img src="graphics/approx.jpg">
<mvt:else>
&nbsp;
</mvt:if>

The spaces should make no difference in that expression and in any event, they don't. Nor does capitalizing Product and code.

I think there is a problem with CIN at least in respect of product codes.

wcw
06-25-06, 12:56 AM
FWIW, I have been unable to get this expression to function:

<mvt:if expr="'FRESH' CIN l.settings:product:code"> <img src="graphics/approx.jpg">
<mvt:else>
&nbsp;
</mvt:if>

The spaces should make no difference in that expression and in any event, they don't. Nor does capitalizing Product and code.

I think there is a problem with CIN at least in respect of product codes.
You indicated in your MM5 bug report you are trying to do that on the basket page. That variable is not available on that page. The following works fine on the basket page:


<mvt:if expr="'1AA' CIN l.settings:item:code">
<br>Software
</mvt:if>


Now for the shameless plug for an $18 module. If you really want to display images in the basket screen, you could use my inexpensive module Categories in Basket Screen which displays:
1) categories the product is in
2) thumb image of the product
3) combines the base and attribute prices to show the combined price

wcw
06-25-06, 01:03 AM
It was suggested in another thread that I use this code to check whether a product code contained a certain letter:

<mvt:if expr="'A' CIN g.product_code ">
// do something
</mvt:if>
But this doesn't seem to be working. It seems to return true whether the product code is "A2456" or "G2456." Have I got the code wrong?
Change it to read:


<mvt:if expr="'A' CIN Product_Code">
TEST OK
</mvt:if>


Note the case sensitivity of the variable you are checking, ie Product_Code. If your head is bloody from beating it against the wall, take a break; it is Saturday and you are not supposed to be working on Miva Merchant.

Pete McNamara
06-25-06, 01:07 AM
Jeez Bill, I thought I had tried item:code too but evidently not.

item:code works fine.

Thanks :)

wcw
06-25-06, 01:14 AM
Jeez Bill, I thought I had tried item:code too but evidently not.

item:code works fine.

Thanks :)
You are welcome.

You guys pay me the big bucks to get you on the right track, right. :-)

Pete McNamara
06-25-06, 01:20 AM
Bill,

That works on the basket page but I can't get either item:code or product:code to work in the OCST, OSEL, OPAY and INVC pages. :(

wcw
06-25-06, 01:32 AM
Bill,

That works on the basket page but I can't get either item:code or product:code to work in the OCST, OSEL, OPAY and INVC pages. :(
You must be putting it in the wrong place. Inside the foreach loop for the basket contents on the ocst page, the following works fine.

<mvt:if expr="'1AA' CIN l.settings:item:code">
<br>TEST OK
</mvt:if>

The item with 1AA in the product code shows the message. The item without the 1AA, does not.

owen
06-25-06, 02:45 AM
Could that be my problem? I'm trying it on the Category Display page, in Category Product List Layout:

<mvt:foreach iterator="product" array="products">

<mvt:if expr="'A' CIN g.Product_Code">
Yes!
<mvt:else>
No!
</mvt:if>

</mvt:foreach>

wcw
06-25-06, 02:54 AM
The only place Product_Code is always going to be valid is the prod page. On the category (ctgy) page, there is not a g.Product_Code variable generated for each product. It is part of the link to the product page, but the variable is not necessarily created. In that page you should be using something like

l.settings:product:code

owen
06-25-06, 03:03 AM
I don't understand... I can output the product code on the CTGY page with &mvt:product:code; ...Not that I can plug that one into the if statement without getting an error.

wcw
06-25-06, 03:06 AM
You were using g.product_code. That is not the same thing as product:code. In the case of the mvt:if you have to use the l.settings prefix.

Pete McNamara
06-25-06, 07:27 AM
You must be putting it in the wrong place. Inside the foreach loop for the basket contents on the ocst page, the following works fine.

<mvt:if expr="'1AA' CIN l.settings:item:code">
<br>TEST OK
</mvt:if>

The item with 1AA in the product code shows the message. The item without the 1AA, does not.

I don't believe I am putting it in the wrong place. This is my code in the basket contents section of the OCST and it does not work:

<mvt:foreach iterator="item" array="basket:items">
<tr>
<td align="left" valign="middle" width="200">&nbsp; &mvt:item:name;
<mvt:if expr="l.settings:item:upsold"> (Special Offer) </mvt:if> <span class="code"> &mvt:item:code;</span>
</td>
<td class=center" valign="middle" nowrap><div align="center"> &mvt:item:quantity; units of &mvt:item:weight; &mvt:store:wtunits;</div></td>
<td align="right" valign="middle" nowrap><div align="center"> &mvt:item:formatted_price; </div></td>
<td valign="middle" nowrap>&mvt:item:formatted_subtotal;
<mvt:if expr = "'FRESH' CIN l.settings:item:code"> <img src="graphics/approx.jpg">
<mvt:else>
&nbsp; </mvt:if></td>
</tr>

wcw
06-25-06, 01:01 PM
I don't believe I am putting it in the wrong place. This is my code in the basket contents section of the OCST and it does not work:

<mvt:foreach iterator="item" array="basket:items">
<tr>
<td align="left" valign="middle" width="200">&nbsp; &mvt:item:name;
<mvt:if expr="l.settings:item:upsold"> (Special Offer) </mvt:if> <span class="code"> &mvt:item:code;</span>
</td>
<td class=center" valign="middle" nowrap><div align="center"> &mvt:item:quantity; units of &mvt:item:weight; &mvt:store:wtunits;</div></td>
<td align="right" valign="middle" nowrap><div align="center"> &mvt:item:formatted_price; </div></td>
<td valign="middle" nowrap>&mvt:item:formatted_subtotal;
<mvt:if expr = "'FRESH' CIN l.settings:item:code"> <img src="graphics/approx.jpg">
<mvt:else>
&nbsp; </mvt:if></td>
</tr>

I tried it with your test. I created a product with the code of junefresh and put your code in my ocst screen. I changed the img src part to TEST OK text in case there was an image issue. I added 3 items to the basket and went to checkout. It worked perfectly. Two of the items were unchanged. One of them had the words "TEST OK" in the basket. I should add, I am using VM5.03 because of the speed bug. If you have 5.04, maybe there is a bug in the newer version.

Pete McNamara
06-25-06, 01:10 PM
Ok - that's excellent feedback. Thanks. I will experiment some more tomorrow.

It's a mystery why it's not working me. I have even reinstalled the store from scratch (to swap to a MySQL database) and have not been able to get it to work in either version (not that it should make any difference).

I'll try your idea of using text instead of the image.

Pete McNamara
06-25-06, 01:40 PM
Bill,

Although I said I was going to experiment tomorrow,I couldn't resist doing it immediately. I found a typo in one of the pages (FRSH instead of FRESH and also discovered that if you eliminate the product code column (and thus the product code from the results, it doesn't work - which is what I did on another of the pages.

It now works fine in all checkout pages. Many thanks for providing that feedback - it really helped. :)

wcw
06-25-06, 01:48 PM
I've found that persistance is the key to MM5. When I have something that is not working that I feel should be, I've found that it is usually some dumb thing I did. Only on rare occassions have I actually found a bug in MM5; although the VM 5.04 speed issue is driving me nuts.

owen
06-25-06, 05:11 PM
You were using g.product_code. That is not the same thing as product:code. In the case of the mvt:if you have to use the l.settings prefix.

Maybe my problem is beyond the scope of this forum? I keep hearing the same suggestions for what to try, but nothing's working.

Is it necessary for me to hire someone in order to get to the bottom of my problem?

wcw
06-25-06, 05:59 PM
I told you exactly what to use. What did you change the code to that is still not working?

owen
06-25-06, 06:53 PM
Sorry, I really am trying my best to follow your recommendations. Here's the entire contents of my Category Product List Layout page:

<mvt:foreach iterator="product" array="products">

<mvt:if expr="'A' CIN Product_Code">
TEST OK<br>
<mvt:else>
Product_Code = &mvt:product:code;<br>
</mvt:if>

</mvt:foreach>
The output looks like this:

Product_Code = G2058
Product_Code = G2058B
Product_Code = A2058
Product_Code = A2058A

wcw
06-25-06, 06:59 PM
Like I said, there is nothing saving the product code value to Product_Code on the ctgy (category) screen. That is ONLY on the prod screen. For the category screen you have to use the l.settings prefix. You already know that the value of product:code is good, so all you need is the prefix.

<mvt:if expr="'A' CIN l.settings:product:code">


When you put things like

Product_Code = &mvt:product:code;

in a template, that is not saving the product:code to a variable. It is merely displaying the value of product:code. If you want to be able to save variables to other variables, you need to use a module like my tool kit. But that is not needed for your simple display of text. Just use the correct syntax as I had told you earlier. For the ctgy screen, use l.settings for the prefix.

owen
07-31-06, 03:57 PM
A very belated thanks to wcw and everyone else who chimed in to help answer my question. It was exactly what I needed, thank you!