Skip to content

Instantly share code, notes, and snippets.

@bheyde
Last active November 7, 2016 18:48
Show Gist options
  • Save bheyde/4bec5d476604a982c371afed68d5c71b to your computer and use it in GitHub Desktop.
Save bheyde/4bec5d476604a982c371afed68d5c71b to your computer and use it in GitHub Desktop.
Subscription Examples
<MvCOMMENT>Build Subscription Structure and Insert</MvCOMMENT>
<MvASSIGN NAME = "l.subscription:custpc_id" VALUE = 0>
<MvASSIGN NAME = "l.subscription:ship_id" VALUE = "{ l.shipping_module:id }">
<MvASSIGN NAME = "l.subscription:ship_data" VALUE = "{ l.module_data }">
<MvASSIGN NAME = "l.subscription:order_id" VALUE = 0>
<MvASSIGN NAME = "l.subscription:line_id" VALUE = 0>
<MvASSIGN NAME = "l.subscription:cust_id" VALUE = "{ l.customer:id }">
<MvASSIGN NAME = "l.subscription:product_id" VALUE = "{ l.product:id }">
<MvASSIGN NAME = "l.subscription:subterm_id" VALUE = "{ l.productsubscriptionterm:id }">
<MvASSIGN NAME = "l.subscription:addr_id" VALUE = "{ l.customeraddress:id }">
<MvASSIGN NAME = "l.subscription:quantity" VALUE = "{ g.Quantity }">
<MvASSIGN NAME = "l.subscription:termrem" VALUE = "{ l.productsubscriptionterm:term }">
<MvASSIGN NAME = "l.subscription:firstdate" VALUE = 0>
<MvASSIGN NAME = "l.subscription:lastdate" VALUE = "{ s.time_t }">
<MvASSIGN NAME = "l.subscription:nextdate" VALUE = "{ g.NextDate }">
<MvASSIGN NAME = "l.subscription:status" VALUE = "A">
<MvASSIGN NAME = "l.subscription:message" VALUE = "">
<MvASSIGN NAME = "l.subscription:cncldate" VALUE = 0>
<MvIF EXPR = "{ NOT [ g.Module_Feature_SUB_DB ].Subscription_Insert( l.subscription ) }">
<MvFUNCTIONRETURN VALUE = "{ [ g.Library_Utilities ].Error( g.Error_Code, g.Error_Message ) }">
</MvIF>
<MvCOMMENT>Loop though product attributes and add to subscriptionOption table</MvCOMMENT>
<MvASSIGN NAME = "l.subscriptionoptions" VALUE = "">
<MvASSIGN NAME = "l.subscriptionoption_count" VALUE = 0>
<MvIF EXPR = "{ l.attribute_count }">
<MvASSIGN NAME = "l.subscriptionoption:subscrp_id" VALUE = "{ l.subscription:id }">
<MvFOREACH ITERATOR = "l.attribute" ARRAY = "l.attributes" COUNT = "{ l.attribute_count }">
<MvASSIGN NAME = "l.subscriptionoption:templ_code" VALUE = "{ l.attribute:template_code }">
<MvASSIGN NAME = "l.subscriptionoption:attr_code" VALUE = "{ l.attribute:code }">
<MvASSIGN NAME = "l.subscriptionoption:value" VALUE = "{ l.attribute:value }">
<MvASSIGN NAME = "l.subscriptionoption_count" VALUE = "{ miva_array_insert( l.subscriptionoptions, l.subscriptionoption, -1 ) }">
<MvIF EXPR = "{ NOT [ g.Module_Feature_SUB_DB ].SubscriptionOption_Insert( l.subscriptionoption ) }">
<MvFUNCTIONRETURN VALUE = "{ [ g.Library_Utilities ].Error( g.Error_Code, g.Error_Message ) }">
</MvIF>
</MvFOREACH>
</MvIF>
custpc_id
Customer Payment Card ID. This will always be 0. We are going to be manually bring over the credit card data.
ship_id
This is the id of the shipping module used for the shipping method
ship_data
This is the shipping method used for the subscription order. This needs to match a shipping method from that module referenced above.
order_id
This is either 0 (say for example if the subscription was created via the admin) or it should contain the initail order that created the subscription.
line_id
This references the specific line_id of the item in the order that is attached to the subscription. This is 0 if the subscription was created via the admin.
cust_id
id of the customer attached to the subscription
product_id
id of product contained within the subscription (Each subscription can only have a single product). If a customer has multiple products on re-order they need to be
setup a seperate subscriptions.
subterm_id
This is the Subscription Term Id. This will need to be looked up a the the product level. Say for example the customer ordered product XYZ evey 30 days, there is
a specific subscription term for that product that needs to be looked up and added here.
addr_id
This is that address book address attached to the subscription.
quantity
quantity being orders
termrem
This value sets when the subscription will expire. For example if you had a magazine and only wanted 12 month memeberhsip. 0 = unlimited.
firstdate (unix time)
Date of the first subscription re-order. Should be 0 upon create. Gets updated when first subscription order is created
lastdate (unix time)
Date of last re-order.
NextDate (unix time)
date of next re-order. This needs to be calculated as date of last re-order + term (20 days, 60 days etc)
status
3 status states: A = Active, E= Error, C = Cancelled
message
message displayed if the subscription is in an Error State.
cncldate
cancellation date. Should 0. Only used for cancelled subscriptions.
<MvASSIGN NAME = "l.productsubscriptionterm:product_id" VALUE = "{ l.product:id }">
<MvASSIGN NAME = "l.productsubscriptionterm:frequency" VALUE = "{ g.Frequency }">
<MvASSIGN NAME = "l.productsubscriptionterm:n" VALUE = "{ g.N_Days }">
<MvASSIGN NAME = "l.productsubscriptionterm:fixed_dow" VALUE = "{ g.DayOfWeek }">
<MvASSIGN NAME = "l.productsubscriptionterm:fixed_dom" VALUE = "{ g.DayOfMonth }">
<MvASSIGN NAME = "l.productsubscriptionterm:term" VALUE = "{ g.Term }">
<MvASSIGN NAME = "l.productsubscriptionterm:sub_count" VALUE = 0>
<MvIF EXPR = "{ NOT [ g.Module_Feature_SUB_DB ].ProductSubscriptionTerm_Insert( l.productsubscriptionterm ) }">
<MvFUNCTIONRETURN VALUE = "{ [ g.Library_Utilities ].Error( g.Error_Code, g.Error_Message ) }">
</MvIF>
Frequency Options
<option value="n">Every N Days (From Purchase Date)</option>
<option value="daily">Daily</option>
<option value="weekly">Weekly (From Purchase Date)</option>
<option value="biweekly">Biweekly (From Purchase Date)</option>
<option value="monthly">Monthly (From Purchase Date)</option>
<option value="quarterly">Quarterly (From Purchase Date)</option>
<option value="semiannually">Semiannually (From Purchase Date)</option>
<option value="annually">Annually (From Purchase Date)</option>
<option value="fixedweekly">Fixed Day of Week</option>
<option value="fixedmonthly">Fixed Day of Month</option>
<option value="dates">Specific Dates Annually</option>
n Options (Number of Days)
Interger value for how often the subscription reorders occur. ex. 30, 60, 90. etc
Term
This value sets when the subsscription will expire. For example if you had a magazine and only wanted 12 month memeberhsip.
0 = Unlimited
Otherwise, interger value
sub_count
Interger. Number of subscriptions that reference this specific products term. Alwasy 0 when inserted, and updated when a subscription uses this products term.
fixed_dow
Interger value. Used when Frequency option is "fixedweekly". Pass 0 if not used
fixed_dom
Interger value. Used when Frequency option is "fixedmonthly". Pass 0 if not used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment