Shopify 实现一个产品订阅模块(Dawn主题模板)

参考网站

Add subscriptions to your theme

预览

前置条件

需创建多个同样但价格不一的产品

需要以当前产品创建多个产品,来设置捆绑数量,比如1件单独销售、2件起售、n件起售,享受不同的折扣和销售计划的折扣。(本质上还是一件产品,不同的价格)

如果是一个产品的销售计划直接复制参考网站代码

安装app创建销售计划

需要安装Shopify官方提供的Subscriptions设置产品订阅计划

设置过后插件通过admin api的muation,这样商店产品就有了“销售计划”这个属性。

创建产品元字段

主要是为了能把默认产品和具有订阅的产品相关联

代码实现

原理

shopify默认加购是form表单,然后使用ajax向shopify发送加购请求body是一个FormData,只需要添加隐藏的input,name为selling_plan,value是selling_plan的id即可。

技术实现

创建selling-plans-integration.liquid(snippets)、selling-plan.css(assets)、selling-plan.js(assets)

创建一个buy-buttons副本buy-selling-buttons,避免影响全局的buy-buttons,

buy-selling-buttons 里面循环元子字段绑定的产品,进而创建顶部tab,再同样循环加购表单,在表单里面render selling-plans-integration.liquid,然后点击tab显示隐藏订阅即可。

我们把所有值都绑定在select的option里(不同的订阅plan,如按周、月、年订阅),切换option拿到值动态渲染,点击一次性加购选项清空所有表单selling_plan的value值,点击订阅选项找到所有表单的select选中的option绑定在dom上的selling_plan的id并赋予到selling_plan这个隐藏的input上,就是这么个逻辑。

代码

selling-plans-integration.liquid
{%- assign current_variant = product.selected_or_first_available_variant | default: product.variants.first -%}
{% if product.selling_plan_groups.size > 0 %}
  <div class="selling_plan_app_container" data-section-id='{
  
  { section.id }}'>
    {% for variant in product.variants %}
      {% if variant.selling_plan_allocations.size > 0 %}
        <section data-variant-id='{
  
  { variant.id }}' class='selling_plan_theme_integration {% if variant.id != current_variant.id %}selling_plan_theme_integration--hidden{% endif %}'>
          <fieldset>
            <div>
              <div class="radio-container">
                <div class="radio-container--subscribe">
                  <label>
                    <input
                      value="sub"
                      type='radio'
                      name="purchaseOption_{
  
  { section.id }}_{
  
  { variant.id }}"
                      {% if variant.available == false %}disabled{% endif %}
                      data-variant-id='{
  
  { variant.id }}'
                      data-variant-saving ='{
  
  { variantSavingPrice }}'
                      checked
                    />
                    Subscribe & Save
                  </label>
                </div>
                {% unless product.requires_selling_plan %}
                  <div class="radio-container--one-time">
                    <label>
                      <input
                        value="one"
                        type='radio'
                        name="purchaseOption_{
  
  { section.id }}_{
  
  { variant.id }}"
                      />
                      One-time purchase
                    </label>
                  </div>
                {% endunless %}
              </div>
              {% assign variant_selling_price = product.selected_or_first_available_selling_plan_allocation.price %}
              {% assign variant_compare_at_price = product.selected_or_first_available_variant.compare_at_price %}
              {% assign variant_price = product.selected_or_first_available_variant.price %}
              <div class="price-wrapper">
                <div class="price-container selling-price">
                  {% if variant_selling_price == variant_price %}
                    <div class="price-regular">{
  
  { variant_selling_price | money }}</div>
                  {% else %}
                    <div class="price-sale">
                      <div class="price-item--sale">{
  
  { variant_selling_price | money }}</div>
                      <s class="price-item--regular">
                        {% if variant_compare_at_price %}
                          {
  
  { variant_compare_at_price | money }}
                        {% else %}
                          {
  
  { variant_price | money }}
                        {% endif %}
                      </s>
                      {% if variant_compare_at_price %}
                        {% assign real_compare_price = variant_compare_at_price %}
                      {% else %}
                        {% assign real_compare_price = variant_price %}
                      {% endif %}
                      {% assign saveing = real_compare_price| minus: variant_selling_price %}
                      <span class="save-price">Save {
  
  { saveing | money }}</span>
                    </div>
                  {% endif %}
                </div>
                <div class="price-container product-price">
                  {% if variant_price == variant_compare_at_price or variant_compare_at_price == blank %}
                    <div class="price-regular">{
  
  { variant_price | money }}</div>
                  {% else %}
                    <div class="price-sale">
                      <div class="price-item--sale">{
  
  { variant_price | money }}</div>
                      <s class="price-item--regular">{
  
  { variant_compare_at_price| money }}</s>
                    </div>
                  {% endif %}
                </div>
              </div>

              <div class="policy-wrapper">
                <div class="policy-advantage">
                  <ul>
                    <li>
                      <svg t="1744189199600" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="20488" width="24" height="24"><path d="M512 1024C229.239467 1024 0 794.760533 0 512 0 229.239467 229.239467 0 512 0c282.760533 0 512 229.239467 512 512 0 282.760533-229.239467 512-512 512z m245.521067-707.413333l-298.939734 275.387733-169.984-147.421867-38.263466 39.662934 208.145066 2
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值