当前位置: 首页>>代码示例>>PHP>>正文


PHP Plan::createStripePlans方法代码示例

本文整理汇总了PHP中Plan::createStripePlans方法的典型用法代码示例。如果您正苦于以下问题:PHP Plan::createStripePlans方法的具体用法?PHP Plan::createStripePlans怎么用?PHP Plan::createStripePlans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Plan的用法示例。


在下文中一共展示了Plan::createStripePlans方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: edit

 public function edit()
 {
     $options = $this->config->config['period_qualifier'];
     $error = array();
     $plan = new Plan();
     $features = new Feature();
     $request = $this->getRequest();
     //check if data was sent
     if ($this->isRequestMethod('POST')) {
         $weight = $request->request->get('plan_weight', '') ?: (int) $plan->getActualPlans()->weight + 1;
         $plan->clear();
         $plan->get_by_id($request->request->get('id'));
         $plan->weight = $weight;
         $plan->name = $request->request->get('name');
         $trial = $request->request->get('trial');
         $plan->trial = !empty($trial);
         $special = $request->request->get('special');
         $plan->special = !empty($special);
         $featuresIds = $request->request->get('feature');
         $saveFeatures = array();
         $saveFeaturesIds = array();
         //check if features was selected
         if (implode('', $featuresIds) == '') {
             $error[] = lang('attached_features_count_error');
         } else {
             $weight = 1;
             //save features of plan
             foreach ($featuresIds as $id) {
                 if ($id) {
                     $plansFeature = new Plans_feature($request->request->get('feature_' . $id . '_plansfeatureid', ''));
                     $plansFeature->feature_id = $id;
                     if ($request->request->has('feature_' . $id . '_value')) {
                         $value = $request->request->get('feature_' . $id . '_value');
                         $featureValidator = new Feature($id);
                         if ($featureValidator->validValue($value)) {
                             $plansFeature->value = $value;
                         } else {
                             $error[] = lang('attached_features_type_error', [$featureValidator->name, $featureValidator->type]);
                         }
                     }
                     $plansFeature->weight = $weight;
                     if ($plansFeature->save()) {
                         $saveFeatures[] = $plansFeature;
                         $saveFeaturesIds[] = $plansFeature->id;
                         $weight++;
                     }
                 }
             }
         }
         //save periods of plan
         $savePeriods = array();
         $savePeriodsIds = array();
         if ($count = count($request->request->get('period_id'))) {
             $periodId = $request->request->get('period_id');
             $period = $request->request->get('period');
             $qualifier = $request->request->get('qualifier');
             $price = $request->request->get('price');
             for ($i = 0; $i < $count; $i++) {
                 $planPeriod = new Plans_period($periodId[$i]);
                 $planPeriod->period = $period[$i];
                 $planPeriod->qualifier = $qualifier[$i];
                 $planPeriod->price = $price[$i];
                 if ($planPeriod->save()) {
                     $savePeriods[] = $planPeriod;
                     $savePeriodsIds[] = $planPeriod->id;
                 }
                 if ($planPeriod->error->string) {
                     $error[] = $planPeriod->error->string;
                 }
             }
         }
         //save plan with related features and period
         if (empty($error)) {
             $plan->save(array($saveFeatures, $savePeriods));
             $plan->createStripePlans();
         }
         if ($plan->errors->string) {
             $error[] = $plan->errors->string;
         }
         if (!empty($error)) {
             $this->addFlash(implode('', $error));
             $this->session->set_flashdata('recent', $request->request->all());
             $planParam = $plan->id ? '?plan=' . $plan->id : '';
             redirect('/admin/manage_plans/edit' . $planParam);
         } else {
             $plan->deleteOldPlanPeriods($savePeriodsIds);
             $plan->deleteOldPlanfeatures($saveFeaturesIds);
         }
         redirect('/admin/manage_plans/');
     }
     $planId = $request->query->get('plan', '');
     $plan->get_by_id($planId);
     $plansFeatures = $plan->getAttachedFeatures();
     $plansPeriod = $plan->plans_period->get();
     //fill data after bad validation
     if ($recent = $this->session->flashdata('recent')) {
         //recent selected features
         foreach ($plansFeatures as $planFeature) {
             $featureId = $planFeature->feature_id;
             if (in_array($featureId, $recent['feature'])) {
//.........这里部分代码省略.........
开发者ID:andrewkrug,项目名称:repucaution,代码行数:101,代码来源:manage_plans.php


注:本文中的Plan::createStripePlans方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。