Пример #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
 /**
  * Deletes an entire set of promotions
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $ids List of promotion IDs to delete
  * @return boolean Success/fail
  **/
 static function deleteset($ids)
 {
     if (empty($ids) || !is_array($ids)) {
         return false;
     }
     $prices = self::discounted_prices($ids);
     // Get the discounted price records
     foreach ($ids as $id) {
         $Promo = new ShoppPromo($id);
         if ('Catalog' == $Promo->target) {
             $Promo->uncatalog($prices);
         }
         // Remove the deleted price discounts
     }
     $table = ShoppDatabaseObject::tablename(self::$table);
     sDB::query("DELETE FROM {$table} WHERE id IN (" . join(',', $ids) . ")");
     // Delete the promotions
     return true;
 }