-
-
Save Kayakbabe/69f78279865d718c71e213d921ea1bf8 to your computer and use it in GitHub Desktop.
Recently Viewed Items Functionality. All custom Miva code, not run by module. It stores a list of product codes, and displays up to the 12 most recent products a customer has viewed. It also stores the list to a custom customer field in case the user is logged in and then comes back later.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*****ACLN***** | |
<mvt:comment>Upon login, read custom field that holds their recently viewed item codes. Then save this value to basket session field for use to display recently viewed items.</mvt:comment> | |
<mvt:if expr="g.Action EQ 'LOGN'"> | |
<mvt:item name="customfields" param="Read_Customer_ID( g.customer:id, 'recentlyViewed', l.settings:recentlyViewed )" /> | |
<mvt:item name="customfields" param="Write_Basket( 'recentlyViewed', l.settings:recentlyViewed )" /> | |
</mvt:if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*****PROD - Top Of Page***** | |
<mvt:comment>Recently Viewed Products Functionality</mvt:comment> | |
<mvt:comment>Ready session basket field that holds product code list</mvt:comment> | |
<mvt:item name="customfields" param="Read_Basket( 'recentlyViewed', l.settings:recentlyViewed )" /> | |
<mvt:comment>Create Miva array from comma separated list</mvt:comment> | |
<mvt:assign name="l.settings:recentlyViewed" value="miva_array_deserialize(l.settings:recentlyViewed)" /> | |
<mvt:comment>Check to ensure product code is not already in list</mvt:comment> | |
<mvt:if expr="miva_array_find( l.settings:product:code, l.settings:recentlyViewed, 0 ) EQ 0"> | |
<mvt:comment>Count the number of codes in the array, and check if there are 13 (12 to show, one extra if viewing product already in list)</mvt:comment> | |
<mvt:assign name="g.rv_count" value="miva_array_elements(l.settings:recentlyViewed)"/> | |
<mvt:if expr="g.rv_count EQ 13"> | |
<mvt:comment>Remove the oldest code (position 1), to keep the list to 12 products long</mvt:comment> | |
<mvt:assign name="l.remove" value="miva_array_delete(l.settings:recentlyViewed, '1', '1')"/> | |
</mvt:if> | |
<mvt:comment>Insert the new code at the end of the array</mvt:comment> | |
<mvt:assign name="l.index" value="miva_array_insert( l.settings:recentlyViewed, l.settings:product:code, -1 )" /> | |
<mvt:comment>Save new list to basket session field and to the customer's custom field for later use if they come back to store and log in</mvt:comment> | |
<mvt:item name="customfields" param="Write_Basket( 'recentlyViewed', l.settings:recentlyViewed )" /> | |
<mvt:item name="customfields" param="Write_Customer_ID( g.customer:id, 'recentlyViewed', l.settings:recentlyViewed )" /> | |
</mvt:if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*****PROD - Recently Viewed Section***** | |
<mvt:item name="customfields" param="Read_Basket( 'recentlyViewed', l.settings:recentlyViewed )" /> | |
<mvt:assign name="l.settings:recentlyViewed" value="miva_array_deserialize(l.settings:recentlyViewed)" /> | |
<mvt:assign name="g.fcount" value="miva_array_elements(l.settings:recentlyViewed)"/> | |
<mvt:comment>If the current product is part of the recently viewed items, then subtract one from the array count since we don't want to show the current product as part of the "recently viewed"</mvt:comment> | |
<mvt:if expr="miva_array_find( l.settings:product:code, l.settings:recentlyViewed, 0 ) NE 0"> | |
<mvt:assign name="g.fcount" value="g.fcount - 1"/> | |
</mvt:if> | |
<mvt:foreach iterator="rv_item_code" array="recentlyViewed"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(l.settings:rv_item_code, l.settings:rv_item)" /> | |
<mvt:comment>Only place active products into footsteps array</mvt:comment> | |
<mvt:if expr="l.settings:rv_item:active EQ 1"> | |
<mvt:comment>Grab full product data, via the base product variable - necessary to pull in base price data after discount function is run below.</mvt:comment> | |
<mvt:do file="g.Module_Feature_TUI_UT" name="l.success" value="CommonComponentFields_Initialize_Product_Runtime(l.settings:rv_item)" /> | |
<mvt:assign name="l.index" value="miva_array_insert( l.settings:footsteps, l.settings:rv_item, -1 )" /> | |
</mvt:if> | |
</mvt:foreach> | |
<mvt:comment>Loading product's discount data from sale and strike through pricing</mvt:comment> | |
<mvt:do name="l.null" file="g.Module_Feature_TUI_UT" value="CommonComponentFields_Initialize_Product_Discounts_Runtime(l.settings:footsteps, miva_array_elements(l.settings:footsteps))" /> | |
<mvt:if expr="miva_array_find( l.settings:product:code, l.settings:footsteps, 0 ) NE 0"> | |
<mvt:assign name="g.fcount" value="g.fcount - 1"/> | |
</mvt:if> | |
<mvt:if expr="g.fcount GT 0"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="ImageType_Load_Code( 'main', l.imagetype:main )" /> | |
<mvt:assign name="l.width" value="320" /> | |
<mvt:assign name="l.height" value="320" /> | |
<mvt:foreach iterator="footstep" array="footsteps"> | |
<mvt:comment>Skip the current product from showing in the recently viewed array</mvt:comment> | |
<mvt:if expr="l.settings:footstep:code EQ l.settings:product:code"> | |
<mvt:foreachcontinue /> | |
</mvt:if> | |
<mvt:comment> NULL Out Variables </mvt:comment> | |
<mvt:assign name="l.success" value="''"/> | |
<mvt:assign name="l.loaded_type" value="NULL" /> | |
<mvt:assign name="l.imagedata" value="NULL" /> | |
<mvt:assign name="l.image" value="NULL" /> | |
<mvt:assign name="l.generated_image:image" value="NULL" /> | |
<mvt:comment>Load Product Image</mvt:comment> | |
<mvt:do name="l.success" file="g.Module_Library_DB" value="ProductImage_Load_Type(l.settings:footstep:id, l.imagetype:main:id, l.loaded_type)" /> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="Image_Load_ID( l.loaded_type:image_id, l.imagedata )" /> | |
<mvt:do file="g.Module_Library_DB" name="l.image_loaded_success" value="Image_Load_File( l.imagedata:image, l.image )" /> | |
<mvt:if expr="l.image_loaded_success EQ 1"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="GeneratedImage_FindOrInsert_Image_Dimensions( l.image, l.width, l.height, l.generated_image )" /> | |
<mvt:if expr="l.generated_image"> | |
<mvt:assign name="l.settings:footstep_image" value="l.generated_image:image" /> | |
</mvt:if> | |
</mvt:if> | |
<mvt:assign name="l.uri:store_id" value="g.Store:id" /> | |
<mvt:assign name="l.uri:screen" value="''" /> | |
<mvt:assign name="l.uri:page_id" value="0" /> | |
<mvt:assign name="l.uri:cat_id" value="0" /> | |
<mvt:assign name="l.uri:product_id" value="l.settings:footstep:id" /> | |
<mvt:do file="g.Module_Feature_URI_DB" name="l.have_uri" value="URI_Load_Item_Canonical( l.uri, l.settings:footstep:link )" /> | |
<mvt:item name="customfields" param="Read_Product_ID(l.settings:footstep:id, 'product_tag', l.settings:footstep:customfield_values:customfields )" /> | |
<mvt:comment>HTML CODE HERE</mvt:comment> | |
</mvt:foreach> | |
</mvt:if> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment