Wrote a module that takes 3rd party data and imports it into the combo facets using the JSON API. The data all the way to the MVCall is only showing single values but it doubles the results in the combo facets database. It doesn't do it all the time, just for some products and I can't figure out a pattern. Curious if anyone else has had this issue or could provide some insight.
Announcement
Collapse
No announcement yet.
JSON API MvCall Doubling Data
Collapse
X
-
Code:<MvFUNCTION NAME = "JSON_Engine_ComboFacetsRecord_MultiAdd" PARAMETERS = "engines, product" STANDARDOUTPUTLEVEL = "text, html"> <MvCAPTURE VARIABLE = "l.xml_data"> <Module code=\"combofacets\" feature=\"util\"> <MvFOREACH ITERATOR = "l.engine" ARRAY = "l.engines"> <MvEVAL EXPR = "{ '<CombinationFacetRecord_Add product_code=' $ '\\"' $ l.product:code $ '\\" facet_code=\\"engine\\">' }"> <CombinationFacetField field_code=\"engine\"><MvEVAL EXPR = "{ encodeentities( l.engine:name ) }"></CombinationFacetField> </CombinationFacetRecord_Add> </MvFOREACH> </Module> </MvCAPTURE> <MvIF EXPR = "{ NOT JSON_MVCall( l.xml_data ) }"> <MvFUNCTIONRETURN VALUE = "{ [ g.Module_JSON ].JSON_Response_Error( g.Error_Code, g.Error_Message ) }"> </MvIF> <MvFUNCTIONRETURN VALUE = 1> </MvFUNCTION>
Code:<MvFUNCTION NAME = "JSON_MVCall" PARAMETERS = "xml_data" STANDARDOUTPUTLEVEL = "text, html, compresswhitespace" ERROROUTPUTLEVEL = ""> <MvASSIGN NAME = "l.endpoint" VALUE = "{ g.secure_baseurl $ 'json.mvc?' }"> <MvASSIGN NAME = "l.access_token" VALUE = "xxx"> <MvASSIGN NAME = "l.signature" VALUE = "{ crypto_base64_decode('xxx') }"> <MvASSIGN NAME = "l.timestamp" VALUE = "{ '\"Miva_Request_Timestamp\" : ' $ '\"' $ s.time_t $ '\",' }"> <MvCAPTURE VARIABLE = "l.json_data"> { <MvEVAL EXPR = "{ l.timestamp }"> "Store_Code" : "<MvEVAL EXPR = "{ encodeentities( g.Store:code ) }">", "Function" : "Provision_Store", "xml" : "<MvEVAL EXPR = "{ l.xml_data }">" } </MvCAPTURE> <MvASSIGN NAME = "l.ok" VALUE = "{ crypto_hmac_sha256(l.json_data,l.signature,'binary ',l.hmac_response) }"> <MvASSIGN NAME = "l.b64encoded_hmac_response" VALUE = "{ crypto_base64_encode(l.hmac_response) }"> <MvASSIGN NAME = "l.headers" VALUE = "{ 'X-Miva-API-Authorization: MIVA-HMAC-SHA256 ' $ l.access_token $ ':' $ l.b64encoded_hmac_response $ asciichar( 13 ) $ asciichar( 10 ) }"> <MIVA MvCALL_ERROR = "nonfatal, nodisplay"> <MvCALL ACTION = "{ l.endpoint }" METHOD = "RAW" HEADERS = "{ l.headers }" CONTENT-TYPE = "application/json" FIELDS = "l.json_data"> <MvCOMMENT> <MvEVAL EXPR = "{ 'Response: ' $ s.callvalue }"><br> </MvCOMMENT> </MvCALL> <MIVA MvCALL_ERROR = "fatal, display"> <MvIF EXPR = "{ g.MvCALL_Error }"> <MvFUNCTIONRETURN VALUE = "{ [ g.Module_JSON ].JSON_Response_Error( g.Error_Code, g.MvCALL_Error ) }"> </MvIF> <MvFUNCTIONRETURN VALUE = 1> </MvFUNCTION>
Last edited by K Series Parts; 05-19-24, 04:40 AM.Chris Dye
http://www.kseriesparts.com
Comment
-
I don't see anything immediately wrong with this. Are you sure the number of engines passed in doesn't have duplicates? You should call log the request made to the API to ensure duplicate values are not being included. Also are you sure you are not calling this function more than 1 time? Calling it multiple times would add duplicate values.David Carver
Miva, Inc. | Software Developer
Comment
-
not sure if this was it but I had changed from an assign to an eval in the xml function when I posted this and that seemed to stop it from double importing from my testing so farChris Dye
http://www.kseriesparts.com
Comment
-
Hi Chris,
I'm curious as to how large your XML can get? Maybe in the context of how many products do you need to update per XML string?
Thanks,
ScottNeed to offer Shipping Insurance?
Interactive Design Solutions https://www.myids.net
MivaMerchant Business Partner | Certified MivaMerchant Web Developer
Competitive Rates, Custom Modules and Integrations, Store Integration
AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
My T-shirt Collection is mostly MivaCon T-shirts!!
Comment
Comment