Announcement

Collapse
No announcement yet.

Batch Import Account Credit

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

  • afiumano
    replied
    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?

    Leave a comment:


  • tpav
    replied
    Beautiful! Thanks Bruce!

    Leave a comment:


  • Bruce - PhosphorMedia
    replied
    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>

    Leave a comment:


  • tpav
    replied
    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!

    Leave a comment:


  • Bruce - PhosphorMedia
    replied
    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.)

    Leave a comment:


  • tpav
    replied
    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.

    Leave a comment:


  • Lokesh
    replied
    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>

    Leave a comment:


  • Lokesh
    replied
    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.

    Leave a comment:


  • tpav
    replied
    Thanks Brennan! I'll give it a try.

    Leave a comment:


  • Brennan
    replied
    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 )" />

    Leave a comment:


  • tpav
    started a topic Batch Import Account Credit

    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.
Working...
X