Any way to batch import account credit? I don't see it as an available import field in the Add/Update customer import settings.
Announcement
Collapse
No announcement yet.
Batch Import Account Credit
Collapse
X
-
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 )" />
-
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.- First make a custom customer field. We named ours 'credit'.
- Add/Update customers from CSV with the 'credit' column filled out. Make sure your credit field DOES NOT contain a currency symbol.
- Create a new page and add this script.
-
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>
- 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.
-
- Load the page that you created, after it's done go check to see if your customers now have account credit.
Comment
-
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
-
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
-
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
Comment