Announcement

Collapse
No announcement yet.

Customer Custom Fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • afiumano
    replied
    Thanks Kent Multer.

    So this is working to out put the value:
    <mvt:eval expr="l.customfield:value:value" />.

    The issue is it is outputting the value for every order. So should it be inside some sort of conditional since we only want it to show for orders made by customers who have a value in that custom field?

    Leave a comment:


  • Kent Multer
    replied
    I didn't take the time to proofread all the code, but here are a few general hints.

    * customfield (singular)and customfields (plural) are two different variables; don't confuse them.
    * Most local variables (l.something) can't be rendered by &mvt: entities. The &mvt: prefix can only be used with variables named l.settings:something.
    * You never use the l. prefix inside an &mvt: entity.

    I think you need to either:

    + Change l.customfield to l.settings:customfield, or
    + Use <mvt:eval expr="l.customfield:custkey:value:value" /> instead of an &mvt: entity to render the value.

    ... but I didn't test it.

    HTH --

    Leave a comment:


  • afiumano
    replied
    This is the code I have on the Template Based Batch Report:

    Code:
    <mvt:miva output="on" compresswhitespace="on" />
    <mvt:assign name="l.header" value="miva_output_header( 'Content-Type', 'text/csv' )" />
    <mvt:assign name="l.header" value="miva_output_header( 'Content-Disposition', 'attachment; filename=orders.csv' )" />
    
    REC_TYPE|ORDER_ID|PROCESSED|ORDER_DATE|ORDER_TIME| SHIP_FNAME|SHIP_LNAME|SHIP_EMAIL|SHIP_COMP|SHIP_PH ONE|SHIP_FAX|SHIP_ADDR|SHIP_CITY|SHIP_STATE|SHIP_Z IP|SHIP_CNTRY|BILL_FNAME|BILL_LNAME|BILL_EMAIL|BIL L_COMP|BILL_PHONE|BILL_FAX|BILL_ADDR|BILL_CITY|BIL L_STATE|BILL_ZIP|BILL_CNTRY|ORDER_TAX|ORDER_SHIP|O RDER_TOTL|SHIP_METHOD_DB|CUST_KEY
    <mvt:foreach iterator="order" array="admin_order:orders">
    
    <mvt:do file="g.Module_Library_DB" name="l.loaded_module" value="Module_Load_Code_Cached( 'customfields', l.customfields_module )" />
    <mvt:do file="g.Module_Root $ l.customfields_module:module" name="l.success" value="CustomerFieldValue_Load_CodeAndCustomer( 'custkey', l.settings:order:cust_id, l.customfield:field, l.customfield:value )" />
    <mvt:eval expr="decodeattribute(glosub(miva_array_serialize( l.customfield), ',', '<br>'))" />
    <mvt:eval expr="l.customfield:value:value" />
    HDR|&mvt:order:id;|N|&mvt:order:date;|&mvt:order:t ime;|&mvte:order:ship_fname;|&mvte:order:ship_lname;|&mvte:order:ship_email;|&mvte:order:ship_comp;| &mvte:order:ship_phone;|&mvte:order:ship_fax;|&mvte:order:ship_addr;|&mvte:order:ship_city;|&mvte:order:ship_state;|&mvte:order:ship_zip;|&mvte:order: ship_cntry;|&mvte:order:bill_fname;|&mvte:order:bill_lname;|&mvte:order:bill_email;|&mvte:order:bill _comp;|&mvte:order:bill_phone;|&mvte:order:bill_fa x;|&mvte:order:bill_addr;|&mvte:order:bill_city;|&mvte:order:bill_state;|&mvte:order:bill_zip;|&mvte :order:bill_cntry;|&mvt:order:total_tax;|&mvt:orde r:total_ship;|&mvt:order:total;|&mvt:order:ship_method;|&mvt:customfields:custkey;|&mvte:customfield s:custkey;|&mvte:customfields:value;|&mvte:custkey :value;|&mvt:customfield:value:value;|&mvt:customf ield:custkey:value:value;|&mvt:l.customfield:custk ey:value:value;|&mvt:l.customfield:value:value;
    <mvt:item name="tbr_order_contents" />
    </mvt:foreach>
    This line:
    Code:
    <mvt:eval expr="decodeattribute(glosub(miva_array_serialize( l.customfield), ',', '<br>'))" />
    Outputs the value I need which is the Customer custom field with code 'custkey':
    Code:
     
    :custkey:field:code=custkey<br>:custkey:field:fieldtype=textfield<br>:custkey:field:group_id=0<br>:c ustkey:field:id=54<br>:custkey:field:info=Wholesale<br>:custkey:field:name=Customer Key<br>:custkey:value:field_id=54<br>:custkey:value:value=AFTG123
    But I have tried many ways to out put the value as you can see and none of them are working:
    Code:
    &mvt:customfields:custkey;|&mvte:customfields:custkey;|&mvte:customfields:value;|&mvte:custkey:value;|&mvt:customfield:value:value;|&mvt:customf ield:custkey:value:value;|&mvt:l.customfield:custkey:value:value;|&mvt:l.customfield:value:value;
    Last edited by afiumano; 02-10-26, 12:46 PM.

    Leave a comment:


  • Kent Multer
    replied
    I agree with Bruce on this. Custom fields can be tricky to work with, because there are two different ways of accessing them, and there are some confusing variable names. An experienced developer can probably find and fix this quickly, but he might need to see all the code, or maybe log in to the store's admin page to take a closer look, check some settings, etc.

    Leave a comment:


  • Bruce - PhosphorMedia
    replied
    Originally posted by afiumano View Post
    lesliekirk Sorry to bring up an old thread, but I am trying to accomplish this as well. I am seeing the Value in the code that spit out but can't get the value to show up where needed in the Batch Report. Were you ever able to get this to work?
    If I'm understanding your post I think we would need to see most if not the entire script because it sounds like you just have it placed in the wrong section. IE inside the correct loop or something like that.

    Leave a comment:


  • lesliekirk
    replied
    Originally posted by afiumano View Post
    lesliekirk Sorry to bring up an old thread, but I am trying to accomplish this as well. I am seeing the Value in the code that spit out but can't get the value to show up where needed in the Batch Report. Were you ever able to get this to work?
    I wish there was/is some way to tag these posts to a project. I need to figure out which project I was working on to go back and look. Let me see if I can find it and if it was ever resolved.

    Leave a comment:


  • afiumano
    replied
    lesliekirk Sorry to bring up an old thread, but I am trying to accomplish this as well. I am seeing the Value in the code that spit out but can't get the value to show up where needed in the Batch Report. Were you ever able to get this to work?

    Leave a comment:


  • lesliekirk
    replied
    Originally posted by Nick View Post
    Sorry all, I got a little ahead of myself and forgot to add some code:

    Code:
    <mvt:do file="g.Module_Library_DB" name="l.loaded_module" value="Module_Load_Code_Cached( 'customfields', l.customfields_module )" />
    <mvt:if expr="l.loaded_module">
    <mvt:do file="g.Module_Root $ l.customfields_module:module" name="l.success" value="CustomerFieldValue_Load_CodeAndCustomer( '
    customer_customfield_code', l.settings:order:cust_id, l.customfield:field, l.customfield:value )" />
    <mvt:eval expr="decodeattribute(glosub(miva_array_serialize( l.customfield), ',', '<br>'))" />
    </mvt:if>
    All that being said the most optimized way of getting the customer custom field would be to assign the custom field item to the page then run the Read_Customer_ID function:

    Code:
    <mvt:item name="customfields" param="Read_Customer_ID( CUST_ID, 'custom_field_code', l.settings:customfields )" />
    More information can be found here: https://docs.miva.com/template-langu...-documentation
    The custom field item has been assigned to this page all along. It was one of the first things I did.

    Please keep in mind, that I'm an integrator who takes the bits and pieces and then puts them together to make it work. I have looked at the docs numerous times over.

    Obviously, this didn't work for me:

    Code:
    <mvt:item name="customfields" param="Read_Customer_ID( CUST_ID, 'test', l.settings:customfields )" />
    &mvte:customfields:test;
    but the code you posted did spit out this:

    Code:
    :field:code=test
    :field:fieldtype=textfield
    :field:group_id=0
    :field:id=105
    :field:info=Field for message
    :field:name=Test
    :value:field_id=105
    :value:value=This is just a test.
    The last line, the "value" is what I need.




    Leave a comment:


  • ids
    replied
    Not trying to redirect the discussion, but it looks like a solution is presented.

    There is a school of thought that you shouldn't need to assign an item to a page if the component item is valid. IOW, especially for a Miva module, Customfields, adding the Read_Customer_ID should be all that was needed for the function to run.

    So, are there other systematic concerns with Component ITEMs?

    Scott


    Leave a comment:


  • Nick
    replied
    Sorry all, I got a little ahead of myself and forgot to add some code:

    Code:
    <mvt:do file="g.Module_Library_DB" name="l.loaded_module" value="Module_Load_Code_Cached( 'customfields', l.customfields_module )" />
    <mvt:if expr="l.loaded_module">
        <mvt:do file="g.Module_Root $ l.customfields_module:module" name="l.success" value="CustomerFieldValue_Load_CodeAndCustomer( '
    customer_customfield_code', l.settings:order:cust_id, l.customfield:field, l.customfield:value )" />
        <mvt:eval expr="decodeattribute(glosub(miva_array_serialize( l.customfield), ',', '<br>'))" />
    </mvt:if>
    All that being said the most optimized way of getting the customer custom field would be to assign the custom field item to the page then run the Read_Customer_ID function:

    Code:
    <mvt:item name="customfields" param="Read_Customer_ID( CUST_ID, 'custom_field_code', l.settings:customfields )" />
    More information can be found here: https://docs.miva.com/template-langu...-documentation

    Leave a comment:


  • lesliekirk
    replied
    Originally posted by Kent Multer View Post
    Just guessing here, but: for the above code snippet, does the variable l.customfields_module:module have a value? It looks to me like either it needs to be initialized, or maybe it's supposed to be "l.settings:..." instead of just "l...."
    That's a good question - what would the "module" be?

    Leave a comment:


  • Kent Multer
    replied
    Just guessing here, but: for the above code snippet, does the variable l.customfields_module:module have a value? It looks to me like either it needs to be initialized, or maybe it's supposed to be "l.settings:..." instead of just "l...."

    Leave a comment:


  • lesliekirk
    replied
    Originally posted by Nick View Post

    No you can use a variable, what is the variable you are using?
    My Custom Customer Field code is "test"

    Code:
    <mvt:do file="l.customfields_module:module" name="l.success" value="CustomerFieldValue_Load_CodeAndCustomer( 'test', l.settings:order:cust_id, l.settings:customer_customfield_code:field, l.settings:customer_customfield_code:value )" />
    <mvt:if expr="l.settings:customer_customfield_code:value"> &mvt:customer_customfield_code:value; </mvt:if>

    Leave a comment:


  • Nick
    replied
    Originally posted by lesliekirk View Post
    Do I have to specify a single customer ID? If so, this isn't going to work the way I'd like it to.
    No you can use a variable, what is the variable you are using?

    Leave a comment:


  • lesliekirk
    replied
    Do I have to specify a single customer ID? If so, this isn't going to work the way I'd like it to.

    Leave a comment:

Working...
X