Last active
September 12, 2017 17:21
-
-
Save steveosoule/d8c60f816de1a2621e4cf6edaffcf56c to your computer and use it in GitHub Desktop.
Miva - Marketing Feed - Variant Price Range Generator
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
<mvt:comment> | |
------------------------------------------------ | |
Variant Price-Range Generator | |
Code: TEMPLATEFEED_VPRG | |
Iterator Template | |
Instructions: | |
1. Create a new Marketing > Feed and configure it as follows: | |
- Code: VPRG | |
- Name: Variant Price-Range Generator | |
- Feed Module: Template Based Feed | |
- Enable URI Access (optional, if you'd like to use it for testing/debugging) | |
- Enable File Creation (optional, if you'd like to be able to click "Process Now" from the Marketing > Feeds page in the admin) | |
- Template: Product | |
2. Navigate to the `TEMPLATEFEED_VPRG` page template code in the Admin | |
3. Switch to Advanced Mode | |
4. Clear out the "Header Template" | |
5. Populate the "Iterator Template" with this snippet's code. | |
6. Assign the `customfields` item to the Feed's page. | |
7. Create the following product custom fields | |
You can import this XML provisioning if you'd like, or just manually create them with the same codes: | |
``` | |
<Module code="customfields" feature="util"> | |
<ProductField_Add> | |
<code>variant_price_range</code> | |
<name>Variant Prices: Price Range</name> | |
<info>Automatically populated by "Variant Price-Range Generator" Marketing Feed.</info> | |
</ProductField_Add> | |
<ProductField_Add> | |
<code>variant_price_low</code> | |
<name>Variant Prices: Lowest Price</name> | |
<info>Automatically populated by "Variant Price-Range Generator" Marketing Feed.</info> | |
</ProductField_Add> | |
<ProductField_Add> | |
<code>variant_price_high</code> | |
<name>Variant Prices: Highest Price</name> | |
<info>Automatically populated by "Variant Price-Range Generator" Marketing Feed.</info> | |
</ProductField_Add> | |
</Module> | |
``` | |
8. Run the feed and test that the custom fields are being populated. | |
9. Setup a Store Settings > Scheduled Tasks to generate the feed daily, weekly, etc. | |
You can import this XML provisioning if you'd like, or just manually create them with the same codes: | |
``` | |
<ScheduledTask_Add> | |
<Description>Generate Variant Price Ranges</Description> | |
<Enabled>1</Enabled> | |
<RunInterval units="days">1</RunInterval> | |
<Module>stdschtasks</Module> | |
<Operation>feed</Operation> | |
<Settings> | |
<Feed>VPRG</Feed> | |
</Settings> | |
</ScheduledTask_Add> | |
``` | |
------------------------------------------------ | |
</mvt:comment> | |
<h2>&mvt:record:name;</h2> | |
<mvt:comment> | |
====Load Product Attributes==== | |
</mvt:comment> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="AttributeList_Load_Product(l.settings:record:id, l.settings:record:attributes)" /> | |
<mvt:if expr="l.settings:record:attributes[1]:attemp_id GT 0"> | |
<mvt:do file="g.Module_Feature_ATT_DB" name="l.success" value="AttributeTemplateAttrList_Load_Template(l.settings:record:attributes[1]:attemp_id, l.settings:record:attributes)" /> | |
</mvt:if> | |
<mvt:comment> | |
====Load Product Attribute Options + Add Option Prices to Array==== | |
</mvt:comment> | |
<mvt:foreach iterator="attribute" array="record:attributes"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="OptionList_Load_Attribute(l.settings:attribute:id, l.settings:attribute:options)" /> | |
<mvt:foreach iterator="option" array="attribute:options"> | |
<mvt:comment> | |
====Check if Product has Variants + Load the Variant List==== | |
</mvt:comment> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductVariantList_Load_Product_Option( l.settings:record:id, l.settings:attribute:id, l.settings:option:id, l.settings:option:variants )" /> | |
<mvt:if expr="l.settings:option:variants[1]"> | |
<mvt:comment> | |
====Load the Variant Parts==== | |
</mvt:comment> | |
<mvt:foreach iterator="variant" array="option:variants"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Variant( l.settings:record:id, l.settings:variant:variant_id, l.settings:variant:parts )" /> | |
<mvt:foreach iterator="part" array="variant:parts"> | |
<mvt:comment> | |
====Determine Highest & Lowest Variant Part Prices==== | |
</mvt:comment> | |
<mvt:if expr="l.settings:part:price GT 0"> | |
<mvt:if expr="ISNULL l.settings:record:price_range:lowest OR l.settings:part:price LT l.settings:record:price_range:lowest"> | |
<mvt:assign name="l.settings:record:price_range:lowest" value="l.settings:part:price" /> | |
</mvt:if> | |
<mvt:if expr="ISNULL l.settings:record:price_range:highest OR l.settings:part:price GT l.settings:record:price_range:highest"> | |
<mvt:assign name="l.settings:record:price_range:highest" value="l.settings:part:price" /> | |
</mvt:if> | |
</mvt:if> | |
</mvt:foreach> | |
</mvt:foreach> | |
</mvt:if> | |
</mvt:foreach> | |
</mvt:foreach> | |
<mvt:if expr="l.settings:record:price_range:lowest AND l.settings:record:price_range:highest"> | |
<mvt:do file="'/mm5/5.00/modules/currency/usmoney.mvc'" name="l.settings:record:price_range:lowest_formatted" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:record:price_range:lowest )" /> | |
<mvt:do file="'/mm5/5.00/modules/currency/usmoney.mvc'" name="l.settings:record:price_range:highest_formatted" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:record:price_range:highest )" /> | |
<mvt:assign name="l.settings:record:price_range:text" value="l.settings:record:price_range:lowest_formatted $ ' - ' $ l.settings:record:price_range:highest_formatted" /> | |
<mvt:item name="customfields" param="Write_Product_ID(l.settings:record:id, 'variant_price_range', l.settings:record:price_range:text)" /> | |
<mvt:item name="customfields" param="Write_Product_ID(l.settings:record:id, 'variant_price_low', l.settings:record:price_range:lowest)" /> | |
<mvt:item name="customfields" param="Write_Product_ID(l.settings:record:id, 'variant_price_high', l.settings:record:price_range:highest)" /> | |
</mvt:if> | |
<mvt:eval expr="glosub(miva_array_serialize(l.settings:record), ',', '<br>')" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment