This is more Javascript than MivaScript so I'll try to be clear
My client wants to be able to display variant level inventory messages on the product page as swatches are clicked. The current behavior is that the button is disabled and "Add to Cart" changes to the generic "Sold Out" which is hard coded into the javascript.
Instead In the admin, the client wants to change the inventory variant "Out of Stock" to "Available Fall 2016" and display that instead.
When the page loads, a Json object is created, but the variant inventory message is not output in the page. (although I'm sure it was loaded by the component)
When attribute selection change AttributeMachine loads that data, as explained below, but does not use the variant information so it is discarded and not saved with the AttributeMachine object.
When a swatch is selected Attribute_Machine triggers AttributeMachine.prototype.Swatch_Click(). This eventually triggers an Ajax call to
/mm5/json.mvc?Store_Code=VS&Function=Runtime_AttributeL ist_Load_ProductVariant_Possible. It eventually disables the button if the item is out of stock.
Later another function in script.js sees the button is disabled and changes the message.
My partial solution was to modify AttributeMachine.prototype.Swatch_Click() in the page template to do another duplicate Ajax call adding the variant data to the AttributeMachine object so I could use it later. That partially works but has some problems I won't go into here.
1. Should I use MivaEvents.SubscribeToEvent() instead? (provide example)
2. Is there a way to hook into the AttributeMachine to retrieve the entire contents of the Ajax response?
My client wants to be able to display variant level inventory messages on the product page as swatches are clicked. The current behavior is that the button is disabled and "Add to Cart" changes to the generic "Sold Out" which is hard coded into the javascript.
Instead In the admin, the client wants to change the inventory variant "Out of Stock" to "Available Fall 2016" and display that instead.
When the page loads, a Json object is created, but the variant inventory message is not output in the page. (although I'm sure it was loaded by the component)
When attribute selection change AttributeMachine loads that data, as explained below, but does not use the variant information so it is discarded and not saved with the AttributeMachine object.
When a swatch is selected Attribute_Machine triggers AttributeMachine.prototype.Swatch_Click(). This eventually triggers an Ajax call to
/mm5/json.mvc?Store_Code=VS&Function=Runtime_AttributeL ist_Load_ProductVariant_Possible. It eventually disables the button if the item is out of stock.
Later another function in script.js sees the button is disabled and changes the message.
My partial solution was to modify AttributeMachine.prototype.Swatch_Click() in the page template to do another duplicate Ajax call adding the variant data to the AttributeMachine object so I could use it later. That partially works but has some problems I won't go into here.
1. Should I use MivaEvents.SubscribeToEvent() instead? (provide example)
2. Is there a way to hook into the AttributeMachine to retrieve the entire contents of the Ajax response?
Code:
function Load_ProductVariantInventory (selected_option_id, input, attribute, option) { var selection = attrMachCall.Build_Selection(); var request = Runtime_AttributeList_Load_ProductVariant_Possible( attrMachCall.settings.product_code, attrMachCall.settings.dependency_resolution, attribute.id, attribute.template_attribute ? attribute.template_attribute.id : 0, selected_option_id, selection.selected_attr_ids, selection.selected_attmpat_ids, selection.selected_option_ids, selection.selected_attr_types, selection.unselected_attr_ids, selection.unselected_attmpat_ids, function( response ) { callback_Save_Variant(response); } ); } function callback_Save_Variant (response) { if ((response.success != 1) && (response.data.variant.inv_active != 1)) { return; } attrMachCall.currentVariantInventory = response.data.variant; console.log(attrMachCall.currentVariantInventory); }
Comment