我有类似的问题,如@wizones373在商业许可证计费:当用户的计划发生变化且计费周期提前时,我如何收取或退还按比例计算的金额?上所描述的,但目标不同。
在带有用于订阅的Commerce license计费模块的Drupal 7网站上,通过在许可实体($ License -> product_id )上保存新的product_id来更改订阅计划实际上会更新许可证和下一次定期付款订单上的到期金额,但是它不会更新许可证的granted和expires字段。
因此,我试图从许可中获取这些字段的值,进行计算,并将它们与整个许可实体一起保存,如下所示:
$bct=$form_state['storage']['target_product']->cl_billing_cycle_type[LANGUAGE_NONE][0]['target_id'];
if ($bct == '1') { // hourly
$target_date = strtotime('+1 hour', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
} elseif ($bct == '2') { // daily
$target_date = strtotime('+1 day', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
} elseif ($bct == '3') { // monthly
$target_date = strtotime('+1 month', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
} elseif ($bct == '4') { // quarterly
$target_date = strtotime('+3 months', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
} elseif ($bct == '5') { // biannually
$target_date = strtotime('+6 months', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
} else { // biannually
$target_date = strtotime('+1 year', REQUEST_TIME);
$license[arg(1)]->expires = $target_date;
}
$license[arg(1)]->granted = strtotime("now");
$license[arg(1)]->product_id = $form_state['storage']['selected_plan'];
entity_save('commerce_license', $license[arg(1)]);
drupal_set_message('License has been updated.');保存许可实体后的admin/commerce/licenses页面显示,所有相关字段--新的product_id、已授予的字段和过期的字段--实际上都已经更新。
但问题是,当过期时,granted字段返回到初始值,而expired字段的值是根据初始granted字段计算的。
换句话说,猜测我有两个计费周期--每小时和每天--如果一个初始订单是按小时计费周期下的,那么将创建具有以下字段的许可:
Cycle: Hourly
Granted: 15 January 2018 - 17:50
Expires: 15 January 2018 - 18:50如果我用新产品id更新许可证,“授予”和“过期”字段,则admin/commerce/licenses显示:
Cycle: Daily
Granted: 15 January 2018 - 17:52
Expires: 16 January 2018 - 17:52当2018年1月16日- 17:52到来并处理所有相关的cron任务时,同一页显示:
Cycle: Daily
Granted: 15 January 2018 - 17:52
Expires: 15 January 2018 - 20:48同时,会收取大量额外的订单,并创建具有Recurring: Open状态的新的重复订单,然后只有显示已授予和过期字段的许可证管理页面(值从2018年1月16日到17:52)随着每个cron的执行而不断变化:
Cycle: Daily
Granted: Active 15 January 2018 - 17:52
Expires: 16 January 2018 - 01:48所以我的问题是:
如果更改许可实体中的granted和expires字段的值不生效,那么我还应该在哪里寻找更改这些值的方法?
发布于 2018-01-15 20:15:58
在监视了数据库表随周期性产品的变化之后,我注意到用新数据保存许可证是不够的,cl_billing_cycle还应该用新的授予日期和到期日期进行更新。
我现在使用的是直接数据库查询。如果有更好的方法更新cl_billing_cycle,请告诉我。
https://drupal.stackexchange.com/questions/253811
复制相似问题