Miva - Dynamic Order Export
Latest Module Version: 2.0002 (as of 10/17/2016)
Dynamic Order Export is a module that keeps track of new and modified: orders, customers, categories, & products.
The knowledge of modified items is then able to be exported through order Template Based Batch Reports or used on other Miva page templates.
Throughout this document we'll refer to "Dynamic Order Export" as "DOE", and "orders, customers, categories, & products" as "entities".
It is very likely, that the installation process will be handled for you by a Miva merchant developer, but here are the steps:
dynamicorderexport.mvc
module file, upload it, and click the "+ Add" button.After the module has been installed, it's settings can be configured in the Miva Admin under: Menu > Utilities > Dynamic Order Export.
On that page it will: allow you to Add Modification Keys, list all of the store's existing Modification Keys, and allow you to perform the following actions: Mark Batch Report Orders, Mark Orders, Mark Products, Mark Categories, Mark Customers.
A modification key is a key that will be used to track which orders, products, categories, and customers have been modified. Each key can be assigned to track either one, or up to all four of those items. The Modification Key Param is kind of like a name/code that is used to put product, categories, customers, and orders into different "buckets" so to speak.
For example, if you need to export orders to a CRM software, and you also need to export orders to a Shipment Fulfillment software, then you could create two Keys to keep track of which orders have been sent to each location. Other examples could be for integrations with 3rd-Party Analytics/Services like Power Reviews, Listrak, or SearchSpring.
When you add a Modification Key, you will be asked which entities you would like to track. Be sure to track all of them that apply to a given system/topic.
The "Manually Reset Modified Items" option is present if you would like to keep entities on the "Modified" queue indefinitely. Entities will only be marked "Unmodified" when they are manually set to be "Unmodified". This setting is helpful for initial development testing & debugging. It can also be helpful where you would like the 3rd-party system to respond & verify that changes with items have been received.
An entity (product, category, order, or customer) is considered modified when the entity has been created. The entity is also considered modified when it is edited in the Miva admin from an edit page or from a Batch List page.
Additionally, customers can also be considered modified through actions that happen on the StoreFront. See Entity Specifics > Customers > Modified Events for a breakdown.
There is a "Set Modified" field visible in the Miva Admin and in data exports/imports that can be used to mark an entity as modified/unmodified. You can set that field to "Yes", "1", or "True" to mark an entity as Modified. You can set an entity to Unmodified be setting the Set Modified field to either "No", "0", or "False".
Once a store has been configured with Modification Keys it will keep track of all of the entities (products, categories, customers, and orders) as they are created or edited. Initially, all entities are considered un-modified so there will not be a queue of entities to start testing with.
You can use the Menu > Utilities > Dynamic Order Export page to "Mark" entities as "Modified" or "Unmodified". Orders can have certain Order # ranges be marked as modified/unmodified, but products, categories, and customers will just mark all items.
For initial testing & debugging, it can be helpful to set a handful of entities as "Modified" and enable the Modification Key's "Manually Reset Modified Items" setting. This will allow you to easily keep refreshing or recalling a URL without having to keep modifying entities.
The DOE module creates 5 new Page Items for a Store: doe_adminpage
, doe_modifiedproducts
, doe_modifiedcategories
, doe_modifiedcustomers
, doe_modifiedorders
The doe_adminpage
allows you to add Miva Admin session validation to a regular User Interface > Page.
The doe_modifiedproducts
, doe_modifiedcategories
, doe_modifiedcustomers
, and doe_modifiedorders
items allow you to load in the list of Modified entities for their corresponding item. If you provide the Modification Key Code into the <mvt:item>
's param
attribute, then it will load in all of the corresponding Modified items:
For Example:
<mvt:item name="doe_modifiedproducts" param="key_code">
<mvt:foreach iterator="product" array="doe_modifiedproducts">
&mvte:product:code;<br/>
</mvt:foreach>
</mvt:item>
The following steps can be used to illustrate how a page can be created to output the core-data for modified products, categories, customers, and orders.
By the end of these steps you will be able to have a page that outputs all of the core-data in JSON format. This would be helpful for a 3rd-party system that would like to poll for updates that happen in the store. Outputting the data as JSON isn't the only thing that you can do with the data. You could perform <mvt:call>
's, update store custom fields, send emails, etc. The JSON just helps illustrate all of the data that is available to you.
doe_modifiedproducts
doe_modifiedcategories
doe_modifiedcustomers
doe_modifiedorders
doe_adminpage
item is not necessary for this example so please do not assign it to the page unless you understand how it works.<mvt:item name="doe_modifiedproducts" param="sample_doe_output">
<mvt:foreach iterator="product" array="doe_modifiedproducts">
&mvt:product:code; | &mvt:product:name;<br>
</mvt:foreach>
</mvt:item>
http://www.yourstore.com/mm5/merchant.mvc?Screen=sample-doe-output
<mvt:assign name="l.null" value="miva_output_header( 'Content-type', 'application/json' )" />
<mvt:item name="doe_modifiedproducts" param="sample_doe_output">
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.settings:doe_modifiedproducts )" />
</mvt:item>
1. The previous code sample will load in all of the Modified sample_doe_output products. The DOE module makes that product information available on the `l.settings:doe_modifiedproducts` variable structure. Then we can use `<mvt:do>` to output all of the data to the page in the JSON format.
1. The `doe_modifiedproducts` item gives us more information than just product codes & names. A lot of other core product details are available (See the `doe_modifiedproducts` Data section below.)
<mvt:assign name="l.null" value="miva_output_header( 'Content-type', 'application/json' )" />
<mvt:item name="doe_modifiedproducts" param="sample_doe_output">
<mvt:assign name="l.settings:data:products" value="l.settings:doe_modifiedproducts" />
</mvt:item>
<mvt:item name="doe_modifiedcategories" param="sample_doe_output">
<mvt:assign name="l.settings:data:categories" value="l.settings:doe_modifiedcategories" />
</mvt:item>
<mvt:item name="doe_modifiedcustomers" param="sample_doe_output">
<mvt:assign name="l.settings:data:customers" value="l.settings:doe_modifiedcustomers" />
</mvt:item>
<mvt:item name="doe_modifiedorders" param="sample_doe_output">
<mvt:assign name="l.settings:data:orders" value="l.settings:doe_modifiedorders" />
</mvt:item>
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.settings:data )" />
1. Edit a couple different categories and customers to set them as Modified.
1. Orders can be marked by opening the Order's Order Processing detail page > Clicking the Dynamic Order Export Modification Keys link > and setting it to be Modified.
1. After marking several products, categories, customers, and orders as Modified and previewing the sample-doe-output page's JSON data you should have a great idea of all the data that is available by default with the DOE module.
The following events will mark a product as being Modified:
The following events will not mark a product as being Modified:
The following events will un-modify an already modified product:
doe_modifiedproducts
DataThe following events will mark a category as being Modified:
The following events will not mark a category as being Modified:
The following events will un-modify an already modified category:
doe_modifiedcategories
DataThe following events will mark a customer as being Modified:
The following events will not mark a customer as being Modified:
The following events will un-modify an already modified customer:
Additionally, the following store-front customer actions can have certain Modification Events too:
Page Code | Description | Action | Set Modified? |
---|---|---|---|
ACAD | Customer Create | ICST | Yes |
ACED | Customer Edit | UCST | Yes |
CPWD | Change Password | CPWD | Yes |
CPWD | Change Email Address | CEML | Yes |
OCST | Customer checks, "Update Customer Record With This Information" checkbox | ORDR | Yes |
- | Customer Address set as Default Address | CCSA | Yes |
- | Customer Address Added | ICSA | No |
- | Customer Address Edited | UCSA | No |
- | Customer Address Removed | DCSA | No |
LOGN | Customer Login | LOGN | No |
- | Customer Logout | LOGO | No |
RGFT | Redeem Git Certificate | RDGC | No |
doe_modifiedcustomers
DataThe following events will mark an order as being Modified:
The following events will not mark an order as being Modified:
The following events will un-modify an already modified order:
doe_modifiedorders
DataYou may have noticed that there is not data that describes the actual order items, charges, discounts, etc. To get that information, it can be easier to not use the Page Item method. Alternatively, you can use a Template Based Batch Report method. Keep reading to find out more about how Dyanmic Order Export can use Batch Reports
Dynamic Order Export can run/output Template Based Batch Reports by making a web-request to the json.mvc
module using specific parameters to control which orders are returned.
The following methods will return Template Based Batch reports by pinging a store's https://www.example.com/mm5/json.mvc file with valid Miva admin credentials.
We need to have a valid Miva admin login and/or Miva admin session in order for your to make web-requests to the json.mvc module and execute Dyanmic Order Export module functions.
There are two options for ensuring the requests are authenticated properly: the first method would be to always pass the Miva Admin's username & password. The Second method would be to pass the username & password the first time, then retrieve the Session_ID and make all subsequent requests with the Session_ID. The first method can often times be easier to program.
Authenticating or testing the authentication requests while you're already logged into the Miva admin in the same browser will return a null result. Try starting a private-browsing window or a fresh-browser session.
Also, it is important to note that authenticated requests to the json.mvc will utilize a store's Miva admin Seat License. This can bring about scenarios where requests are not able to be performed because too many seats are being used. Applying for a Reserved Seat license can help resolve this.
Additionally, using the TemporarySession=1
parameter will help ensure that your session is not kept open until the Store's timeout period has occurred. It's best to always pass the TemporarySession=1
parameter for each web-request.
Here is a sample web-request that illustrates the basics parameters that are needed to successfully access Miva admin functionality through the json.mvc module:
{{JSON_URL}}?Session_Type=admin&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&TemporarySession=1
https://www.example.com/mm5/json.mvc?Session_Type=admin&TemporarySession=1&Store_Code=ABC-123&UserName=admin&Password=open_sesame!
Template Based Batch reports are typically seen by going into the Miva Admin > Menu > Order Processing > Selecting a range of orders > Clicking the Batch Actions button > Selecting the Batch Report option > Selecting the Batch Report you want > and then clicking the Run Report button.
Rather than doing that process manually, we can use Dynamic Order Export to get/execute Batch Report's through web-requests.
All orders start out as "Unprocessed" and once DOE has output a Batch Report for a specific order, it considers it "Processed". The date, time, IP, and output file can all be listed in the Miva admin's Order Processing detail page. One order can be considered Processed/Unprocessed for each Template Based Batch Report that exists in the store.
Here are some sample requests that illustrate what kinds of Batch Report operations you can do:
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}&Order_IDs=111
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}&Order_IDs=111,222,333
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}&First_Order_ID=111
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}&Last_Order_ID=999
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code={{Report_Code}}&First_Order_ID=888&Last_Order_ID=999
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&Report_Module_Code=templatebatchreports&Module_Function=DOE_Mark_Orders&Mark_Type=date_after&Report_Code={{Report_Code}}&After_Month=8&After_Day=30&After_Year=2015&After_Hour=17&After_Minute=26&After_Second=4&Processed=1
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&Report_Module_Code=templatebatchreports&Module_Function=DOE_Mark_Orders&Mark_Type=date_before&Report_Code={{Report_Code}}&Before_Month=8&Before_Day=30&Before_Year=2015&Before_Hour=17&Before_Minute=26&Before_Second=4&Processed=0
The previous examples all used the Dynamic Order Export's Processed/Unprocessed methodology for keeping track of whether an order has been handled yet. DOE can also output order Batch Reports based on their Modification Key too.
The main differentiation is that the Module_Function parameter is changed from Export_OrderBatchReport
to Export_OrderBatchReport_ModificationKey
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport_ModificationKey&Modification_Key={{Modification_Key}}&Report_Code={{Report_Code}}
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=ModificationKey_Reset&Modification_Key={{Modification_Key}}&Modification_Type=orders&Order_IDs=1001,1002,1009
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=ModificationKey_Reset&Modification_Key={{Modification_Key}}&Modification_Type=orders&First_Order_ID=1000&Last_Order_ID=1010
{{JSON_URL}}?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=ModificationKey_Reset&Modification_Key={{Modification_Key}}&Modification_Type=products,categories,customers
<mvt:assign name="l.header" value="miva_output_header( 'Content-type', 'application/json' )" />
<mvt:if expr="g.Download">
<mvt:assign name="l.header" value="miva_output_header( 'Content-Disposition', 'attachment; filename=orders.json' )" />
</mvt:if>
<mvt:do file="g.Module_JSON" name="l.null" value="JSON_Output( l.settings:admin_order )" />
1. Expand the "Order Contents" section
1. Configure & select any relevant Custom Fields, Images, Additional Price Displays, and Coupons
1. Click Update
1. Go to the page's Items tab
1. Remove the `inline_css` item
https://www.example.com/mm5/json.mvc?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code=JSON&Order_IDs=123456
1. You should see a JSON output for all of the order details for that specific order.
Order_IDs
parameter, like this:https://www.example.com/mm5/json.mvc?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport&Report_Code=JSON
1. You probably wont have any Unprocessed orders, since we Marked them all as Processed in a previous step. The output from the last request will probably look like this:
{
"orders": ""
}
1. Wait for an order to be placed, or:
1. Go in to the Miva admin > Order Process > Double-click and order > Click the "Dynamic Order Export Reports" link
1. Check the box in the Mark Unprocessed column for the JSON report.
1. Click the Save Button
1. Refresh/recall the last DOE json.mvc url and now it should output all of the order details for the order you marked as Unprocessed.
The following section will give a more detailed explanation of each of the parameters that can be present in a DOE request.
Description: This field is required and will always need to be "admin".
Sample: Session_Type=admin
Description: This field is optional but highly recommended. Miva has a limited number of Admin sessions that are allowed to be open according to the Store's Seats. This tells Miva not to create a lasting session that would hold one of the store's seats.
Sample: TemporarySession=1
Description: This field is optional for most sites, but it is good practice to keep it. It is required for mall sites (sites with multiple stores running on one Miva installation).
Sample: Store_Code=TS
Description: This field is required. This needs to be a valid Miva admin username. It is recommended to use a Reserved Seat in a production environment, but a regular user can be used for development.
Sample: UserName=admin
Description: This field is required. This needs to be the matching password for the Miva admin user.
Sample: Password=P@ssw0rd
Description: This is an optional parameter that is used if you need to export encrypted payment information. The store's Order Encryption Key (or multiple encryption keys) can be passed if you need the credit-card/payment details.
Sample: Passphrase[1]=opensesame
or Passphrase[1]=opensesame&Passphrase[2]=abra-ka-dabra
Description: This field is required and will always be "Module". This tells the json.mvc
module which type of process to run.
Sample: Function=Module
Description: This field is required and will always be "dynamicorderexport". This tells the json.mvc
module which external module it will be invoking a function on.
Sample: Module_Code=dynamicorderexport
Description: This field is required and will always be: "templatebatchreports". This tells the dynamicorderexport
module which module will report module it will be using.
Sample: ReportModule=dynamicorderexport
Description: This field is required and will change depending on the Template Based Batch Report that you want to run. This is the Template Based Batch Report's Page Code without the "ORDER_". For example, all stores come with an "ORDER_INVOICE" page/batch-report by default. The Report_Code
would just be "INVOICE".
Sample: Report_Code=INVOICE
or Report_Code=JSON
Description: This field is required and will be one of two values: "Export_OrderBatchReport" or "Export_OrderBatchReport_ModificationKey". This tells the json.mvc
module which external module it will be invocing a function on.
Sample: Module_Function=Export_OrderBatchReport
or Module_Function=Export_OrderBatchReport_ModificationKey
Description: This field is optional, but required when using, "Module_Function=Export_OrderBatchReport_ModificationKey". The Modification_Key
allows you to group and track orders so that they can be output for their proper service/endpoint.
Sample: Modification_Key=sample_doe_output
Description: This is an optional parameter that would be used to export a specific range of orders. If specified, it will export all orders greater-than-or-equal to that order id until it gets to the most recent order, or it gets to the Last_Order_ID
(if it was passed).
Sample: First_Order_ID=12345
Description: This is an optional parameter that would be used to export a specific range of orders. If specified, it will export all orders less-than-or-equal to that order id until it get's to the first order in the store, or it gets to the First_Order_ID
(if it was passed).
Sample: Last_Order_ID=12345
Description: This is an optional parameter that would be used to export one or more specific orders. It accepts a comma separated listed of order ids. If specified, it will export each order that is listed.
Sample: Order_IDs=12345
or Order_IDs=111,222,333
First_Order_ID
AND Last_Order_ID
, then it will export all orders within that range.First_Order_ID
, then it will export all orders after that idLast_Order_ID
, then it will export all orders before that idOrder_IDs
, then it will export those specific order(s)The following methods are available through the Dynamic Order Export module, but it is often more ideal an convenience to use one of the web-request methods described above.
You can export a batch report through provisioning. Here is the XML provisioning that is required to execute a Batch Report:
<Export_OrderBatchReport>
<Module>templatebatchreports</Module>
<Report>JSON</Report>
<OutputFile suffix="timestamp">sample_doe_output.txt</OutputFile>
<FirstOrderID>1000</FirstOrderID>
<LastOrderID>1100</LastOrderID>
</Export_OrderBatchReport>
You can export content of any page through provisioning.
You can even pass in variables through the parameters provisioning tag. This allows those variables and their values to be set prior to the page being rendered. The assignments are processed after the page has been loaded so that settings may be injected into the page by specifying a variable name such as "l.page:settings:xxx".
Here is an example of how you would load a page and inject settings
<Module code="dynamicorderexport" feature="util">
<Export_Page>
<OutputFile suffix="none">sample_doe_output.txt</OutputFile>
<Code>test</Code>
<Parameters>
<Parameter name="l.page:settings:test">Value</Parameter>
<Parameter name="g.Globals_Work">Too</Parameter>
</Parameters>
</Export_Page>
</Module>
You can export content of any page through json.mvc. You can also pass in variables through the parameters variable in the URL. This allows those variables and their values to be set prior to the page being rendered. The assignments are processed after the page has been loaded so that settings may be injected into the page by specifying a variable name such as "l.page:settings:xxx".
Here is an example of how you would load a page and inject settings
https://www.example.com/mm5/json.mvc?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&Module_Function=Export_Page&Page_Code=sample_doe_output&Parameters=l.page:settings:test~Value&Globals_Work=Too
doe_acme_customers
page's Items tabdoe_modifiedcustomers
item.<h1>&mvt:page:name;</h1>
<hr>
<mvt:item name="doe_modifiedcustomers" param="AcmeCRM">
<mvt:foreach iterator="customer" array="doe_modifiedcustomers">
&mvte:customer:login;<br/>
</mvt:foreach>
</mvt:item>
<h1>&mvt:page:name;</h1>
<hr>
<mvt:item name="doe_modifiedcustomers" param="AcmeCRM">
<mvt:assign name="g.Customers" value="miva_array_serialize(l.settings:doe_modifiedcustomers)" />
<mvt:call action="'https://www.example.com/sample.php'" method="'POST'" fields="'Customers">
<mvt:eval expr="s.callvalue" />
</mvt:call>
<mvt:if expr="g.MvCALL_Error">
<!-- @@ &mvt:global:MvCALL_Error; -->
</mvt:if>
</mvt:item>
var_dump($_POST)
so that we can test how we're communicating with a sample integration. Here's my "sample.php" file:<?php
echo "Hello from Sample API\n\n";
var_dump($_POST);
?>
<mvt:assign name="l.null" value="miva_output_header( 'Content-type', 'application/json' )" />
<mvt:assign name="l.settings:output:order_count" value="miva_array_elements( l.settings:admin_order:orders )" />
<mvt:assign name="l.settings:output:data" value="l.settings:admin_order:orders" />
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.settings:output )" />
https://www.example.com/mm5/json.mvc?Session_Type=admin&TemporarySession=1&Store_Code={{Store_Code}}&UserName={{Username}}&Password={{Password}}&Function=Module&Module_Code=dynamicorderexport&ReportModule=templatebatchreports&Module_Function=Export_OrderBatchReport_ModificationKey&Modification_Key=AcmeERP&Report_Code=AcmeERP
{
"data": "",
"order_count": 0
}
json.mvc
URL above, you should see at more complex JSON data-structure for that order.json.mvc
URL we should see our sample integration display info for our test order(s) one last time. We can refresh the page, and it should not output any orders; the modified order queue is now empty.json.mvc
URL at a reasonable interval that works for our site & integration needs (Once a month/week/day/hour/etc.)