Announcement

Collapse
No announcement yet.

Batch Import Account Credit

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

    Batch Import Account Credit

    Any way to batch import account credit? I don't see it as an available import field in the Add/Update customer import settings.
    Tony Pavao
    Studio6t6
    Vancouver BC Canada
    [email protected]

    #2
    Not currently, but we have plans to add it to the customer import. You can do it via page template code. You would first import the credit into a custom custom field, loop though all customers, read in the value and use the code to update the account credit:

    Code:
    <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="Customer_Load_Login( 'customer_login', l.settings:customer )" />
     
    <mvt:assign name="l.entry:user_id"      value="''" />
    <mvt:assign name="l.entry:cust_id"       value="l.settings:customer:id" />
    <mvt:assign name="l.entry:order_id"    value="''" />
    <mvt:assign name="l.entry:txref"                            value="''" />
    <mvt:assign name="l.entry:descrip"       value="'Customer Credit'" />
    <mvt:assign name="l.entry:amount"                      value="25" />
     
    <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="CustomerCreditHistory_Insert( l.entry )" />
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Thanks Brennan! I'll give it a try.
      Tony Pavao
      Studio6t6
      Vancouver BC Canada
      [email protected]

      Comment


        #4
        After working with Brennan we were able to import customer credit. I kept finding this thread when looking for an answer so I will post the solution to this problem here.
        1. First make a custom customer field. We named ours 'credit'.
        2. Add/Update customers from CSV with the 'credit' column filled out. Make sure your credit field DOES NOT contain a currency symbol.
        3. Create a new page and add this script.
          1. Code:
            <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="CustomerList_Load_Offset(0, '', '', 100, l.nextoffset, l.settings:customers)" />
            		<mvt:foreach iterator="customer" array="customers">
            		 
            		                                <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="Customer_Load_Login( l.settings:customer:login, l.settings:customer )" />
            		 
            		                               
            		                                <mvt:assign name="g.credit_amount" value="''" />
            		                                <mvt:item name="customfields" param="Read_Customer_Login( l.settings:customer:login, 'credit', g.credit_amount )" />
            		 
            		                                <mvt:if expr="NOT ISNULL g.credit_amount AND g.credit_amount GT 0">
            		                               
            		                                                <mvt:assign name="l.entry:user_id"      value="''" />
            		                                                <mvt:assign name="l.entry:cust_id"       value="l.settings:customer:id" />
            		                                                <mvt:assign name="l.entry:order_id"    value="''" />
            		                                                <mvt:assign name="l.entry:txref"                            value="''" />
            		                                                <mvt:assign name="l.entry:descrip"       value="'Customer Credit'" />
            		                                                <mvt:assign name="l.entry:amount"                      value="g.credit_amount" />
            		                                               
            		 
            		                                                <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="CustomerCreditHistory_Insert( l.entry )" />
            		 
            		                                </mvt:if>
            		 
            		</mvt:foreach>
          2. The first line has an offset. This is telling it to only go through customers 0-100. You can adjust this as needed. We had 56k customer accounts to go through and without the offset there would be a server timeout.
        4. Load the page that you created, after it's done go check to see if your customers now have account credit.

        Comment


          #5
          UPDATE: Had to add the code in red so that it would remove credit from the customers account. Without the added code it just adds credit to whatever amount is already there.

          Code:
          <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="CustomerList_Load_Offset(15400, '', '', 15500, l.nextoffset, l.settings:customers)" />
          <mvt:foreach iterator="customer" array="customers">
           
                                          <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="Customer_Load_Login( l.settings:customer:login, l.settings:customer )" />
           
                                         
                                          <mvt:assign name="g.credit_amount" value="''" />
                                          <mvt:item name="customfields" param="Read_Customer_Login( l.settings:customer:login, 'credit', g.credit_amount )" />
          
          
                                          <mvt:if expr="NOT ISNULL g.credit_amount AND g.credit_amount GT 0">
                                         
                                                          <mvt:assign name="l.entry:user_id"      value="''" />
                                                          <mvt:assign name="l.entry:cust_id"       value="l.settings:customer:id" />
                                                          <mvt:assign name="l.entry:order_id"    value="''" />
                                                          <mvt:assign name="l.entry:txref"                            value="''" />
                                                          <mvt:assign name="l.entry:descrip"       value="'Customer Credit'" />
                                                          <mvt:assign name="l.entry:amount"                      value="g.credit_amount" />
                                                         
                                   <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="Customer_Adjust_Credit(l.settings:customer:id,  (-1 * l.settings:customer:credit))" />
                                  <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="CustomerCreditHistory_Delete_All_Customer(l.settings:customer:id)" />
                                                          <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="CustomerCreditHistory_Insert( l.entry )" />
           
                                          </mvt:if>
           
          </mvt:foreach>

          Comment


            #6
            Just rehashing this old post... Anybody ever try the second entry that removes the existing credit before adding the new credit? Doesn't seem to be working. When you load the page, nothing happens. The first entry that just adds credit to whatever was there, works perfectly.
            Tony Pavao
            Studio6t6
            Vancouver BC Canada
            [email protected]

            Comment


              #7
              Might want to eval the l.success of the Balance Removal function
              <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="Customer_Adjust_Credit(l.settings:customer: id, (-1 * l.settings:customer:credit))" />

              Also might try assigning the second parameter to a variable,

              <mvt:assign name="l.settings:customer:creditRemove" value="(-1 * l.settings:customer:credit)"/>

              then doing

              <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="Customer_Adjust_Credit(l.settings:customer: id, l.settings:creditRemove)" />

              (Sometimes expressions don't fair well in API function calls.)
              Bruce Golub
              Phosphor Media - "Your Success is our Business"

              Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
              phosphormedia.com

              Comment


                #8
                Thanks for you response Bruce. I'm starting to get lost a bit. Would you be able to modify the existing script with your suggestions? Much appreciated!
                Tony Pavao
                Studio6t6
                Vancouver BC Canada
                [email protected]

                Comment


                  #9
                  Code:
                  <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="CustomerList_Load_Offset(15400, '', '', 15500, l.nextoffset, l.settings:customers)" />
                  <mvt:foreach iterator="customer" array="customers">
                  
                     <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="Customer_Load_Login( l.settings:customer:login, l.settings:customer )" />
                  
                     <mvt:assign name="g.credit_amount" value="''" />
                     <mvt:item name="customfields" param="Read_Customer_Login( l.settings:customer:login, 'credit', g.credit_amount )" />
                  
                     <mvt:if expr="NOT ISNULL g.credit_amount AND g.credit_amount GT 0">
                  
                        <mvt:assign name="l.entry:user_id"     value="''" />
                        <mvt:assign name="l.entry:cust_id"     value="l.settings:customer:id" />
                        <mvt:assign name="l.entry:order_id"    value="''" />
                        <mvt:assign name="l.entry:txref"       value="''" />
                        <mvt:assign name="l.entry:descrip"     value="'Customer Credit'" />
                        <mvt:assign name="l.entry:amount"      value="g.credit_amount" />
                  
                        <mvt:assign name="l.settings:creditRemove" value="(-1 * l.settings:customer:credit)"/>
                  
                        <mvt:do file="g.Module_Feature_CUS_DB" name="l.adjustCredit" value="Customer_Adjust_Credit(l.settings:customer: id, l.settings:creditRemove)" />
                  
                        <mvt:comment> Test the API Call -- Remove if you see a 1</mvt:comment>
                        <mvt:eval expr="l.adjustCredit"/><br />
                        <mvt:comment> // Test the API Call -- Remove if you see a 1</mvt:comment>
                  
                        <mvt:do file="g.Module_Feature_CUS_DB" name="l.success" value="CustomerCreditHistory_Delete_All_Customer(l.settings:customer:id)" />
                  
                        <mvt:do name="g.success" file="g.Module_Feature_CUS_DB" value="CustomerCreditHistory_Insert( l.entry )" />
                  
                     </mvt:if>
                  
                  </mvt:foreach>
                  Bruce Golub
                  Phosphor Media - "Your Success is our Business"

                  Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                  phosphormedia.com

                  Comment


                    #10
                    Beautiful! Thanks Bruce!
                    Tony Pavao
                    Studio6t6
                    Vancouver BC Canada
                    [email protected]

                    Comment


                      #11
                      I tried moving over some credit balances from a live store to a dev store but the credit values are too large and don't match the custom field. I loaded the page each time I adjusted the numbers, in batches of 200. Any ideas how to fix so that the balance equals the custom field?

                      Comment

                      Working...
                      X