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


PHP CartRule::save方法代码示例

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


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

示例1: postProcess

 public function postProcess()
 {
     //ADD
     if (Tools::isSubmit('submitAddcampaign')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         // ADD WAY
         if (!($id_campaign = (int) Tools::getValue('id_campaign')) && empty($this->errors)) {
             $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
             // Include voucher :
             if (Tools::getValue('include_voucher') == '1') {
                 // Check values for voucher :
                 $voucher_name = Tools::getValue('voucher_name');
                 $voucher_code = Tools::getValue('voucher_code');
                 $voucher_amount_type = Tools::getValue('voucher_amount_type');
                 $voucher_amount_value = Tools::getValue('voucher_amount_value');
                 $voucher_date = Tools::getValue('voucher_date_to');
                 $new_voucher = new CartRule(null, $defaultLanguage->id);
                 $new_voucher->name = $voucher_name;
                 $new_voucher->date_from = date('Y-m-d');
                 $new_voucher->date_to = $voucher_date;
                 $new_voucher->description = 'Campaign : ' . $voucher_name;
                 $new_voucher->code = $voucher_code;
                 $new_voucher->quantity = 1000;
                 // Todo : Update when campaign is lunch to number of concerned people
                 // Si percent :
                 if ($voucher_amount_type == 'percent') {
                     $new_voucher->reduction_percent = $voucher_amount_value;
                 } else {
                     $new_voucher->reduction_amount = $voucher_amount_value;
                 }
                 $new_voucher->save();
             }
             // Create campaign :
             $campaign = new Campaign();
             $campaign->name = Tools::getValue('name');
             $campaign->email_tpl = Tools::getValue('email_tpl');
             $campaign->execution_time_day = Tools::getValue('execution_time_day');
             $campaign->execution_time_hour = Tools::getValue('execution_time_hour');
             $campaign->voucher_amount_type = Tools::getValue('voucher_amount_type');
             if (isset($new_voucher->id)) {
                 $campaign->id_voucher = $new_voucher->id;
             } else {
                 $campaign->id_voucher = 0;
             }
             $campaign->active = Tools::getValue('active');
             // Create email files :
             $path = _PS_ROOT_DIR_ . '/modules/superabandonedcart/mails/' . $defaultLanguage->iso_code . '/';
             if (!file_exists($path)) {
                 if (!mkdir($path, 0777, true)) {
                     $this->errors[] = Tools::displayError('Mails directory could not be created. Please check system permissions');
                 }
             }
             $tpl_file_name = $campaign->getFileName('html');
             // create html files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, $campaign->email_tpl);
             fwrite($f, PHP_EOL);
             fclose($f);
             $tpl_file_name = $campaign->getFileName('txt');
             // create txt files
             $f = fopen($path . $tpl_file_name, 'w');
             fwrite($f, strip_tags($campaign->email_tpl));
             fwrite($f, PHP_EOL);
             fclose($f);
             if (!$campaign->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             }
             // UPDATE WAY
         } elseif ($id_campaign = Tools::getValue('id_campaign')) {
             $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
             $campaign = new Campaign($id_campaign);
             // Include voucher :
             if (Tools::getValue('include_voucher') == '1') {
                 $voucher_name = Tools::getValue('voucher_name');
                 $voucher_code = Tools::getValue('voucher_code');
                 $voucher_amount_type = Tools::getValue('voucher_amount_type');
                 $voucher_amount_value = Tools::getValue('voucher_amount_value');
                 $voucher_date = Tools::getValue('voucher_date_to');
                 $new_voucher = new CartRule($campaign->id_voucher, $defaultLanguage->id);
                 $new_voucher->name = $voucher_name;
                 $new_voucher->date_from = date('Y-m-d');
                 $new_voucher->date_to = $voucher_date;
                 $new_voucher->description = 'Campaign : ' . $voucher_name;
                 $new_voucher->code = $voucher_code;
                 $new_voucher->quantity = 1000;
                 // Todo : Update when campaign is lunch to number of concerned people
                 // Si percent :
                 if ($voucher_amount_type == 'percent') {
                     $new_voucher->reduction_percent = $voucher_amount_value;
                 } else {
                     $new_voucher->reduction_amount = $voucher_amount_value;
                 }
                 //	d($new_voucher);
                 if (!$new_voucher->save()) {
                     $this->errors[] = Tools::displayError('An error has occured : when saved voucher');
                 }
             }
//.........这里部分代码省略.........
开发者ID:prestarocket,项目名称:superabandonedcart,代码行数:101,代码来源:AdminSuperAbandonedCart.php


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