How To

Magento B2B MSI

16min
the current version of klevu’s magento extension does not natively support indexing of magento's multi source inventory ( inventory management ) values the values must be provided into the klevu index so that they may be used for constraining the results to the desired source availability and/or indicating inventory two parameters are required at the product level during indexing one to identify the item is sold at the selected location one to identify the item is in stock at the selected location on the website front end, a filter is applied “behind the scenes” to the outgoing search query to constrain results to the visitors selected source/store if you are looking for msi salable availability (true/false) only, please review our sub module add on to see if it useful for your scenario https //github com/klevu/msi https //github com/klevu/msi the solution below will explain 1] options to provide the availability data and stock status at the product level to the klevu index extend the klevu search module klevu feed xml klevu indexing api 2] options to modify the outgoing search query to filter by the selected source and/or stock status klevu search api template js v2 override template js v1 variable if you are using the “preserve your magento layout” option of the klevu magento module, please contact customer support for guidance specific to your version the option selected for indexing and query will apply globally it is recommended to not mix indexing methods note the methods for obtaining the availability data will be the responsibility of your development team once the availability values have been indexed, the outgoing search queries to klevu can use the values for filtering based on source and/or stock availability note the name and value pairs used in this document are for examples only the actual values can be whatever best fits the implementation and business requirements so long as they are consistent for example indexing options to provide the availability data and stock status at the product level to the klevu index extend the klevu search module klevu feed xml klevu indexing api option 1 extend the klevu search module extend klevu's magento module to include the availability datapoints at the product level during catalog indexing the klevu module contains a function designed for adding additional datapoints https //github com/klevu/productsearch/blob/379fea472dbf1fa4eb15c3bcbf943fcb953fb89b/model/product/loadattribute php#l295 this function can be extended as preference and used for additional parameters added at the product level during indexing vendor/klevu/module productsearch/model/product/loadattribute php > processproductafter() / process product data if want to add any extra information from third party module @param $product @param $parent @param $item @return $this|mixed / public function processproductafter(&$product ,&$parent,&$item){ return $this; } source reference klevu productsearch on github example extended class and logic because there are many ways to work within the magento framework, the actual implementation as well as methods and applied logic for the availability data will be the responsibility of your development team it is strongly recommended to properly extend the klevu extension for this purpose to avoid potential conflicts during future updates to the system 1] extend the loadattribute class as preference \<preference for="klevu\search\model\product\loadattribute" type="klevu\override\model\product\loadattributecustom"/> 2] override the processproductafter function within the loadattribute class this example adds source availability and source instock as facets to the klevu module's indexing api call to klevu the product is sold at location1 and location2 (comma separated array), but is only in stock at location1 class loadattributecustom extends \klevu\search\model\product\loadattribute { public function processproductafter(&$product ,&$parent,&$item) { if (get source data) { $product\["other"]\["source availability"] = \["location1","location2"]; if (source stock logic here) { $product\["other"]\["source instock"] = "location1"; } return $this; } } } api reference data indexing docid 5yqa6etayyyqzwqhfx db option 2 klevu feed xml you may disengage the klevu module's built in sync and provide an external xml feed https //help klevu com/support/solutions/articles/5000871297 feed format file with the full catalog data, including the additional availability datapoints please reference the knowledge base article https //help klevu com/support/solutions/articles/5000871297 feed format for more information on using xml for data indexing the source availability datapoints can be entered using the \<attribute> node in this example the product is sold at location1 and location2 , but is only in stock at location1 \<attributes> \<attribute> \<id>source availability\</id> \<name>source availability\</name> \<is facet>true\</is facet> \<values> \<value>location1\</value> \<value>location2\</value> \</values> \</attribute> \<attribute> \<id>source instock\</id> \<name>source instock\</name> \<is facet>true\</is facet> \<values> \<value>location1\</value> \</values> \</attribute> \</attributes> note \<is facet> is set to true to allow filtering on the attribute source references klevu feed format guide and klevu feed example xml option 3 klevu indexing api you may disengage the klevu module's built in sync and use klevu’s data indexing docid 5yqa6etayyyqzwqhfx db directly for indexing the full catalog data, including the additional availability datapoints the source availability datapoints can be sent using the other key\ value pair (as facets) in this example the product is sold at location1 and location2 , but is only in stock at location1 \<?xml version="1 0" encoding="utf 8" ?> \<request> \<sessionid>your session id\</sessionid> \<records> \<record> \<pairs> \<pair> \<key>other\</key> \<value>source availability\ source availability\ location1,location2;source instock,source instock,location1\</value> \</pair> api reference data indexing docid 5yqa6etayyyqzwqhfx db querying options to modify the outgoing search query to filter by the selected source and/or stock status klevu search api template js v2 override template js v1 (legacy) if you are using the “preserve your magento layout” option of the klevu magento module, please contact customer support for guidance specific to your version option 1 klevu search api using the api parameter customandquery , a constraint can be applied for the query to those items that correspond to the selected source availability value example api request json using customandquery constraint this example adds source availability and source instock as filters to the template js api call to klevu the web visitor has selected to see items sold at location1 and only in stock at location1 "recordqueries" \[ { "settings" { "id" "productsearch", "customandquery" "(source availability \\"location1\\") and source instock \\"location1\\")", } ] source reference option 2 template js v2 override to apply the availability constraint within the context of the klevu template js ui the outgoing search request needs to be intercepted and modified see custom overrides docid bc3gcthleeatoyujdtue for details on preparing for klevu js overriding you may also find klevus example customization module on gihub useful for this scenario (and more) example override using customandquery constraint this example adds source availability and source instock as constraints to the template js api call to klevu the web visitor has selected to see items sold at location1 and only in stock at location1 the result set will only include items that meet these requirements klevu setobjectpath( data, "localoverrides query productlist settings customandquery", "(source availability \\"location1\\") and (source instock \\"location1\\")" ); note the above example applies the constraint to productlist query only for a complete javascript example of applying this to all query, see the complete template js example below complete template js example this example uses a common function to apply the availability constraint via customandquery override for all queries on quicksearch, search landing, and category pages javascript \<script type="text/javascript"> klevu modifyrequest("landing,catnav", function(data, scope){ // loop through all the pending queries klevu each(data request current recordqueries,function(key, query){ // set query contraints by availability location/stock klevu setobjectpath(data, "localoverrides query " + query id + " settings customandquery", "(source availability \\"location1\\") and (source instock \\"location1\\")" ); }); }); \</script> option 3 template js v1 (legacy) klevus legacy template provides a basic means to apply preset filters via a javascript variable this example adds source availability and source instock as filters to the template js api call to klevu the web visitor has selected to see items sold at location1 and only in stock at location1 var klevu userfilterresults = "source availability\ location1;;source instock\ location1";