Miva - JSON Session Data Page
<mvt:assign name="l.settings:output:customer" value="l.settings:customer" />
<mvt:assign name="l.settings:output:basket" value="l.settings:basket" />
<mvt:assign name="l.settings:output:sessions:session_id" value="g.Session_ID" />
<mvt:assign name="l.settings:output:sessions:customer_session_id" value="g.Customer_Session_ID" />
<mvt:assign name="l.settings:output:sessions:checkout_session_id" value="g.Checkout_Session_ID" />
<mvt:assign name="l.null" value="miva_output_header( 'Content-type', 'application/json' )" />
<mvt:do file="g.Module_JSON" name="l.null" value="JSON_Output( l.settings:output )" />
The example miva-json-session-data-page.xml page can be added to a store to illustrate how a 3rd-Party entity can retrieve helpful Miva store-front session information.
Now you can access that page on your store and you'll have a programmatically digestiable JSON object that describes the core essential data for store-front session. For example:
If you created the json-session-data
page, then you should be able to access it at your store's equivalent of: https://www.example.com/mm5/merchant.mvc?Screen=json-session-data
That should output something like this:
{
"basket": {
"advanced": 0,
"applycoupons": 0,
"b_height": 75,
"b_width": 75,
"button_wish": 1,
"constrain": "B",
"discounts": 1,
"empty": 1,
"groups": 1,
"handling": 0,
"items": "",
"lineitemcoupons": 0,
"lineitemdiscounts": 1,
"lineitemprice": "base",
"redeemgiftcerts": 0,
"salestax": 0,
"shipping": 0,
"splitpayments": 0,
"template_filename": "json-session-data-basket.mvc",
"template_id": 504,
"total": "0.00"
},
"customer": {
"bill_addr": "",
"bill_addr1": "",
"bill_addr2": "",
"bill_city": "",
"bill_cntry": "",
"bill_comp": "",
"bill_email": "",
"bill_fax": "",
"bill_fname": "",
"bill_id": "",
"bill_lname": "",
"bill_phone": "",
"bill_state": "",
"bill_zip": "",
"credit": "",
"formatted_credit": "$0.00",
"id": "",
"login": "",
"password": "",
"pgrpcount": "",
"prefix": "",
"pw_email": "",
"ship_addr": "",
"ship_addr1": "",
"ship_addr2": "",
"ship_city": "",
"ship_cntry": "",
"ship_comp": "",
"ship_email": "",
"ship_fax": "",
"ship_fname": "",
"ship_id": "",
"ship_lname": "",
"ship_phone": "",
"ship_res": "",
"ship_state": "",
"ship_zip": "",
"template_filename": "json-session-data-customer.mvc",
"template_id": 505
},
"sessions": {
"checkout_session_id": "",
"customer_session_id": "",
"session_id": "abc123abc123abc123abc123abc123ab"
}
}
It doesn't look like much now, but you now have a session_id to perform additional store-front actions (ex: login, logout, add products to basket, etc.)
Just besure to grab the sessions:session_id
on the first request, and then pass it as a query string parameter on all subsequent requests.
https://www.example.com/mm5/merchant.mvc?Screen=json-session-data&Session_ID=abc123abc123abc123abc123abc123ab&Action=LOGN&Customer_Login=someone@example.com&Customer_Password=opensesame!
https://www.example.com/mm5/merchant.mvc?Screen=json-session-data&Session_ID=abc123abc123abc123abc123abc123ab&Action=ADPR&Product_Code=test-product&Product_Attributes[1]:code=size&Product_Attributes[1]:value=small&Quantity=1
https://www.example.com/mm5/merchant.mvc?Screen=json-session-data&Session_ID=abc123abc123abc123abc123abc123ab&Action=LOGO
Basically any web requests & form-data that happen for customers can be done with server-sided requests (MvCALLs, mvt:calls, cURLs, etc.) so long as a valid and active Session_ID is passed for the subsequent calls.
Eventually after performing the above calls, your json-session-data
page could end up with a bunch of data like this:
{
"basket": {
"advanced": 0,
"applycoupons": 0,
"b_height": 75,
"b_width": 75,
"button_wish": 1,
"constrain": "B",
"coupons": "",
"discounts": 1,
"fields_custom": "",
"formatted_total": "$300.00",
"groups": [{
"base_price": 101,
"basket_id": 5396,
"code": "miva-test-variant",
"discount_count": 1,
"discounts": [{
"basket_id": 5396,
"descrip": "Volume Pricing",
"discount": 3,
"display": 1,
"formatted_discount": "$3.00",
"line_id": 120342,
"pgrp_id": 13,
"priority": 0
}],
"formatted_base_price": "$101.00",
"formatted_price": "$100.00",
"formatted_retail": "$101.00",
"formatted_subtotal": "$300.00",
"formatted_subtotal_base_price": "$303.00",
"formatted_subtotal_comprehensive": "$300.00",
"formatted_subtotal_retail": "$303.00",
"group_id": 120342,
"line_id": 120342,
"link": "http:\/\/johndoe.mivamerchantdev.com\/store\/miva-test-variant.html",
"name": "Miva Test: Variant",
"option_count": 1,
"options": [{
"attmpat_id": 0,
"attr_code": "size",
"attr_id": 5,
"attr_prompt": "Size",
"base_price": 0,
"basket_id": 5396,
"data": "",
"data_long": "",
"discount_count": 0,
"discounts": "",
"formatted_base_price": "$0.00",
"formatted_price": "$0.00",
"formatted_retail": "$0.00",
"formatted_subtotal": "$0.00",
"formatted_subtotal_base_price": "$0.00",
"formatted_subtotal_retail": "$0.00",
"line_id": 120342,
"opt_code": "s",
"opt_prompt": "Small",
"option_id": 11,
"price": 0,
"retail": 0,
"subtotal": 0,
"subtotal_base_price": 0,
"subtotal_retail": 0,
"weight": 0
}],
"part_count": 1,
"parts": [{
"active": 0,
"agrpcount": 0,
"cancat_id": 0,
"catcount": 0,
"code": "miva-test-variant_s",
"cost": 0,
"descrip": "",
"disp_order": 162,
"id": 162,
"image": "",
"inv_active": 1,
"inv_available": 990,
"inv_instock": 985,
"inv_level": "in",
"inv_long": "985 available for immediate delivery",
"inv_low_level": 5,
"inv_low_track": 1,
"inv_out_level": 0,
"inv_out_track": 0,
"inv_short": "In Stock",
"name": "Miva Test: Variant size:s",
"page_id": 0,
"page_title": "",
"pgrpcount": 0,
"price": 101,
"quantity": 1,
"sku": "",
"taxable": 0,
"thumbnail": "",
"total_quantity": 3,
"weight": 1
}],
"price": 100,
"product": {
"active": 1,
"agrpcount": 0,
"cancat_id": 0,
"catcount": 1,
"code": "miva-test-variant",
"cost": 50,
"descrip": "Hello World\u0021",
"disp_order": 160,
"id": 160,
"image": "",
"inv_active": 0,
"name": "Miva Test: Variant",
"page_id": 0,
"page_title": "",
"pgrpcount": 1,
"price": 100,
"productsubscriptionsettings": {
"can_cancel": 1,
"can_date": 1,
"can_qty": 1,
"can_term": 1,
"enabled": 0,
"mandatory": 0,
"product_id": 160
},
"sku": "",
"taxable": 1,
"thumbnail": "",
"weight": 1
},
"product_id": 160,
"quantity": 3,
"retail": 101,
"subterm_id": 0,
"subtotal": 300,
"subtotal_base_price": 303,
"subtotal_comprehensive": "300.00",
"subtotal_retail": 303,
"taxable": 1,
"upsold": 0,
"variant_id": 21,
"weight": 1,
"wish_id": 0
}],
"handling": 0,
"imagetypes": "",
"items": [{
"base_price": 101,
"basket_id": 5396,
"code": "miva-test-variant",
"discount_count": 1,
"discounts": [{
"basket_id": 5396,
"descrip": "Volume Pricing",
"discount": 1,
"display": 1,
"formatted_discount": "$1.00",
"line_id": 120342,
"pgrp_id": 13,
"priority": 0
}],
"formatted_base_price": "$101.00",
"formatted_price": "$100.00",
"formatted_retail": "$101.00",
"formatted_subtotal": "$300.00",
"formatted_subtotal_base_price": "$303.00",
"formatted_subtotal_comprehensive": "$300.00",
"formatted_subtotal_retail": "$303.00",
"group_id": 120342,
"line_id": 120342,
"link": "http:\/\/johndoe.mivamerchantdev.com\/store\/miva-test-variant.html",
"name": "Miva Test: Variant",
"option_count": 1,
"options": [{
"attmpat_id": 0,
"attr_code": "size",
"attr_id": 5,
"attr_prompt": "Size",
"base_price": 0,
"basket_id": 5396,
"data": "",
"data_long": "",
"discount_count": 0,
"discounts": "",
"formatted_base_price": "$0.00",
"formatted_price": "$0.00",
"formatted_retail": "$0.00",
"formatted_subtotal": "$0.00",
"formatted_subtotal_base_price": "$0.00",
"formatted_subtotal_retail": "$0.00",
"line_id": 120342,
"opt_code": "s",
"opt_prompt": "Small",
"option_id": 11,
"price": 0,
"retail": 0,
"subtotal": 0,
"subtotal_base_price": 0,
"subtotal_retail": 0,
"weight": 0
}],
"part_count": 1,
"parts": [{
"active": 0,
"agrpcount": 0,
"cancat_id": 0,
"catcount": 0,
"code": "miva-test-variant_s",
"cost": 0,
"descrip": "",
"disp_order": 162,
"id": 162,
"image": "",
"inv_active": 1,
"inv_available": 990,
"inv_instock": 985,
"inv_level": "in",
"inv_long": "985 available for immediate delivery",
"inv_low_level": 5,
"inv_low_track": 1,
"inv_out_level": 0,
"inv_out_track": 0,
"inv_short": "In Stock",
"name": "Miva Test: Variant size:s",
"page_id": 0,
"page_title": "",
"pgrpcount": 0,
"price": 101,
"quantity": 1,
"sku": "",
"taxable": 0,
"thumbnail": "",
"total_quantity": 3,
"weight": 1
}],
"price": 100,
"product": {
"active": 1,
"agrpcount": 0,
"cancat_id": 0,
"catcount": 1,
"code": "miva-test-variant",
"cost": 50,
"descrip": "Hello World\u0021",
"disp_order": 160,
"id": 160,
"image": "",
"inv_active": 0,
"name": "Miva Test: Variant",
"page_id": 0,
"page_title": "",
"pgrpcount": 1,
"price": 100,
"productsubscriptionsettings": {
"can_cancel": 1,
"can_date": 1,
"can_qty": 1,
"can_term": 1,
"enabled": 0,
"mandatory": 0,
"product_id": 160
},
"sku": "",
"taxable": 1,
"thumbnail": "",
"weight": 1
},
"product_id": 160,
"quantity": 3,
"retail": 101,
"subterm_id": 0,
"subtotal": 300,
"subtotal_base_price": 303,
"subtotal_comprehensive": "300.00",
"subtotal_retail": 303,
"taxable": 1,
"upsold": 0,
"variant_id": 21,
"weight": 1,
"wish_id": 0
}],
"lineitemcoupons": 0,
"lineitemdiscounts": 1,
"lineitemprice": "base",
"redeemgiftcerts": 0,
"salestax": 0,
"shipping": 0,
"splitpayments": 0,
"template_filename": "json-session-data-basket.mvc",
"template_id": 504,
"total": "300.00",
"total_weight": "3.00"
},
"customer": {
"address_count": 2,
"addresses": [{
"addr": "16745 W Bernardo Dr.",
"addr1": "16745 W Bernardo Dr.",
"addr2": "",
"city": "San Diego",
"cntry": "TC",
"comp": "Miva",
"cust_id": 1,
"descrip": "16745 W Bernardo Dr.",
"email": "johndoe@miva.com",
"fax": "999-555-1234",
"fname": "Test\u0021",
"id": 1,
"lname": "Order",
"phone": "999-555-1234",
"resdntl": 0,
"state": "CA",
"zip": 92127
}, {
"addr": "123 Main St.",
"addr1": "123 Main St.",
"addr2": "",
"city": "San Diego",
"cntry": "US",
"comp": "",
"cust_id": 1,
"descrip": "Foobar 2",
"email": "something@email.com",
"fax": 2712096,
"fname": "John",
"id": 27,
"lname": "Doe",
"phone": 7605551234,
"resdntl": 1,
"state": "CA",
"zip": 92127
}],
"bill_addr": "16745 W Bernardo Dr.",
"bill_addr1": "16745 W Bernardo Dr.",
"bill_addr2": "",
"bill_city": "San Diego",
"bill_cntry": "TC",
"bill_comp": "Miva",
"bill_email": "johndoe@miva.com",
"bill_fax": "999-555-1234",
"bill_fname": "Test\u0021",
"bill_id": 1,
"bill_lname": "Order",
"bill_phone": "999-555-1234",
"bill_state": "CA",
"bill_zip": 92127,
"credit": 20,
"formatted_credit": "$20.00",
"id": 1,
"login": "johndoe",
"password": "PBKDF1:sha1:1000:xo9WyxBHubs\u003D:X7vMrJYbRhq7Pj\/Ur2mDd+nhITY\u003D",
"pgrpcount": 0,
"prefix": "",
"pw_email": "johndoe@miva.com",
"ship_addr": "16745 W Bernardo Dr.",
"ship_addr1": "16745 W Bernardo Dr.",
"ship_addr2": "",
"ship_city": "San Diego",
"ship_cntry": "TC",
"ship_comp": "Miva",
"ship_email": "johndoe@miva.com",
"ship_fax": "999-555-1234",
"ship_fname": "Test\u0021",
"ship_id": 1,
"ship_lname": "Order",
"ship_phone": "999-555-1234",
"ship_res": 0,
"ship_state": "CA",
"ship_zip": 92127,
"template_filename": "json-session-data-customer.mvc",
"template_id": 505
},
"sessions": {
"checkout_session_id": "",
"customer_session_id": "404ed9e7f854ec6b1879a4b7f75e099d",
"session_id": "d54515866b80e234d7c98dc22c39b058"
}
}