示例#1
0
 protected function save()
 {
     if (empty($_POST['save'])) {
         return;
     }
     check_admin_referer('shopp-save-discount');
     if ('new' !== $_POST['id']) {
         $Promotion = new ShoppPromo($_POST['id']);
         $wascatalog = 'Catalog' == $Promotion->target;
     } else {
         $Promotion = new ShoppPromo();
     }
     if (!empty($_POST['starts']['month']) && !empty($_POST['starts']['date']) && !empty($_POST['starts']['year'])) {
         $_POST['starts'] = mktime(0, 0, 0, $_POST['starts']['month'], $_POST['starts']['date'], $_POST['starts']['year']);
     } else {
         $_POST['starts'] = 1;
     }
     if (!empty($_POST['ends']['month']) && !empty($_POST['ends']['date']) && !empty($_POST['ends']['year'])) {
         $_POST['ends'] = mktime(23, 59, 59, $_POST['ends']['month'], $_POST['ends']['date'], $_POST['ends']['year']);
     } else {
         $_POST['ends'] = 1;
     }
     if (isset($_POST['rules'])) {
         $_POST['rules'] = stripslashes_deep($_POST['rules']);
         foreach ($_POST['rules'] as &$rule) {
             if ('promo code' == strtolower($rule['property'])) {
                 $rule['value'] = trim($rule['value']);
             }
             if (false !== stripos($rule['property'], 'country') && 'USA' == $rule['value']) {
                 $rule['value'] = 'US';
             }
             // country-based rules must use 2-character ISO code, see #3129
         }
     }
     $Promotion->updates($_POST);
     $Promotion->save();
     do_action_ref_array('shopp_promo_saved', array(&$Promotion));
     // Apply catalog promotion discounts to catalog product price lines
     if ('Catalog' == $Promotion->target) {
         $Promotion->catalog();
     } elseif ($wascatalog) {
         // Unapply catalog discounts for discounts that no longer target catalog products
         $priceids = ShoppPromo::discounted_prices(array($Promotion->id));
         $Promotion->uncatalog($priceids);
     }
     // Set confirmation notice
     $this->notice(Shopp::__('Promotion has been updated!'));
     // Stay in the editor
     $url = add_query_arg('id', $Promotion->id, $this->url);
     wp_redirect($url);
     exit;
 }
示例#2
0
 /**
  * Disables an entire set of promotions
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $ids List of promotion IDs to disable
  * @return boolean Success/fail
  **/
 static function disableset($ids)
 {
     if (empty($ids) || !is_array($ids)) {
         return false;
     }
     $table = ShoppDatabaseObject::tablename(self::$table);
     sDB::query("UPDATE {$table} SET status='disabled' WHERE id IN (" . join(',', $ids) . ")");
     $catalogpromos = sDB::query("SELECT id FROM {$table} WHERE target='Catalog'", 'array', 'col', 'id');
     foreach ($catalogpromos as $promoid) {
         $Promo = new ShoppPromo($promoid);
         $Promo->catalog();
     }
     return true;
 }